@delofarag/ai-utils 1.0.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/README.md +95 -0
- package/dist/src/heart/agent.d.ts +68 -0
- package/dist/src/heart/agent.d.ts.map +1 -0
- package/dist/src/heart/agent.js +140 -0
- package/dist/src/heart/agent.js.map +1 -0
- package/dist/src/heart/chain.d.ts +42 -0
- package/dist/src/heart/chain.d.ts.map +1 -0
- package/dist/src/heart/chain.js +152 -0
- package/dist/src/heart/chain.js.map +1 -0
- package/dist/src/heart/chatbot.d.ts +27 -0
- package/dist/src/heart/chatbot.d.ts.map +1 -0
- package/dist/src/heart/chatbot.js +99 -0
- package/dist/src/heart/chatbot.js.map +1 -0
- package/dist/src/heart/memorychain.d.ts +59 -0
- package/dist/src/heart/memorychain.d.ts.map +1 -0
- package/dist/src/heart/memorychain.js +164 -0
- package/dist/src/heart/memorychain.js.map +1 -0
- package/dist/src/heart/tools/BasicToolRegistry.d.ts +22 -0
- package/dist/src/heart/tools/BasicToolRegistry.d.ts.map +1 -0
- package/dist/src/heart/tools/BasicToolRegistry.js +45 -0
- package/dist/src/heart/tools/BasicToolRegistry.js.map +1 -0
- package/dist/src/heart/tools/CombinedRegistry.d.ts +41 -0
- package/dist/src/heart/tools/CombinedRegistry.d.ts.map +1 -0
- package/dist/src/heart/tools/CombinedRegistry.js +46 -0
- package/dist/src/heart/tools/CombinedRegistry.js.map +1 -0
- package/dist/src/heart/tools/ZodiosToolRegistry.d.ts +22 -0
- package/dist/src/heart/tools/ZodiosToolRegistry.d.ts.map +1 -0
- package/dist/src/heart/tools/ZodiosToolRegistry.js +80 -0
- package/dist/src/heart/tools/ZodiosToolRegistry.js.map +1 -0
- package/dist/src/helpers.d.ts +31 -0
- package/dist/src/helpers.d.ts.map +1 -0
- package/dist/src/helpers.js +105 -0
- package/dist/src/helpers.js.map +1 -0
- package/dist/src/imports.d.ts +44 -0
- package/dist/src/imports.d.ts.map +1 -0
- package/dist/src/imports.js +56 -0
- package/dist/src/imports.js.map +1 -0
- package/dist/src/memory.d.ts +78 -0
- package/dist/src/memory.d.ts.map +1 -0
- package/dist/src/memory.js +276 -0
- package/dist/src/memory.js.map +1 -0
- package/dist/src/rag.d.ts +58 -0
- package/dist/src/rag.d.ts.map +1 -0
- package/dist/src/rag.js +72 -0
- package/dist/src/rag.js.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @my/ai-utils
|
|
2
|
+
|
|
3
|
+
Utilities for working with LangChain, AI models, and RAG (Retrieval Augmented Generation).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @my/ai-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Peer Dependencies:**
|
|
12
|
+
```bash
|
|
13
|
+
npm install @my/supabase-utils
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Basic LLM Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { getLLM } from "@my/ai-utils"
|
|
22
|
+
|
|
23
|
+
const llm = getLLM("groq", {
|
|
24
|
+
chatgroqApiKey: "your-api-key"
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const response = await llm.invoke("Hello!")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Chain
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Chain } from "@my/ai-utils"
|
|
34
|
+
import { getLLM } from "@my/ai-utils"
|
|
35
|
+
|
|
36
|
+
const llm = getLLM("groq", { chatgroqApiKey: "your-key" })
|
|
37
|
+
|
|
38
|
+
const chain = new Chain({
|
|
39
|
+
llm,
|
|
40
|
+
prompt: [["system", "You are a helpful assistant"]]
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const result = await chain.invoke({ message: "Hello!" })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Agent
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Agent } from "@my/ai-utils"
|
|
50
|
+
import { getLLM } from "@my/ai-utils"
|
|
51
|
+
|
|
52
|
+
const llm = getLLM("groq", { chatgroqApiKey: "your-key" })
|
|
53
|
+
|
|
54
|
+
const agent = new Agent({
|
|
55
|
+
llm,
|
|
56
|
+
tools: [/* your tools */],
|
|
57
|
+
prompt: [["system", "You are a helpful assistant"]]
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const result = await agent.invoke({
|
|
61
|
+
input: "What's the weather?",
|
|
62
|
+
thread_id: "thread-1"
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Memory Chain
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { MemoryChain } from "@my/ai-utils"
|
|
70
|
+
import { getLLM } from "@my/ai-utils"
|
|
71
|
+
|
|
72
|
+
const llm = getLLM("groq", { chatgroqApiKey: "your-key" })
|
|
73
|
+
|
|
74
|
+
const chain = new MemoryChain({
|
|
75
|
+
llm,
|
|
76
|
+
prompt: [["system", "You are a helpful chatbot"]]
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const result = await chain.invoke({
|
|
80
|
+
input: "Hello!",
|
|
81
|
+
thread_id: "thread-1"
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Exports
|
|
86
|
+
|
|
87
|
+
- `getLLM()` - Create LLM instance (Groq, OpenAI, Ollama)
|
|
88
|
+
- `Chain` - Basic chain without memory
|
|
89
|
+
- `MemoryChain` - Chain with memory support
|
|
90
|
+
- `Agent` - Agent with tools and memory
|
|
91
|
+
- `Chatbot` - High-level chatbot interface
|
|
92
|
+
- `structure()` - Structure output with Zod schema
|
|
93
|
+
- `summarize()` - Summarize conversations
|
|
94
|
+
- RAG utilities for vector stores
|
|
95
|
+
|
|
@@ -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?: Array<["system", string]>;
|
|
8
|
+
tools: DynamicStructuredTool[];
|
|
9
|
+
llm: BaseChatModel;
|
|
10
|
+
schema?: T;
|
|
11
|
+
memory?: BaseCheckpointSaver;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* CONSTRUCTOR:
|
|
15
|
+
* @example constructor({
|
|
16
|
+
prompt = [["system", `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 = getLLM("groq"),
|
|
24
|
+
schema,
|
|
25
|
+
memory
|
|
26
|
+
}: AgentProps<T>) {
|
|
27
|
+
this.prompt = prompt
|
|
28
|
+
this.tools = tools
|
|
29
|
+
this.llm = llm
|
|
30
|
+
this.schema = schema
|
|
31
|
+
this.memory = memory
|
|
32
|
+
}
|
|
33
|
+
*/
|
|
34
|
+
export declare class Agent<T extends z.ZodObject<any, any>> {
|
|
35
|
+
private prompt;
|
|
36
|
+
private tools;
|
|
37
|
+
private llm;
|
|
38
|
+
private schema;
|
|
39
|
+
private agent;
|
|
40
|
+
private memory;
|
|
41
|
+
private vectorStore;
|
|
42
|
+
private rag_tool;
|
|
43
|
+
private times_of_added_context;
|
|
44
|
+
private should_use_schema;
|
|
45
|
+
constructor({ prompt, tools, llm, schema, memory }: AgentProps<T>);
|
|
46
|
+
invoke(invokeInput: Record<string, any> & {
|
|
47
|
+
input: string;
|
|
48
|
+
thread_id?: string;
|
|
49
|
+
debug?: boolean;
|
|
50
|
+
}): Promise<T extends undefined ? string : z.infer<T>>;
|
|
51
|
+
stream(invokeInput: Record<string, any> & {
|
|
52
|
+
input: string;
|
|
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,EAAY,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AASxC,UAAU,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,EAAC,GAAG,CAAC;IAC/C,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;IAClC,KAAK,EAAE,qBAAqB,EAAE,CAAA;IAC9B,GAAG,EAAE,aAAa,CAAA;IAClB,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,MAAM,CAAC,EAAE,mBAAmB,CAAA;CAC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BrF,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,140 @@
|
|
|
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 = [["system", `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 = getLLM("groq"),
|
|
18
|
+
schema,
|
|
19
|
+
memory
|
|
20
|
+
}: AgentProps<T>) {
|
|
21
|
+
this.prompt = prompt
|
|
22
|
+
this.tools = tools
|
|
23
|
+
this.llm = llm
|
|
24
|
+
this.schema = schema
|
|
25
|
+
this.memory = memory
|
|
26
|
+
}
|
|
27
|
+
*/
|
|
28
|
+
export class Agent {
|
|
29
|
+
prompt;
|
|
30
|
+
tools;
|
|
31
|
+
llm;
|
|
32
|
+
schema;
|
|
33
|
+
agent;
|
|
34
|
+
memory;
|
|
35
|
+
vectorStore;
|
|
36
|
+
rag_tool;
|
|
37
|
+
times_of_added_context = 0;
|
|
38
|
+
should_use_schema = true;
|
|
39
|
+
constructor({ prompt = [["system", `Du bist ein hilfreicher Assistent.
|
|
40
|
+
WICHTIG:
|
|
41
|
+
- Nutze Tools NUR wenn nötig
|
|
42
|
+
- Nach jedem Tool-Call gib eine finale Antwort
|
|
43
|
+
- Stoppe nach der Antwort, rufe keine Tools mehr auf
|
|
44
|
+
- Wenn du die Antwort hast, gib sie direkt zurück`]], tools, llm, schema, memory }) {
|
|
45
|
+
this.prompt = prompt;
|
|
46
|
+
this.tools = tools;
|
|
47
|
+
this.llm = llm;
|
|
48
|
+
this.schema = schema;
|
|
49
|
+
this.memory = memory;
|
|
50
|
+
}
|
|
51
|
+
async invoke(invokeInput) {
|
|
52
|
+
const { input, thread_id, debug, ...variables } = invokeInput;
|
|
53
|
+
// Dynamische Variablen als System-Messages (thread_id wird NICHT als Message, sondern als config genutzt)
|
|
54
|
+
const contextMessages = Object.entries(variables).map(([key, value]) => ["system", `${key}: ${typeof value === "object" ? JSON.stringify(value) : value}`]);
|
|
55
|
+
// Tools für diesen invoke (inkl. RAG falls vorhanden)
|
|
56
|
+
const activeTools = this.rag_tool
|
|
57
|
+
? [...this.tools, this.rag_tool]
|
|
58
|
+
: this.tools;
|
|
59
|
+
this.agent = createReactAgent({
|
|
60
|
+
llm: this.llm,
|
|
61
|
+
tools: activeTools,
|
|
62
|
+
checkpointSaver: this.memory,
|
|
63
|
+
prompt: (state) => [
|
|
64
|
+
...this.prompt,
|
|
65
|
+
...contextMessages,
|
|
66
|
+
...state.messages
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
const config = thread_id && this.memory ? { configurable: { thread_id } } : undefined;
|
|
70
|
+
const result = await this.agent.invoke({ messages: [new HumanMessage(input)] }, config);
|
|
71
|
+
if (debug)
|
|
72
|
+
return result;
|
|
73
|
+
const lastMessage = result.messages[result.messages.length - 1];
|
|
74
|
+
const content = lastMessage.content;
|
|
75
|
+
if (this.schema && this.should_use_schema) {
|
|
76
|
+
return await structure({ data: content, into: this.schema, llm: this.llm });
|
|
77
|
+
}
|
|
78
|
+
return content;
|
|
79
|
+
}
|
|
80
|
+
async *stream(invokeInput) {
|
|
81
|
+
this.should_use_schema = false;
|
|
82
|
+
try {
|
|
83
|
+
const { stream_delay = 1, ...rest } = invokeInput;
|
|
84
|
+
const response = await this.invoke(rest);
|
|
85
|
+
const responseStr = typeof response === "string" ? response : JSON.stringify(response);
|
|
86
|
+
const words = responseStr.split(" ");
|
|
87
|
+
for await (const word of stream(words, stream_delay)) {
|
|
88
|
+
yield word + " ";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
this.should_use_schema = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
setContext(vectorStore, metadata = {}) {
|
|
96
|
+
this.vectorStore = vectorStore;
|
|
97
|
+
this.rag_tool = new DynamicStructuredTool({
|
|
98
|
+
name: metadata.name ?? "search_context",
|
|
99
|
+
description: metadata.description ?? "Search the knowledge base for relevant information",
|
|
100
|
+
schema: z.object({
|
|
101
|
+
query: z.string().describe("The search query")
|
|
102
|
+
}),
|
|
103
|
+
func: async ({ query }) => {
|
|
104
|
+
const docs = await this.vectorStore?.similaritySearch(query, 3);
|
|
105
|
+
if (!docs || docs.length === 0)
|
|
106
|
+
return "No relevant information found.";
|
|
107
|
+
return docs.map(doc => doc.pageContent).join("\n\n---\n\n");
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async addContext(data) {
|
|
112
|
+
if (!this.vectorStore) {
|
|
113
|
+
throw new Error("Cant add context, no vector store set");
|
|
114
|
+
}
|
|
115
|
+
this.times_of_added_context++;
|
|
116
|
+
const docs = turn_to_docs(data);
|
|
117
|
+
await this.vectorStore.addDocuments(docs);
|
|
118
|
+
console.log(`Added context ${this.times_of_added_context} ${this.times_of_added_context === 1 ? "time" : "times"}`);
|
|
119
|
+
}
|
|
120
|
+
clearContext() {
|
|
121
|
+
this.rag_tool = undefined;
|
|
122
|
+
this.vectorStore = undefined;
|
|
123
|
+
this.times_of_added_context = 0;
|
|
124
|
+
console.log("Context cleared");
|
|
125
|
+
}
|
|
126
|
+
hasContext() {
|
|
127
|
+
return this.vectorStore !== undefined && this.rag_tool !== undefined;
|
|
128
|
+
}
|
|
129
|
+
addTool(tool) {
|
|
130
|
+
this.tools.push(tool);
|
|
131
|
+
}
|
|
132
|
+
get currentTools() {
|
|
133
|
+
const tools = [...this.tools];
|
|
134
|
+
if (this.rag_tool) {
|
|
135
|
+
tools.push(this.rag_tool);
|
|
136
|
+
}
|
|
137
|
+
return tools.map(tool => tool.name);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# 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,EAAY,MAAM,YAAY,CAAA;AAI5D,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,CAAA;AAY7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,KAAK;IACN,MAAM,CAA2B;IACjC,KAAK,CAAyB;IAC9B,GAAG,CAAe;IAClB,MAAM,CAAe;IACrB,KAAK,CAAK;IACV,MAAM,CAAiC;IACvC,WAAW,CAAyB;IACpC,QAAQ,CAAmC;IAC3C,sBAAsB,GAAW,CAAC,CAAA;IAClC,iBAAiB,GAAY,IAAI,CAAA;IAEzC,YAAY,EACR,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE;;;;;8DAKiC,CAAC,CAAC,EACxD,KAAK,EACL,GAAG,EACH,MAAM,EACN,MAAM,EACM;QACZ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,K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AI,CAAC,sBAAsB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;IACvH,CAAC;IAEM,YAAY;QACf,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;QACzB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;QAC5B,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAA;QAC/B,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAClC,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,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,42 @@
|
|
|
1
|
+
import { BaseChatModel, MessagesPlaceholder, VectorStore } from "../imports";
|
|
2
|
+
import { z } from "zod/v3";
|
|
3
|
+
interface ChainProps<T extends z.ZodObject<any, any>> {
|
|
4
|
+
prompt?: Array<["human" | "system", string] | MessagesPlaceholder<any>>;
|
|
5
|
+
llm: BaseChatModel;
|
|
6
|
+
schema?: T;
|
|
7
|
+
}
|
|
8
|
+
export declare const DEFAULT_SCHEMA: z.ZodObject<{
|
|
9
|
+
output: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
output: string;
|
|
12
|
+
}, {
|
|
13
|
+
output: string;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* CONSTRUCTOR:
|
|
17
|
+
* @example constructor({prompt = [["system","du bist ein hilfreicher Assistent"]],llm = getLLM("groq"),schema}:ChainProps<T> = {}){
|
|
18
|
+
this.prompt = prompt
|
|
19
|
+
this.llm = llm
|
|
20
|
+
this.schema = (schema ?? DEFAULT_SCHEMA) as unknown as T
|
|
21
|
+
this.parser = StructuredOutputParser.fromZodSchema(this.schema)
|
|
22
|
+
}
|
|
23
|
+
*/
|
|
24
|
+
export declare class Chain<T extends z.ZodObject<any, any> = typeof DEFAULT_SCHEMA> {
|
|
25
|
+
private prompt;
|
|
26
|
+
private vectorStore;
|
|
27
|
+
private times_of_added_context;
|
|
28
|
+
private parser;
|
|
29
|
+
private llm;
|
|
30
|
+
private schema;
|
|
31
|
+
constructor({ prompt, llm, schema }: ChainProps<T>);
|
|
32
|
+
invoke(input: Record<string, any> & {
|
|
33
|
+
debug?: boolean;
|
|
34
|
+
}): Promise<z.infer<T>>;
|
|
35
|
+
stream(input: Record<string, any>): AsyncGenerator<string, void, unknown>;
|
|
36
|
+
/** Fügt RAG-Kontext hinzu. Docs werden EINMAL zum VectorStore hinzugefügt. */
|
|
37
|
+
addContext(data: Array<any>): Promise<void>;
|
|
38
|
+
setContext(vectorStore: VectorStore): Promise<void>;
|
|
39
|
+
clearContext(): void;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# 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;AAGnB,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE1B,UAAU,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,EAAC,GAAG,CAAC;IAC/C,MAAM,CAAC,EAAC,KAAK,CAAC,CAAC,OAAO,GAAG,QAAQ,EAAE,MAAM,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAA;IACtE,GAAG,EAAC,aAAa,CAAA;IACjB,MAAM,CAAC,EAAC,CAAC,CAAA;CACZ;AAED,eAAO,MAAM,cAAc;;;;;;EAEzB,CAAA;AAEF;;;;;;;;GAQG;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,MAAyD,EAAC,GAAG,EAAC,MAAM,EAAC,EAAC,UAAU,CAAC,CAAC,CAAC;IAOnF,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,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IAuDvF,8EAA8E;IACjE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAU3B,UAAU,CAAC,WAAW,EAAE,WAAW;IAKzC,YAAY;CAKtB"}
|
|
@@ -0,0 +1,152 @@
|
|
|
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 = [["system","du bist ein hilfreicher Assistent"]],llm = getLLM("groq"),schema}:ChainProps<T> = {}){
|
|
10
|
+
this.prompt = prompt
|
|
11
|
+
this.llm = llm
|
|
12
|
+
this.schema = (schema ?? DEFAULT_SCHEMA) as unknown as T
|
|
13
|
+
this.parser = StructuredOutputParser.fromZodSchema(this.schema)
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
export class Chain {
|
|
17
|
+
prompt;
|
|
18
|
+
vectorStore;
|
|
19
|
+
times_of_added_context = 0;
|
|
20
|
+
parser;
|
|
21
|
+
llm;
|
|
22
|
+
schema;
|
|
23
|
+
constructor({ prompt = [["system", "du bist ein hilfreicher Assistent"]], llm, schema }) {
|
|
24
|
+
this.prompt = prompt;
|
|
25
|
+
this.llm = llm;
|
|
26
|
+
this.schema = (schema ?? DEFAULT_SCHEMA);
|
|
27
|
+
this.parser = StructuredOutputParser.fromZodSchema(this.schema);
|
|
28
|
+
}
|
|
29
|
+
async invoke(input) {
|
|
30
|
+
const messagesArray = [...this.prompt];
|
|
31
|
+
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"]);
|
|
32
|
+
if (this.vectorStore)
|
|
33
|
+
messagesArray.push(["system", "Hier ist relevanter Kontext:\n{context}"]);
|
|
34
|
+
for (const key in input) {
|
|
35
|
+
if (key === "debug")
|
|
36
|
+
continue;
|
|
37
|
+
if (key === "thread_id") {
|
|
38
|
+
console.error("eine normale chain hat keine memory, deswegen wird thread_id ignoriert");
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (typeof input[key] !== "string") {
|
|
42
|
+
messagesArray.push(["human", `${key}:${JSON.stringify(input[key])}`]);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
messagesArray.push(["human", `${key}:{${key}}`]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const true_prompt = ChatPromptTemplate.fromMessages(messagesArray);
|
|
49
|
+
if (input.debug)
|
|
50
|
+
console.log("Prompt: ", true_prompt);
|
|
51
|
+
const invokeInput = { ...input, format_instructions: this.parser.getFormatInstructions() };
|
|
52
|
+
if (this.vectorStore) {
|
|
53
|
+
const retriever = this.vectorStore.asRetriever();
|
|
54
|
+
const stuff_chain = await createStuffDocumentsChain({
|
|
55
|
+
llm: this.llm,
|
|
56
|
+
prompt: true_prompt,
|
|
57
|
+
outputParser: this.parser
|
|
58
|
+
});
|
|
59
|
+
const chain = await createRetrievalChain({
|
|
60
|
+
combineDocsChain: stuff_chain,
|
|
61
|
+
retriever: retriever
|
|
62
|
+
});
|
|
63
|
+
if (input.debug)
|
|
64
|
+
console.log("created retrieval chain");
|
|
65
|
+
const respo = await chain.invoke({ input: JSON.stringify(input), ...invokeInput });
|
|
66
|
+
return this.schema.parse(respo.answer);
|
|
67
|
+
}
|
|
68
|
+
const chain = true_prompt.pipe(this.llm).pipe(this.parser);
|
|
69
|
+
if (input.debug)
|
|
70
|
+
console.log("created normal chain");
|
|
71
|
+
const respo = await chain.invoke(invokeInput);
|
|
72
|
+
return this.schema.parse(respo);
|
|
73
|
+
}
|
|
74
|
+
async *stream(input) {
|
|
75
|
+
const messagesArray = [...this.prompt];
|
|
76
|
+
// Beim Streamen KEIN Schema-Prompt - nur reiner Text
|
|
77
|
+
if (this.vectorStore)
|
|
78
|
+
messagesArray.push(["system", "Hier ist relevanter Kontext:\n{context}"]);
|
|
79
|
+
for (const key in input) {
|
|
80
|
+
if (key === "debug")
|
|
81
|
+
continue;
|
|
82
|
+
if (key === "thread_id") {
|
|
83
|
+
console.error("eine normale chain hat keine memory, deswegen wird thread_id ignoriert");
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (typeof input[key] !== "string") {
|
|
87
|
+
messagesArray.push(["human", `${key}:${JSON.stringify(input[key])}`]);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
messagesArray.push(["human", `${key}:{${key}}`]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const true_prompt = ChatPromptTemplate.fromMessages(messagesArray);
|
|
94
|
+
if (input.debug)
|
|
95
|
+
console.log("Prompt: ", true_prompt);
|
|
96
|
+
const invokeInput = { ...input };
|
|
97
|
+
if (this.vectorStore) {
|
|
98
|
+
const retriever = this.vectorStore.asRetriever();
|
|
99
|
+
if (input.debug)
|
|
100
|
+
console.log("created retrieval chain (streaming)");
|
|
101
|
+
// Für RAG: Hole Context und stream dann die LLM-Antwort
|
|
102
|
+
const contextDocs = await retriever.invoke(JSON.stringify(input));
|
|
103
|
+
const contextText = contextDocs.map((doc) => doc.pageContent).join("\n\n");
|
|
104
|
+
// Stream die LLM-Antwort mit Context
|
|
105
|
+
const streamChain = true_prompt.pipe(this.llm);
|
|
106
|
+
const stream = await streamChain.stream({ ...invokeInput, context: contextText });
|
|
107
|
+
for await (const chunk of stream) {
|
|
108
|
+
if (chunk && typeof chunk === 'object' && 'content' in chunk) {
|
|
109
|
+
yield chunk.content;
|
|
110
|
+
}
|
|
111
|
+
else if (typeof chunk === 'string') {
|
|
112
|
+
yield chunk;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// Ohne RAG: Stream direkt
|
|
118
|
+
const streamChain = true_prompt.pipe(this.llm);
|
|
119
|
+
if (input.debug)
|
|
120
|
+
console.log("created normal chain (streaming)");
|
|
121
|
+
const stream = await streamChain.stream(invokeInput);
|
|
122
|
+
for await (const chunk of stream) {
|
|
123
|
+
if (chunk && typeof chunk === 'object' && 'content' in chunk) {
|
|
124
|
+
yield chunk.content;
|
|
125
|
+
}
|
|
126
|
+
else if (typeof chunk === 'string') {
|
|
127
|
+
yield chunk;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Fügt RAG-Kontext hinzu. Docs werden EINMAL zum VectorStore hinzugefügt. */
|
|
133
|
+
async addContext(data) {
|
|
134
|
+
if (!this.vectorStore) {
|
|
135
|
+
throw new Error("Cant add context, no vector store set");
|
|
136
|
+
}
|
|
137
|
+
this.times_of_added_context++;
|
|
138
|
+
const docs = turn_to_docs(data);
|
|
139
|
+
await this.vectorStore.addDocuments(docs);
|
|
140
|
+
console.log(`Added context ${this.times_of_added_context} ${this.times_of_added_context === 1 ? "time" : "times"}`);
|
|
141
|
+
}
|
|
142
|
+
async setContext(vectorStore) {
|
|
143
|
+
console.log("Setting context");
|
|
144
|
+
this.vectorStore = vectorStore;
|
|
145
|
+
}
|
|
146
|
+
clearContext() {
|
|
147
|
+
this.vectorStore = undefined;
|
|
148
|
+
this.times_of_added_context = 0;
|
|
149
|
+
console.log("Context cleared");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# 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;AAErC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAQ1B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;CACnE,CAAC,CAAA;AAEF;;;;;;;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imports";
|
|
2
|
+
import { BaseChatModel } from "../imports";
|
|
3
|
+
type ChatbotProps = {
|
|
4
|
+
llm: BaseChatModel;
|
|
5
|
+
prompt?: Array<["system", string]>;
|
|
6
|
+
tools?: DynamicStructuredTool[];
|
|
7
|
+
memory?: BaseCheckpointSaver;
|
|
8
|
+
};
|
|
9
|
+
export declare class Chatbot {
|
|
10
|
+
private chain;
|
|
11
|
+
private agent;
|
|
12
|
+
constructor({ llm, prompt, tools, memory }: ChatbotProps);
|
|
13
|
+
chat({ input, thread_id }: {
|
|
14
|
+
input: string;
|
|
15
|
+
thread_id: string;
|
|
16
|
+
}): AsyncGenerator<string, string, unknown>;
|
|
17
|
+
session({ breakword, numberOfMessages, id }?: {
|
|
18
|
+
breakword?: string;
|
|
19
|
+
numberOfMessages?: number;
|
|
20
|
+
id?: string;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
addContext(data: Array<any>): Promise<void>;
|
|
23
|
+
setContext(vectorStore: VectorStore): Promise<void>;
|
|
24
|
+
clearContext(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# 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,EAAE,MAAM,YAAY,CAAA;AACvK,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAQ1C,KAAK,YAAY,GAAG;IAChB,GAAG,EAAE,aAAa,CAAA;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;IAClC,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAA;IAC/B,MAAM,CAAC,EAAE,mBAAmB,CAAA;CAC/B,CAAA;AAED,qBAAa,OAAO;IAChB,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,KAAK,CAAwB;gBAEzB,EAAC,GAAG,EAAC,MAAM,EAAC,KAAK,EAAC,MAAM,EAAC,EAAC,YAAY;IAiBpC,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,99 @@
|
|
|
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
|
+
export class Chatbot {
|
|
8
|
+
chain;
|
|
9
|
+
agent;
|
|
10
|
+
constructor({ llm, prompt, tools, memory }) {
|
|
11
|
+
if (tools) {
|
|
12
|
+
this.agent = new Agent({
|
|
13
|
+
memory: memory ?? new SmartCheckpointSaver(new MemorySaver(), { llm }),
|
|
14
|
+
tools: tools,
|
|
15
|
+
prompt: prompt,
|
|
16
|
+
llm: llm
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.chain = new MemoryChain({
|
|
21
|
+
memory: memory,
|
|
22
|
+
prompt: prompt,
|
|
23
|
+
llm: llm
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async *chat({ input, thread_id }) {
|
|
28
|
+
const streamable = this.chain ? this.chain : this.agent;
|
|
29
|
+
if (!streamable)
|
|
30
|
+
throw new Error("kein streamable!");
|
|
31
|
+
let fullResponse = "";
|
|
32
|
+
for await (const chunk of streamable.stream({ input, thread_id })) {
|
|
33
|
+
fullResponse += chunk;
|
|
34
|
+
yield chunk;
|
|
35
|
+
}
|
|
36
|
+
return fullResponse;
|
|
37
|
+
}
|
|
38
|
+
async session({ breakword = "exit", numberOfMessages = Number.POSITIVE_INFINITY, id = `${Date.now()}` } = {}) {
|
|
39
|
+
let messages = 0;
|
|
40
|
+
while (true) {
|
|
41
|
+
try {
|
|
42
|
+
const message = await input("You: ");
|
|
43
|
+
if (message === breakword) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
const response = this.chat({
|
|
47
|
+
input: message,
|
|
48
|
+
thread_id: id,
|
|
49
|
+
});
|
|
50
|
+
console.log("Assistant: ");
|
|
51
|
+
for await (const chunk of response) {
|
|
52
|
+
logChunk(chunk);
|
|
53
|
+
}
|
|
54
|
+
console.log(""); // Zeilenumbruch nach dem Streamen, damit Output nicht überschrieben wird
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error("Error: ", e);
|
|
58
|
+
}
|
|
59
|
+
messages = messages + 2;
|
|
60
|
+
if (messages > numberOfMessages) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async addContext(data) {
|
|
66
|
+
if (this.chain) {
|
|
67
|
+
await this.chain.addContext(data);
|
|
68
|
+
}
|
|
69
|
+
else if (this.agent) {
|
|
70
|
+
await this.agent.addContext(data);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw Error("weder agent noch chain, kein addContext möglich");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async setContext(vectorStore) {
|
|
77
|
+
if (this.chain) {
|
|
78
|
+
this.chain.setContext(vectorStore);
|
|
79
|
+
}
|
|
80
|
+
else if (this.agent) {
|
|
81
|
+
this.agent.setContext(vectorStore);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw Error("weder agent noch chain, kein setContext möglich");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async clearContext() {
|
|
88
|
+
if (this.chain) {
|
|
89
|
+
this.chain.clearContext();
|
|
90
|
+
}
|
|
91
|
+
else if (this.agent) {
|
|
92
|
+
this.agent.clearContext();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw Error("weder agent noch chain, kein clearContext möglich");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# 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,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAS/B,MAAM,OAAO,OAAO;IACR,KAAK,CAAyB;IAC9B,KAAK,CAAwB;IAErC,YAAY,EAAC,GAAG,EAAC,MAAM,EAAC,KAAK,EAAC,MAAM,EAAc;QAC9C,IAAG,KAAK,EAAC,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC;gBACnB,MAAM,EAAE,MAAM,IAAI,IAAI,oBAAoB,CAAC,IAAI,WAAW,EAAE,EAAC,EAAE,GAAG,EAAE,CAAC;gBACrE,KAAK,EAAG,KAAK;gBACb,MAAM,EAAE,MAA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