Fixed timestamp breaking api calls
All checks were successful
Publish Library / Build NPM Project (push) Successful in 34s
Publish Library / Tag Version (push) Successful in 8s

This commit is contained in:
2025-12-16 12:56:56 -05:00
parent 1a0351aeef
commit 0730f5f3f9
5 changed files with 26 additions and 28 deletions

View File

@@ -31,8 +31,9 @@ export class Ollama extends LLMProvider {
private fromStandard(history: LLMMessage[]): any[] {
return history.map((h: any) => {
if(h.role != 'tool') return h;
return {role: 'tool', tool_name: h.name, content: h.error || h.content, timestamp: h.timestamp}
const {timestamp, ...rest} = h;
if(h.role != 'tool') return rest;
return {role: 'tool', tool_name: h.name, content: h.error || h.content}
});
}
@@ -90,22 +91,21 @@ export class Ollama extends LLMProvider {
}
loopMessages.push({role: 'assistant', content: resp.message?.content, timestamp: Date.now()});
if(resp.message?.tool_calls?.length && !controller.signal.aborted) {
history.push({...resp.message, timestamp: Date.now()});
history.push(resp.message);
const results = await Promise.all(resp.message.tool_calls.map(async (toolCall: any) => {
const tool = (options.tools || this.ai.options.tools)?.find(findByProp('name', toolCall.function.name));
if(!tool) return {role: 'tool', tool_name: toolCall.function.name, content: '{"error": "Tool not found"}', timestamp: Date.now()};
if(!tool) return {role: 'tool', tool_name: toolCall.function.name, content: '{"error": "Tool not found"}'};
const args = typeof toolCall.function.arguments === 'string' ? JSONAttemptParse(toolCall.function.arguments, {}) : toolCall.function.arguments;
try {
const result = await tool.fn(args, this.ai);
return {role: 'tool', tool_name: toolCall.function.name, args, content: JSONSanitize(result), timestamp: Date.now()};
return {role: 'tool', tool_name: toolCall.function.name, args, content: JSONSanitize(result)};
} catch (err: any) {
return {role: 'tool', tool_name: toolCall.function.name, args, content: JSONSanitize({error: err?.message || err?.toString() || 'Unknown'}), timestamp: Date.now()};
return {role: 'tool', tool_name: toolCall.function.name, args, content: JSONSanitize({error: err?.message || err?.toString() || 'Unknown'})};
}
}));
history.push(...results);
loopMessages.push(...results);
loopMessages.push(...results.map(r => ({...r, timestamp: Date.now()})));
requestParams.messages = history;
}
} while (!controller.signal.aborted && resp.message?.tool_calls?.length);