Changesets · Branches · Tags · Compare
| Changeset | 33f5452d0cbfe2db88b4fdf14de609c805c9eb7f0cd9566ebc243a2db487a765 |
|---|---|
| Author | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-05-09 13:36 -07:00 |
| Committer | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-05-09 13:36 -07:00 |
| Parents | 2e6956dfd5fc |
1 file changed
modified core/llm/llms/Ollama.ts +10 −8
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { Mutex } from "async-mutex"; |
| 2 | 2 | import { JSONSchema7, JSONSchema7Object } from "json-schema"; |
| 3 | +import { v4 as uuidv4 } from "uuid"; | |
| 3 | 4 | |
| 4 | 5 | import { |
| 5 | 6 | ChatMessage, |
| @@ -90,10 +91,10 @@ | ||
| 90 | 91 | model: string; |
| 91 | 92 | created_at: string; |
| 92 | 93 | } & ( |
| 93 | - | { | |
| 94 | + | { | |
| 94 | 95 | done: false; |
| 95 | 96 | } |
| 96 | - | { | |
| 97 | + | { | |
| 97 | 98 | done: true; |
| 98 | 99 | done_reason: string; |
| 99 | 100 | total_duration: number; // Time spent generating the response in nanoseconds |
| @@ -104,7 +105,7 @@ | ||
| 104 | 105 | eval_duration: number; // Time spent generating the response in nanoseconds |
| 105 | 106 | context: number[]; // An encoding of the conversation used in this response; can be sent in the next request to keep conversational memory |
| 106 | 107 | } |
| 107 | - ); | |
| 108 | +); | |
| 108 | 109 | |
| 109 | 110 | type OllamaErrorResponse = { |
| 110 | 111 | error: string; |
| @@ -113,14 +114,14 @@ | ||
| 113 | 114 | type OllamaRawResponse = |
| 114 | 115 | | OllamaErrorResponse |
| 115 | 116 | | (OllamaBaseResponse & { |
| 116 | - response: string; // the generated response | |
| 117 | - }); | |
| 117 | + response: string; // the generated response | |
| 118 | + }); | |
| 118 | 119 | |
| 119 | 120 | type OllamaChatResponse = |
| 120 | 121 | | OllamaErrorResponse |
| 121 | 122 | | (OllamaBaseResponse & { |
| 122 | - message: OllamaChatMessage; | |
| 123 | - }); | |
| 123 | + message: OllamaChatMessage; | |
| 124 | + }); | |
| 124 | 125 | |
| 125 | 126 | interface OllamaTool { |
| 126 | 127 | type: "function"; |
| @@ -370,7 +371,7 @@ | ||
| 370 | 371 | if ("error" in j) { |
| 371 | 372 | throw new Error(j.error); |
| 372 | 373 | } |
| 373 | - j.response ??= '' | |
| 374 | + j.response ??= ""; | |
| 374 | 375 | yield j.response; |
| 375 | 376 | } catch (e) { |
| 376 | 377 | throw new Error(`Error parsing Ollama response: ${e} ${chunk}`); |
| @@ -439,6 +440,7 @@ | ||
| 439 | 440 | // But ollama returns the full object in one response with no streaming |
| 440 | 441 | chatMessage.toolCalls = res.message.tool_calls.map((tc) => ({ |
| 441 | 442 | type: "function", |
| 443 | + id: `tc_${uuidv4()}`, // Generate a proper UUID with a prefix | |
| 442 | 444 | function: { |
| 443 | 445 | name: tc.function.name, |
| 444 | 446 | arguments: JSON.stringify(tc.function.arguments), |