mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
saving
This commit is contained in:
parent
e8c7a4f6e0
commit
ffd97375a8
160 changed files with 6704 additions and 1895 deletions
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import type {
|
||||
RequestResponse,
|
||||
FlowRequestor,
|
||||
TextCompletionRequest,
|
||||
TextCompletionResponse,
|
||||
EmbeddingsRequest,
|
||||
|
|
@ -20,16 +20,20 @@ import type {
|
|||
} from "@trustgraph/base";
|
||||
|
||||
export interface DocumentRagClients {
|
||||
llm: RequestResponse<TextCompletionRequest, TextCompletionResponse>;
|
||||
embeddings: RequestResponse<EmbeddingsRequest, EmbeddingsResponse>;
|
||||
docEmbeddings: RequestResponse<DocumentEmbeddingsRequest, DocumentEmbeddingsResponse>;
|
||||
prompt: RequestResponse<PromptRequest, PromptResponse>;
|
||||
llm: FlowRequestor<TextCompletionRequest, TextCompletionResponse>;
|
||||
embeddings: FlowRequestor<EmbeddingsRequest, EmbeddingsResponse>;
|
||||
docEmbeddings: FlowRequestor<DocumentEmbeddingsRequest, DocumentEmbeddingsResponse>;
|
||||
prompt: FlowRequestor<PromptRequest, PromptResponse>;
|
||||
}
|
||||
|
||||
export type ChunkCallback = (text: string, endOfStream: boolean) => Promise<void>;
|
||||
|
||||
export class DocumentRag {
|
||||
constructor(private readonly clients: DocumentRagClients) {}
|
||||
private readonly clients: DocumentRagClients;
|
||||
|
||||
constructor(clients: DocumentRagClients) {
|
||||
this.clients = clients;
|
||||
}
|
||||
|
||||
async query(
|
||||
queryText: string,
|
||||
|
|
@ -57,8 +61,9 @@ export class DocumentRag {
|
|||
|
||||
// Step 3: Build context from chunks
|
||||
const context = chunks
|
||||
.filter((c) => c.content)
|
||||
.map((c) => c.content)
|
||||
.flatMap((c) =>
|
||||
c.content !== undefined && c.content.length > 0 ? [c.content] : [],
|
||||
)
|
||||
.join("\n\n---\n\n");
|
||||
|
||||
// Step 4: Synthesize answer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue