toolcalls

This commit is contained in:
Andrew Pareles 2025-02-16 20:51:42 -08:00
parent 432a1766af
commit 628adedaec
4 changed files with 10 additions and 10 deletions

View file

@ -326,15 +326,15 @@ class ChatThreadService extends Disposable implements IChatThreadService {
onText: ({ fullText }) => {
this._setStreamState(threadId, { messageSoFar: fullText })
},
onFinalMessage: async ({ fullText, toolCalls: tools }) => {
console.log('FINAL MESSAGE', fullText, tools)
onFinalMessage: async ({ fullText, toolCalls }) => {
console.log('FINAL MESSAGE', fullText, toolCalls)
if ((tools?.length ?? 0) === 0) {
if ((toolCalls?.length ?? 0) === 0) {
this._finishStreamingTextMessage(threadId, fullText)
}
else {
this._addMessageToThread(threadId, { role: 'assistant', content: fullText, displayContent: fullText, tool_calls: tools })
for (const tool of tools ?? []) {
this._addMessageToThread(threadId, { role: 'assistant', content: fullText, displayContent: fullText, tool_calls: toolCalls })
for (const tool of toolCalls ?? []) {
if (!(tool.name in this._toolsService.toolFns)) {
this._addMessageToThread(threadId, { role: 'tool', name: tool.name, params: tool.params, id: tool.id, content: `Error: This tool was not recognized, so it was not called.`, displayContent: `Error: tool not recognized.`, })
}

View file

@ -86,9 +86,9 @@ export const sendAnthropicChat: _InternalSendLLMChatMessageFnType = ({ messages:
stream.on('finalMessage', (response) => {
// stringify the response's content
const content = response.content.map(c => c.type === 'text' ? c.text : '').join('\n\n')
const tools = response.content.map(c => c.type === 'tool_use' ? { name: c.name, params: JSON.stringify(c.input), id: c.id } : null).filter(c => !!c)
const toolCalls = response.content.map(c => c.type === 'tool_use' ? { name: c.name, params: JSON.stringify(c.input), id: c.id } : null).filter(c => !!c)
onFinalMessage({ fullText: content, toolCalls: tools })
onFinalMessage({ fullText: content, toolCalls })
})
stream.on('error', (error) => {

View file

@ -62,10 +62,10 @@ export const sendLLMMessage = ({
_fullTextSoFar = fullText
}
const onFinalMessage: OnFinalMessage = ({ fullText, toolCalls: tools }) => {
const onFinalMessage: OnFinalMessage = ({ fullText, toolCalls }) => {
if (_didAbort) return
captureLLMEvent(`${loggingName} - Received Full Message`, { messageLength: fullText.length, duration: new Date().getMilliseconds() - submit_time.getMilliseconds() })
onFinalMessage_({ fullText, toolCalls: tools })
onFinalMessage_({ fullText, toolCalls })
}
const onError: OnError = ({ message: error, fullError }) => {

View file

@ -100,7 +100,7 @@ export class LLMMessageChannel implements IServerChannel {
const mainThreadParams: SendLLMMessageParams = {
...params,
onText: ({ newText, fullText }) => { this._onText_llm.fire({ requestId, newText, fullText }); },
onFinalMessage: ({ fullText, toolCalls: tools }) => { this._onFinalMessage_llm.fire({ requestId, fullText, toolCalls: tools }); },
onFinalMessage: ({ fullText, toolCalls }) => { this._onFinalMessage_llm.fire({ requestId, fullText, toolCalls }); },
onError: ({ message: error, fullError }) => { console.log('sendLLM: firing err'); this._onError_llm.fire({ requestId, message: error, fullError }); },
abortRef: this._abortRefOfRequestId_llm[requestId],
}