added tool calls to completions in agent dev data

This commit is contained in:
adarshramiyer 2025-06-25 15:45:15 -07:00
parent 61f9592a33
commit a5d80dce9b
2 changed files with 34 additions and 24 deletions

View file

@ -492,28 +492,32 @@ export abstract class BaseLLM implements ILLM {
const msgsCopy = messages ? messages.map((msg) => ({ ...msg })) : [];
let formatted = "";
for (const msg of msgsCopy) {
let contentToShow = "";
if (msg.role === "tool") {
contentToShow = msg.content;
} else if (msg.role === "assistant" && msg.toolCalls) {
contentToShow = msg.toolCalls
?.map(
(toolCall) =>
`${toolCall.function?.name}(${toolCall.function?.arguments})`,
)
.join("\n");
} else if ("content" in msg) {
if (Array.isArray(msg.content)) {
msg.content = renderChatMessage(msg);
}
contentToShow = msg.content;
}
formatted += `<${msg.role}>\n${contentToShow}\n\n`;
formatted += this._formatChatMessage(msg);
}
return formatted;
}
private _formatChatMessage(msg: ChatMessage): string {
let contentToShow = "";
if (msg.role === "tool") {
contentToShow = msg.content;
} else if (msg.role === "assistant" && msg.toolCalls) {
contentToShow = msg.toolCalls
?.map(
(toolCall) =>
`${toolCall.function?.name}(${toolCall.function?.arguments})`,
)
.join("\n");
} else if ("content" in msg) {
if (Array.isArray(msg.content)) {
msg.content = renderChatMessage(msg);
}
contentToShow = msg.content;
}
return `<${msg.role}>\n${contentToShow}\n\n`;
}
protected async *_streamFim(
prefix: string,
suffix: string,
@ -569,11 +573,12 @@ export abstract class BaseLLM implements ILLM {
const result = fromChatCompletionChunk(chunk);
if (result) {
const content = renderChatMessage(result);
const formattedContent = this._formatChatMessage(result);
interaction?.logItem({
kind: "chunk",
chunk: content,
chunk: formattedContent,
});
completion += content;
completion += formattedContent;
yield content;
}
}
@ -932,7 +937,7 @@ export abstract class BaseLLM implements ILLM {
);
const msg = fromChatResponse(response);
yield msg;
completion = renderChatMessage(msg);
completion = this._formatChatMessage(msg);
} else {
// Stream true
const stream = this.openaiAdapter.chatCompletionStream(
@ -945,7 +950,7 @@ export abstract class BaseLLM implements ILLM {
for await (const chunk of stream) {
const result = fromChatCompletionChunk(chunk);
if (result) {
completion += result.content;
completion += this._formatChatMessage(result);
interaction?.logItem({
kind: "message",
message: result,
@ -961,7 +966,7 @@ export abstract class BaseLLM implements ILLM {
completionOptions,
)) {
if (chunk.role === "assistant") {
completion += chunk.content;
completion += this._formatChatMessage(chunk);
} else if (chunk.role === "thinking") {
thinking += chunk.content;
}

View file

@ -139,7 +139,7 @@
},
"../packages/config-yaml": {
"name": "@continuedev/config-yaml",
"version": "1.0.94",
"version": "1.0.95",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/config-types": "^1.0.14",
@ -150,10 +150,15 @@
"config-yaml": "dist/cli.js"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.2.6",
"@semantic-release/npm": "^10.0.6",
"@types/jest": "^29.5.14",
"@types/node": "^20.0.0",
"cross-env": "^7.0.3",
"jest": "^29.7.0",
"semantic-release": "^21.1.2",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"zod-to-json-schema": "^3.24.5"