Elffuss BraidHub

kikocis/continue public

fix: ollama tool use
Changeset33f5452d0cbfe2db88b4fdf14de609c805c9eb7f0cd9566ebc243a2db487a765
AuthorTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-05-09 13:36 -07:00
CommitterTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-05-09 13:36 -07:00
Parents2e6956dfd5fc

Browse the files at this changeset

1 file changed

modified core/llm/llms/Ollama.ts +10 −8
@@ -1,5 +1,6 @@
11 import { Mutex } from "async-mutex";
22 import { JSONSchema7, JSONSchema7Object } from "json-schema";
3+import { v4 as uuidv4 } from "uuid";
34
45 import {
56 ChatMessage,
@@ -90,10 +91,10 @@
9091 model: string;
9192 created_at: string;
9293 } & (
93- | {
94+ | {
9495 done: false;
9596 }
96- | {
97+ | {
9798 done: true;
9899 done_reason: string;
99100 total_duration: number; // Time spent generating the response in nanoseconds
@@ -104,7 +105,7 @@
104105 eval_duration: number; // Time spent generating the response in nanoseconds
105106 context: number[]; // An encoding of the conversation used in this response; can be sent in the next request to keep conversational memory
106107 }
107- );
108+);
108109
109110 type OllamaErrorResponse = {
110111 error: string;
@@ -113,14 +114,14 @@
113114 type OllamaRawResponse =
114115 | OllamaErrorResponse
115116 | (OllamaBaseResponse & {
116- response: string; // the generated response
117- });
117+ response: string; // the generated response
118+ });
118119
119120 type OllamaChatResponse =
120121 | OllamaErrorResponse
121122 | (OllamaBaseResponse & {
122- message: OllamaChatMessage;
123- });
123+ message: OllamaChatMessage;
124+ });
124125
125126 interface OllamaTool {
126127 type: "function";
@@ -370,7 +371,7 @@
370371 if ("error" in j) {
371372 throw new Error(j.error);
372373 }
373- j.response ??= ''
374+ j.response ??= "";
374375 yield j.response;
375376 } catch (e) {
376377 throw new Error(`Error parsing Ollama response: ${e} ${chunk}`);
@@ -439,6 +440,7 @@
439440 // But ollama returns the full object in one response with no streaming
440441 chatMessage.toolCalls = res.message.tool_calls.map((tc) => ({
441442 type: "function",
443+ id: `tc_${uuidv4()}`, // Generate a proper UUID with a prefix
442444 function: {
443445 name: tc.function.name,
444446 arguments: JSON.stringify(tc.function.arguments),