@delofarag/ai-utils 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/heart/agent.d.ts +68 -0
- package/dist/heart/agent.d.ts.map +1 -0
- package/dist/heart/agent.js +146 -0
- package/dist/heart/agent.js.map +1 -0
- package/dist/heart/chain.d.ts +50 -0
- package/dist/heart/chain.d.ts.map +1 -0
- package/dist/heart/chain.js +165 -0
- package/dist/heart/chain.js.map +1 -0
- package/dist/heart/chatbot.d.ts +45 -0
- package/dist/heart/chatbot.d.ts.map +1 -0
- package/dist/heart/chatbot.js +117 -0
- package/dist/heart/chatbot.js.map +1 -0
- package/dist/heart/memorychain.d.ts +57 -0
- package/dist/heart/memorychain.d.ts.map +1 -0
- package/dist/heart/memorychain.js +178 -0
- package/dist/heart/memorychain.js.map +1 -0
- package/dist/heart/tools/BasicToolRegistry.d.ts +22 -0
- package/dist/heart/tools/BasicToolRegistry.d.ts.map +1 -0
- package/dist/heart/tools/BasicToolRegistry.js +45 -0
- package/dist/heart/tools/BasicToolRegistry.js.map +1 -0
- package/dist/heart/tools/CombinedRegistry.d.ts +41 -0
- package/dist/heart/tools/CombinedRegistry.d.ts.map +1 -0
- package/dist/heart/tools/CombinedRegistry.js +46 -0
- package/dist/heart/tools/CombinedRegistry.js.map +1 -0
- package/dist/heart/tools/ZodiosToolRegistry.d.ts +22 -0
- package/dist/heart/tools/ZodiosToolRegistry.d.ts.map +1 -0
- package/dist/heart/tools/ZodiosToolRegistry.js +80 -0
- package/dist/heart/tools/ZodiosToolRegistry.js.map +1 -0
- package/dist/helpers.d.ts +39 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +99 -0
- package/dist/helpers.js.map +1 -0
- package/dist/imports.d.ts +44 -0
- package/dist/imports.d.ts.map +1 -0
- package/dist/imports.js +56 -0
- package/dist/imports.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +78 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +276 -0
- package/dist/memory.js.map +1 -0
- package/dist/rag.d.ts +58 -0
- package/dist/rag.d.ts.map +1 -0
- package/dist/rag.js +72 -0
- package/dist/rag.js.map +1 -0
- package/package.json +10 -9
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod/v3";
|
|
2
|
+
import { DynamicStructuredTool } from "../imports";
|
|
3
|
+
import { BaseChatModel } from "../imports";
|
|
4
|
+
import { BaseCheckpointSaver } from "../imports";
|
|
5
|
+
import { VectorStore } from "../imports";
|
|
6
|
+
interface AgentProps<T extends z.ZodObject<any, any>> {
|
|
7
|
+
prompt?: string | Array<string>;
|
|
8
|
+
tools: DynamicStructuredTool[];
|
|
9
|
+
llm: BaseChatModel;
|
|
10
|
+
schema?: T;
|
|
11
|
+
memory?: BaseCheckpointSaver;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* CONSTRUCTOR:
|
|
15
|
+
* @example constructor({
|
|
16
|
+
prompt = `Du bist ein hilfreicher Assistent.
|
|
17
|
+
WICHTIG:
|
|
18
|
+
- Nutze Tools NUR wenn nötig
|
|
19
|
+
- Nach jedem Tool-Call gib eine finale Antwort
|
|
20
|
+
- Stoppe nach der Antwort, rufe keine Tools mehr auf
|
|
21
|
+
- Wenn du die Antwort hast, gib sie direkt zurück`,
|
|
22
|
+
tools,
|
|
23
|
+
llm,
|
|
24
|
+
schema,
|
|
25
|
+
memory
|
|
26
|
+
}: AgentProps<T>) {
|
|
27
|
+
this.prompt = typeof prompt === "string" ? [["system", prompt]] : Array.isArray(prompt) ? prompt.map((p:string)=>{
|
|
28
|
+
return ["system", p]
|
|
29
|
+
}) : []
|
|
30
|
+
this.tools = tools
|
|
31
|
+
this.llm = llm
|
|
32
|
+
this.schema = schema
|
|
33
|
+
this.memory = memory
|
|
34
|
+
}
|
|
35
|
+
*/
|
|
36
|
+
export declare class Agent<T extends z.ZodObject<any, any>> {
|
|
37
|
+
private prompt;
|
|
38
|
+
private tools;
|
|
39
|
+
private llm;
|
|
40
|
+
private schema;
|
|
41
|
+
private agent;
|
|
42
|
+
private memory;
|
|
43
|
+
private vectorStore;
|
|
44
|
+
private rag_tool;
|
|
45
|
+
private times_of_added_context;
|
|
46
|
+
private should_use_schema;
|
|
47
|
+
constructor({ prompt, tools, llm, schema, memory }: AgentProps<T>);
|
|
48
|
+
invoke(invokeInput: Record<string, any> & {
|
|
49
|
+
thread_id?: string;
|
|
50
|
+
debug?: boolean;
|
|
51
|
+
}): Promise<T extends undefined ? string : z.infer<T>>;
|
|
52
|
+
stream(invokeInput: Record<string, any> & {
|
|
53
|
+
thread_id?: string;
|
|
54
|
+
debug?: boolean;
|
|
55
|
+
stream_delay?: number;
|
|
56
|
+
}): AsyncGenerator<string, void, unknown>;
|
|
57
|
+
setContext(vectorStore: VectorStore, metadata?: {
|
|
58
|
+
name?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
}): void;
|
|
61
|
+
addContext(data: Array<any>): Promise<void>;
|
|
62
|
+
clearContext(): void;
|
|
63
|
+
hasContext(): boolean;
|
|
64
|
+
addTool(tool: DynamicStructuredTool): void;
|
|
65
|
+
get currentTools(): string[];
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/heart/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAC1B,OAAO,EAAE,qBAAqB,EAAiC,MAAM,YAAY,CAAA;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA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O,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IAevJ,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO;IAgBrF,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAUjC,YAAY;IAOZ,UAAU,IAAI,OAAO;IAIrB,OAAO,CAAC,IAAI,EAAC,qBAAqB;IAIzC,IAAW,YAAY,IAAI,MAAM,EAAE,CAMlC;CACJ"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod/v3";
|
|
2
|
+
import { DynamicStructuredTool } from "../imports";
|
|
3
|
+
import { turn_to_docs } from "../rag";
|
|
4
|
+
import { createReactAgent } from "../imports";
|
|
5
|
+
import { HumanMessage } from "../imports";
|
|
6
|
+
import { structure, stream } from "../helpers";
|
|
7
|
+
/**
|
|
8
|
+
* CONSTRUCTOR:
|
|
9
|
+
* @example constructor({
|
|
10
|
+
prompt = `Du bist ein hilfreicher Assistent.
|
|
11
|
+
WICHTIG:
|
|
12
|
+
- Nutze Tools NUR wenn nötig
|
|
13
|
+
- Nach jedem Tool-Call gib eine finale Antwort
|
|
14
|
+
- Stoppe nach der Antwort, rufe keine Tools mehr auf
|
|
15
|
+
- Wenn du die Antwort hast, gib sie direkt zurück`,
|
|
16
|
+
tools,
|
|
17
|
+
llm,
|
|
18
|
+
schema,
|
|
19
|
+
memory
|
|
20
|
+
}: AgentProps<T>) {
|
|
21
|
+
this.prompt = typeof prompt === "string" ? [["system", prompt]] : Array.isArray(prompt) ? prompt.map((p:string)=>{
|
|
22
|
+
return ["system", p]
|
|
23
|
+
}) : []
|
|
24
|
+
this.tools = tools
|
|
25
|
+
this.llm = llm
|
|
26
|
+
this.schema = schema
|
|
27
|
+
this.memory = memory
|
|
28
|
+
}
|
|
29
|
+
*/
|
|
30
|
+
export class Agent {
|
|
31
|
+
prompt;
|
|
32
|
+
tools;
|
|
33
|
+
llm;
|
|
34
|
+
schema;
|
|
35
|
+
agent;
|
|
36
|
+
memory;
|
|
37
|
+
vectorStore;
|
|
38
|
+
rag_tool;
|
|
39
|
+
times_of_added_context = 0;
|
|
40
|
+
should_use_schema = true;
|
|
41
|
+
constructor({ prompt = `Du bist ein hilfreicher Assistent.
|
|
42
|
+
WICHTIG:
|
|
43
|
+
- Nutze Tools NUR wenn nötig
|
|
44
|
+
- Nach jedem Tool-Call gib eine finale Antwort
|
|
45
|
+
- Stoppe nach der Antwort, rufe keine Tools mehr auf
|
|
46
|
+
- Wenn du die Antwort hast, gib sie direkt zurück`, tools, llm, schema, memory }) {
|
|
47
|
+
this.prompt = typeof prompt === "string" ? [["system", prompt]] : Array.isArray(prompt) ? prompt.map((p) => {
|
|
48
|
+
return ["system", p];
|
|
49
|
+
}) : [];
|
|
50
|
+
this.tools = tools;
|
|
51
|
+
this.llm = llm;
|
|
52
|
+
this.schema = schema;
|
|
53
|
+
this.memory = memory;
|
|
54
|
+
}
|
|
55
|
+
async invoke(invokeInput) {
|
|
56
|
+
const { thread_id, debug, ...variables } = invokeInput;
|
|
57
|
+
if (this.vectorStore && !thread_id)
|
|
58
|
+
throw new Error("thread_id is required when using a vector store, else no memory is stored");
|
|
59
|
+
if (!this.vectorStore && thread_id)
|
|
60
|
+
console.warn("thread_id is provided but no vector store is set, so no memory is stored");
|
|
61
|
+
const humanMessages = Object.entries(variables).map(([key, value]) => new HumanMessage(`${key}: ${typeof value === "object" ? JSON.stringify(value) : value}`));
|
|
62
|
+
// Tools für diesen invoke (inkl. RAG falls vorhanden)
|
|
63
|
+
const activeTools = this.rag_tool
|
|
64
|
+
? [...this.tools, this.rag_tool]
|
|
65
|
+
: this.tools;
|
|
66
|
+
this.agent = createReactAgent({
|
|
67
|
+
llm: this.llm,
|
|
68
|
+
tools: activeTools,
|
|
69
|
+
checkpointSaver: this.memory,
|
|
70
|
+
prompt: (state) => [
|
|
71
|
+
...this.prompt,
|
|
72
|
+
...state.messages
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
const config = thread_id && this.memory ? { configurable: { thread_id } } : undefined;
|
|
76
|
+
const result = await this.agent.invoke({ messages: humanMessages }, config);
|
|
77
|
+
if (debug)
|
|
78
|
+
return result;
|
|
79
|
+
const lastMessage = result.messages[result.messages.length - 1];
|
|
80
|
+
const content = lastMessage.content;
|
|
81
|
+
if (this.schema && this.should_use_schema) {
|
|
82
|
+
return await structure({ data: content, into: this.schema, llm: this.llm });
|
|
83
|
+
}
|
|
84
|
+
return content;
|
|
85
|
+
}
|
|
86
|
+
async *stream(invokeInput) {
|
|
87
|
+
this.should_use_schema = false;
|
|
88
|
+
try {
|
|
89
|
+
const { stream_delay = 1, ...rest } = invokeInput;
|
|
90
|
+
const response = await this.invoke(rest);
|
|
91
|
+
const responseStr = typeof response === "string" ? response : JSON.stringify(response);
|
|
92
|
+
const words = responseStr.split(" ");
|
|
93
|
+
for await (const word of stream(words, stream_delay)) {
|
|
94
|
+
yield word + " ";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
this.should_use_schema = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
setContext(vectorStore, metadata = {}) {
|
|
102
|
+
this.vectorStore = vectorStore;
|
|
103
|
+
this.rag_tool = new DynamicStructuredTool({
|
|
104
|
+
name: metadata.name ?? "search_context",
|
|
105
|
+
description: metadata.description ?? "Search the knowledge base for relevant information",
|
|
106
|
+
schema: z.object({
|
|
107
|
+
query: z.string().describe("The search query")
|
|
108
|
+
}),
|
|
109
|
+
func: async ({ query }) => {
|
|
110
|
+
const docs = await this.vectorStore?.similaritySearch(query, 3);
|
|
111
|
+
if (!docs || docs.length === 0)
|
|
112
|
+
return "No relevant information found.";
|
|
113
|
+
return docs.map(doc => doc.pageContent).join("\n\n---\n\n");
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async addContext(data) {
|
|
118
|
+
if (!this.vectorStore) {
|
|
119
|
+
throw new Error("Cant add context, no vector store set");
|
|
120
|
+
}
|
|
121
|
+
this.times_of_added_context++;
|
|
122
|
+
const docs = turn_to_docs(data);
|
|
123
|
+
await this.vectorStore.addDocuments(docs);
|
|
124
|
+
console.log(`Added context ${this.times_of_added_context} ${this.times_of_added_context === 1 ? "time" : "times"}`);
|
|
125
|
+
}
|
|
126
|
+
clearContext() {
|
|
127
|
+
this.rag_tool = undefined;
|
|
128
|
+
this.vectorStore = undefined;
|
|
129
|
+
this.times_of_added_context = 0;
|
|
130
|
+
console.log("Context cleared");
|
|
131
|
+
}
|
|
132
|
+
hasContext() {
|
|
133
|
+
return this.vectorStore !== undefined && this.rag_tool !== undefined;
|
|
134
|
+
}
|
|
135
|
+
addTool(tool) {
|
|
136
|
+
this.tools.push(tool);
|
|
137
|
+
}
|
|
138
|
+
get currentTools() {
|
|
139
|
+
const tools = [...this.tools];
|
|
140
|
+
if (this.rag_tool) {
|
|
141
|
+
tools.push(this.rag_tool);
|
|
142
|
+
}
|
|
143
|
+
return tools.map(tool => tool.name);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/heart/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAC1B,OAAO,EAAE,qBAAqB,EAAiC,MAAM,YAAY,CAAA;AAIjF,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,YAAY,EAA0B,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,SAAS,EAAC,MAAM,EAAE,MAAM,YAAY,CAA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AAQ,KAAK,SAAS,CAAA;IACxE,CAAC;IAEM,OAAO,CAAC,IAA0B;QACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAED,IAAW,YAAY;QACnB,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC7B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC7B,CAAC;QACD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;CACJ"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseChatModel, MessagesPlaceholder, VectorStore } from "../imports";
|
|
2
|
+
import { z } from "zod/v3";
|
|
3
|
+
export declare const DEFAULT_SCHEMA: z.ZodObject<{
|
|
4
|
+
output: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
output: string;
|
|
7
|
+
}, {
|
|
8
|
+
output: string;
|
|
9
|
+
}>;
|
|
10
|
+
interface ChainProps<T extends z.ZodObject<any, any>> {
|
|
11
|
+
prompt?: string | Array<string | MessagesPlaceholder<any>>;
|
|
12
|
+
llm: BaseChatModel;
|
|
13
|
+
schema?: T;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* CONSTRUCTOR:
|
|
17
|
+
* @example constructor({prompt = "du bist ein hilfreicher Assistent",llm,schema}:ChainProps<T>){
|
|
18
|
+
this.prompt = typeof prompt === "string" ? [["system", prompt]] : Array.isArray(prompt) ? prompt.map((p:string | MessagesPlaceholder<any>)=>{
|
|
19
|
+
if(typeof p === "string"){
|
|
20
|
+
return ["system", p]
|
|
21
|
+
} else {
|
|
22
|
+
return p
|
|
23
|
+
}
|
|
24
|
+
}) : []
|
|
25
|
+
this.llm = llm
|
|
26
|
+
this.schema = (schema ?? DEFAULT_SCHEMA) as unknown as T
|
|
27
|
+
this.parser = StructuredOutputParser.fromZodSchema(this.schema)
|
|
28
|
+
}
|
|
29
|
+
*/
|
|
30
|
+
export declare class Chain<T extends z.ZodObject<any, any> = typeof DEFAULT_SCHEMA> {
|
|
31
|
+
private prompt;
|
|
32
|
+
private vectorStore;
|
|
33
|
+
private times_of_added_context;
|
|
34
|
+
private parser;
|
|
35
|
+
private llm;
|
|
36
|
+
private schema;
|
|
37
|
+
constructor({ prompt, llm, schema }: ChainProps<T>);
|
|
38
|
+
invoke(input: Record<string, any> & {
|
|
39
|
+
debug?: boolean;
|
|
40
|
+
}): Promise<z.infer<T>>;
|
|
41
|
+
stream(input: Record<string, any> & {
|
|
42
|
+
debug?: boolean;
|
|
43
|
+
}): AsyncGenerator<string, void, unknown>;
|
|
44
|
+
/** Fügt RAG-Kontext hinzu. Docs werden EINMAL zum VectorStore hinzugefügt. */
|
|
45
|
+
addContext(data: Array<any>): Promise<void>;
|
|
46
|
+
setContext(vectorStore: VectorStore): Promise<void>;
|
|
47
|
+
clearContext(): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/heart/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAGb,mBAAmB,EACnB,WAAW,EAGd,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE1B,eAAO,MAAM,cAAc;;;;;;EAEzB,CAAA;AAEF,UAAU,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,EAAC,GAAG,CAAC;IAC/C,MAAM,CAAC,EAAC,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAA;IACzD,GAAG,EAAC,aAAa,CAAA;IACjB,MAAM,CAAC,EAAC,CAAC,CAAA;CACZ;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,EAAC,GAAG,CAAC,GAAG,OAAO,cAAc;IACrE,OAAO,CAAC,MAAM,CAA+D;IAC7E,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,sBAAsB,CAAY;IAC1C,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,MAAM,CAAE;gBAEJ,EAAC,MAA4C,EAAC,GAAG,EAAC,MAAM,EAAC,EAAC,UAAU,CAAC,CAAC,CAAC;IAatE,MAAM,CAAC,KAAK,EAAC,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,GAAG;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAC,GAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IA2CvE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IAuD7G,8EAA8E;IACjE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAU3B,UAAU,CAAC,WAAW,EAAE,WAAW;IAKzC,YAAY;CAKtB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { StructuredOutputParser, ChatPromptTemplate, createRetrievalChain, createStuffDocumentsChain, } from "../imports";
|
|
2
|
+
import { turn_to_docs } from "../rag";
|
|
3
|
+
import { z } from "zod/v3";
|
|
4
|
+
export const DEFAULT_SCHEMA = z.object({
|
|
5
|
+
output: z.string().describe("Dein Output zur anfrage des Users")
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* CONSTRUCTOR:
|
|
9
|
+
* @example constructor({prompt = "du bist ein hilfreicher Assistent",llm,schema}:ChainProps<T>){
|
|
10
|
+
this.prompt = typeof prompt === "string" ? [["system", prompt]] : Array.isArray(prompt) ? prompt.map((p:string | MessagesPlaceholder<any>)=>{
|
|
11
|
+
if(typeof p === "string"){
|
|
12
|
+
return ["system", p]
|
|
13
|
+
} else {
|
|
14
|
+
return p
|
|
15
|
+
}
|
|
16
|
+
}) : []
|
|
17
|
+
this.llm = llm
|
|
18
|
+
this.schema = (schema ?? DEFAULT_SCHEMA) as unknown as T
|
|
19
|
+
this.parser = StructuredOutputParser.fromZodSchema(this.schema)
|
|
20
|
+
}
|
|
21
|
+
*/
|
|
22
|
+
export class Chain {
|
|
23
|
+
prompt;
|
|
24
|
+
vectorStore;
|
|
25
|
+
times_of_added_context = 0;
|
|
26
|
+
parser;
|
|
27
|
+
llm;
|
|
28
|
+
schema;
|
|
29
|
+
constructor({ prompt = "du bist ein hilfreicher Assistent", llm, schema }) {
|
|
30
|
+
this.prompt = typeof prompt === "string" ? [["system", prompt]] : Array.isArray(prompt) ? prompt.map((p) => {
|
|
31
|
+
if (typeof p === "string") {
|
|
32
|
+
return ["system", p];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
}) : [];
|
|
38
|
+
this.llm = llm;
|
|
39
|
+
this.schema = (schema ?? DEFAULT_SCHEMA);
|
|
40
|
+
this.parser = StructuredOutputParser.fromZodSchema(this.schema);
|
|
41
|
+
}
|
|
42
|
+
async invoke(input) {
|
|
43
|
+
const messagesArray = [...this.prompt];
|
|
44
|
+
messagesArray.push(["system", "You MUST respond ONLY with valid JSON matching this exact schema:\n{format_instructions}\n\nIMPORTANT: \n- Output ONLY valid JSON, no markdown code blocks\n- No backslashes or line breaks in strings\n- All strings must be on single lines\n- Do NOT wrap in ```json``` blocks\n- Return the JSON object DIRECTLY"]);
|
|
45
|
+
if (this.vectorStore)
|
|
46
|
+
messagesArray.push(["system", "Hier ist relevanter Kontext:\n{context}"]);
|
|
47
|
+
for (const key in input) {
|
|
48
|
+
if (key === "debug")
|
|
49
|
+
continue;
|
|
50
|
+
if (key === "thread_id") {
|
|
51
|
+
console.error("eine normale chain hat keine memory, deswegen wird thread_id ignoriert");
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (typeof input[key] !== "string") {
|
|
55
|
+
messagesArray.push(["human", `${key}:${JSON.stringify(input[key])}`]);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
messagesArray.push(["human", `${key}:{${key}}`]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const true_prompt = ChatPromptTemplate.fromMessages(messagesArray);
|
|
62
|
+
if (input.debug)
|
|
63
|
+
console.log("Prompt: ", true_prompt);
|
|
64
|
+
const invokeInput = { ...input, format_instructions: this.parser.getFormatInstructions() };
|
|
65
|
+
if (this.vectorStore) {
|
|
66
|
+
const retriever = this.vectorStore.asRetriever();
|
|
67
|
+
const stuff_chain = await createStuffDocumentsChain({
|
|
68
|
+
llm: this.llm,
|
|
69
|
+
prompt: true_prompt,
|
|
70
|
+
outputParser: this.parser
|
|
71
|
+
});
|
|
72
|
+
const chain = await createRetrievalChain({
|
|
73
|
+
combineDocsChain: stuff_chain,
|
|
74
|
+
retriever: retriever
|
|
75
|
+
});
|
|
76
|
+
if (input.debug)
|
|
77
|
+
console.log("created retrieval chain");
|
|
78
|
+
const respo = await chain.invoke({ input: JSON.stringify(input), ...invokeInput });
|
|
79
|
+
return this.schema.parse(respo.answer);
|
|
80
|
+
}
|
|
81
|
+
const chain = true_prompt.pipe(this.llm).pipe(this.parser);
|
|
82
|
+
if (input.debug)
|
|
83
|
+
console.log("created normal chain");
|
|
84
|
+
const respo = await chain.invoke(invokeInput);
|
|
85
|
+
return this.schema.parse(respo);
|
|
86
|
+
}
|
|
87
|
+
async *stream(input) {
|
|
88
|
+
const messagesArray = [...this.prompt];
|
|
89
|
+
// Beim Streamen KEIN Schema-Prompt - nur reiner Text
|
|
90
|
+
if (this.vectorStore)
|
|
91
|
+
messagesArray.push(["system", "Hier ist relevanter Kontext:\n{context}"]);
|
|
92
|
+
for (const key in input) {
|
|
93
|
+
if (key === "debug")
|
|
94
|
+
continue;
|
|
95
|
+
if (key === "thread_id") {
|
|
96
|
+
console.error("eine normale chain hat keine memory, deswegen wird thread_id ignoriert");
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (typeof input[key] !== "string") {
|
|
100
|
+
messagesArray.push(["human", `${key}:${JSON.stringify(input[key])}`]);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
messagesArray.push(["human", `${key}:{${key}}`]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const true_prompt = ChatPromptTemplate.fromMessages(messagesArray);
|
|
107
|
+
if (input.debug)
|
|
108
|
+
console.log("Prompt: ", true_prompt);
|
|
109
|
+
const invokeInput = { ...input };
|
|
110
|
+
if (this.vectorStore) {
|
|
111
|
+
const retriever = this.vectorStore.asRetriever();
|
|
112
|
+
if (input.debug)
|
|
113
|
+
console.log("created retrieval chain (streaming)");
|
|
114
|
+
// Für RAG: Hole Context und stream dann die LLM-Antwort
|
|
115
|
+
const contextDocs = await retriever.invoke(JSON.stringify(input));
|
|
116
|
+
const contextText = contextDocs.map((doc) => doc.pageContent).join("\n\n");
|
|
117
|
+
// Stream die LLM-Antwort mit Context
|
|
118
|
+
const streamChain = true_prompt.pipe(this.llm);
|
|
119
|
+
const stream = await streamChain.stream({ ...invokeInput, context: contextText });
|
|
120
|
+
for await (const chunk of stream) {
|
|
121
|
+
if (chunk && typeof chunk === 'object' && 'content' in chunk) {
|
|
122
|
+
yield chunk.content;
|
|
123
|
+
}
|
|
124
|
+
else if (typeof chunk === 'string') {
|
|
125
|
+
yield chunk;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Ohne RAG: Stream direkt
|
|
131
|
+
const streamChain = true_prompt.pipe(this.llm);
|
|
132
|
+
if (input.debug)
|
|
133
|
+
console.log("created normal chain (streaming)");
|
|
134
|
+
const stream = await streamChain.stream(invokeInput);
|
|
135
|
+
for await (const chunk of stream) {
|
|
136
|
+
if (chunk && typeof chunk === 'object' && 'content' in chunk) {
|
|
137
|
+
yield chunk.content;
|
|
138
|
+
}
|
|
139
|
+
else if (typeof chunk === 'string') {
|
|
140
|
+
yield chunk;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Fügt RAG-Kontext hinzu. Docs werden EINMAL zum VectorStore hinzugefügt. */
|
|
146
|
+
async addContext(data) {
|
|
147
|
+
if (!this.vectorStore) {
|
|
148
|
+
throw new Error("Cant add context, no vector store set");
|
|
149
|
+
}
|
|
150
|
+
this.times_of_added_context++;
|
|
151
|
+
const docs = turn_to_docs(data);
|
|
152
|
+
await this.vectorStore.addDocuments(docs);
|
|
153
|
+
console.log(`Added context ${this.times_of_added_context} ${this.times_of_added_context === 1 ? "time" : "times"}`);
|
|
154
|
+
}
|
|
155
|
+
async setContext(vectorStore) {
|
|
156
|
+
console.log("Setting context");
|
|
157
|
+
this.vectorStore = vectorStore;
|
|
158
|
+
}
|
|
159
|
+
clearContext() {
|
|
160
|
+
this.vectorStore = undefined;
|
|
161
|
+
this.times_of_added_context = 0;
|
|
162
|
+
console.log("Context cleared");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/heart/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,sBAAsB,EACtB,kBAAkB,EAGlB,oBAAoB,EACpB,yBAAyB,GAC5B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA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C,iBAAiB,IAAI,CAAC,sBAAsB,IAAI,IAAI,CAAC,sBAAsB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;IACvH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,WAAwB;QAC5C,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAClC,CAAC;IAEM,YAAY;QACf,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;QAC5B,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAA;QAC/B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAClC,CAAC;CACJ"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseCheckpointSaver, VectorStore, DynamicStructuredTool } from "../imports";
|
|
2
|
+
import { BaseChatModel } from "../imports";
|
|
3
|
+
type ChatbotProps = {
|
|
4
|
+
llm: BaseChatModel;
|
|
5
|
+
prompt?: string | Array<string>;
|
|
6
|
+
tools?: DynamicStructuredTool[];
|
|
7
|
+
memory?: BaseCheckpointSaver;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* CONSTRUCTOR:
|
|
11
|
+
* @example constructor({llm,prompt = "Du bist ein hilfreicher chatbot der mit dem User ein höffliches und hilfreiches Gespräch führt",tools,memory}:ChatbotProps){
|
|
12
|
+
if(tools){
|
|
13
|
+
this.agent = new Agent({
|
|
14
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(),{ llm }),
|
|
15
|
+
tools : tools,
|
|
16
|
+
prompt: prompt,
|
|
17
|
+
llm: llm
|
|
18
|
+
})
|
|
19
|
+
} else {
|
|
20
|
+
this.chain = new MemoryChain({
|
|
21
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(),{ llm }),
|
|
22
|
+
prompt: prompt,
|
|
23
|
+
llm: llm
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
*/
|
|
27
|
+
export declare class Chatbot {
|
|
28
|
+
private chain;
|
|
29
|
+
private agent;
|
|
30
|
+
constructor({ llm, prompt, tools, memory }: ChatbotProps);
|
|
31
|
+
chat({ input, thread_id }: {
|
|
32
|
+
input: string;
|
|
33
|
+
thread_id: string;
|
|
34
|
+
}): AsyncGenerator<string, string, unknown>;
|
|
35
|
+
session({ breakword, numberOfMessages, id }?: {
|
|
36
|
+
breakword?: string;
|
|
37
|
+
numberOfMessages?: number;
|
|
38
|
+
id?: string;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
addContext(data: Array<any>): Promise<void>;
|
|
41
|
+
setContext(vectorStore: VectorStore): Promise<void>;
|
|
42
|
+
clearContext(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=chatbot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatbot.d.ts","sourceRoot":"","sources":["../../src/heart/chatbot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAqF,WAAW,EAAE,qBAAqB,EAAuB,MAAM,YAAY,CAAA;AAC5L,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAQ1C,KAAK,YAAY,GAAG;IAChB,GAAG,EAAE,aAAa,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IAC/B,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAA;IAC/B,MAAM,CAAC,EAAE,mBAAmB,CAAA;CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAO;IAChB,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,KAAK,CAAwB;gBAEzB,EAAC,GAAG,EAAC,MAAyG,EAAC,KAAK,EAAC,MAAM,EAAC,EAAC,YAAY;IAiBvI,IAAI,CAAC,EAAC,KAAK,EAAC,SAAS,EAAC,EAAC;QAAC,KAAK,EAAC,MAAM,CAAC;QAAC,SAAS,EAAC,MAAM,CAAA;KAAC,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;IAWlG,OAAO,CAAC,EACjB,SAAkB,EAClB,gBAA2C,EAC3C,EAAoB,EACvB,GAAC;QACE,SAAS,CAAC,EAAC,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAC,MAAM,CAAC;QACzB,EAAE,CAAC,EAAC,MAAM,CAAA;KACR;IA2BO,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAU3B,UAAU,CAAC,WAAW,EAAE,WAAW;IAUnC,YAAY;CAS5B"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SmartCheckpointSaver } from "../memory";
|
|
2
|
+
import { MemorySaver } from "../imports";
|
|
3
|
+
import { logChunk } from "../helpers";
|
|
4
|
+
import { input } from "@delofarag/base-utils";
|
|
5
|
+
import { MemoryChain } from "./memorychain";
|
|
6
|
+
import { Agent } from "./agent";
|
|
7
|
+
/**
|
|
8
|
+
* CONSTRUCTOR:
|
|
9
|
+
* @example constructor({llm,prompt = "Du bist ein hilfreicher chatbot der mit dem User ein höffliches und hilfreiches Gespräch führt",tools,memory}:ChatbotProps){
|
|
10
|
+
if(tools){
|
|
11
|
+
this.agent = new Agent({
|
|
12
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(),{ llm }),
|
|
13
|
+
tools : tools,
|
|
14
|
+
prompt: prompt,
|
|
15
|
+
llm: llm
|
|
16
|
+
})
|
|
17
|
+
} else {
|
|
18
|
+
this.chain = new MemoryChain({
|
|
19
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(),{ llm }),
|
|
20
|
+
prompt: prompt,
|
|
21
|
+
llm: llm
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
*/
|
|
25
|
+
export class Chatbot {
|
|
26
|
+
chain;
|
|
27
|
+
agent;
|
|
28
|
+
constructor({ llm, prompt = "Du bist ein hilfreicher chatbot der mit dem User ein höffliches und hilfreiches Gespräch führt", tools, memory }) {
|
|
29
|
+
if (tools) {
|
|
30
|
+
this.agent = new Agent({
|
|
31
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(), { llm }),
|
|
32
|
+
tools: tools,
|
|
33
|
+
prompt: prompt,
|
|
34
|
+
llm: llm
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.chain = new MemoryChain({
|
|
39
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(), { llm }),
|
|
40
|
+
prompt: prompt,
|
|
41
|
+
llm: llm
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async *chat({ input, thread_id }) {
|
|
46
|
+
const streamable = this.chain ? this.chain : this.agent;
|
|
47
|
+
if (!streamable)
|
|
48
|
+
throw new Error("kein streamable!");
|
|
49
|
+
let fullResponse = "";
|
|
50
|
+
for await (const chunk of streamable.stream({ input, thread_id })) {
|
|
51
|
+
fullResponse += chunk;
|
|
52
|
+
yield chunk;
|
|
53
|
+
}
|
|
54
|
+
return fullResponse;
|
|
55
|
+
}
|
|
56
|
+
async session({ breakword = "exit", numberOfMessages = Number.POSITIVE_INFINITY, id = `${Date.now()}` } = {}) {
|
|
57
|
+
let messages = 0;
|
|
58
|
+
while (true) {
|
|
59
|
+
try {
|
|
60
|
+
const message = await input("You: ");
|
|
61
|
+
if (message === breakword) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
const response = this.chat({
|
|
65
|
+
input: message,
|
|
66
|
+
thread_id: id,
|
|
67
|
+
});
|
|
68
|
+
console.log("Assistant: ");
|
|
69
|
+
for await (const chunk of response) {
|
|
70
|
+
logChunk(chunk);
|
|
71
|
+
}
|
|
72
|
+
console.log(""); // Zeilenumbruch nach dem Streamen, damit Output nicht überschrieben wird
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error("Error: ", e);
|
|
76
|
+
}
|
|
77
|
+
messages = messages + 2;
|
|
78
|
+
if (messages > numberOfMessages) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async addContext(data) {
|
|
84
|
+
if (this.chain) {
|
|
85
|
+
await this.chain.addContext(data);
|
|
86
|
+
}
|
|
87
|
+
else if (this.agent) {
|
|
88
|
+
await this.agent.addContext(data);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw Error("weder agent noch chain, kein addContext möglich");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async setContext(vectorStore) {
|
|
95
|
+
if (this.chain) {
|
|
96
|
+
this.chain.setContext(vectorStore);
|
|
97
|
+
}
|
|
98
|
+
else if (this.agent) {
|
|
99
|
+
this.agent.setContext(vectorStore);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw Error("weder agent noch chain, kein setContext möglich");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async clearContext() {
|
|
106
|
+
if (this.chain) {
|
|
107
|
+
this.chain.clearContext();
|
|
108
|
+
}
|
|
109
|
+
else if (this.agent) {
|
|
110
|
+
this.agent.clearContext();
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
throw Error("weder agent noch chain, kein clearContext möglich");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=chatbot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatbot.js","sourceRoot":"","sources":["../../src/heart/chatbot.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAC7C,OAAO,E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