Fixed timestamp breaking api calls
This commit is contained in:
@@ -39,13 +39,13 @@ export class Anthropic extends LLMProvider {
|
||||
if(history[i].role == 'tool') {
|
||||
const h: any = history[i];
|
||||
history.splice(i, 1,
|
||||
{role: 'assistant', content: [{type: 'tool_use', id: h.id, name: h.name, input: h.args}], timestamp: h.timestamp},
|
||||
{role: 'user', content: [{type: 'tool_result', tool_use_id: h.id, is_error: !!h.error, content: h.error || h.content}], timestamp: Date.now()}
|
||||
{role: 'assistant', content: [{type: 'tool_use', id: h.id, name: h.name, input: h.args}]},
|
||||
{role: 'user', content: [{type: 'tool_result', tool_use_id: h.id, is_error: !!h.error, content: h.error || h.content}]}
|
||||
)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return history;
|
||||
return history.map(({timestamp, ...h}) => h);
|
||||
}
|
||||
|
||||
ask(message: string, options: LLMRequest = {}): AbortablePromise<LLMMessage[]> {
|
||||
@@ -107,7 +107,7 @@ export class Anthropic extends LLMProvider {
|
||||
loopMessages.push({role: 'assistant', content: resp.content, timestamp: Date.now()});
|
||||
const toolCalls = resp.content.filter((c: any) => c.type === 'tool_use');
|
||||
if(toolCalls.length && !controller.signal.aborted) {
|
||||
history.push({role: 'assistant', content: resp.content, timestamp: Date.now()});
|
||||
history.push({role: 'assistant', content: resp.content});
|
||||
const results = await Promise.all(toolCalls.map(async (toolCall: any) => {
|
||||
const tool = options.tools?.find(findByProp('name', toolCall.name));
|
||||
if(!tool) return {tool_use_id: toolCall.id, is_error: true, content: 'Tool not found'};
|
||||
@@ -118,9 +118,9 @@ export class Anthropic extends LLMProvider {
|
||||
return {type: 'tool_result', tool_use_id: toolCall.id, is_error: true, content: err?.message || err?.toString() || 'Unknown'};
|
||||
}
|
||||
}));
|
||||
const userMsg = {role: 'user', content: results, timestamp: Date.now()};
|
||||
const userMsg = {role: 'user', content: results};
|
||||
history.push(userMsg);
|
||||
loopMessages.push(userMsg);
|
||||
loopMessages.push({...userMsg, timestamp: Date.now()});
|
||||
requestParams.messages = history;
|
||||
}
|
||||
} while (!controller.signal.aborted && resp.content.some((c: any) => c.type === 'tool_use'));
|
||||
|
||||
Reference in New Issue
Block a user