Merge pull request #5425 from continuedev/dallin/chat-titles

Fix [Object object] chat title generation
This commit is contained in:
Nate Sesti 2025-04-29 14:17:29 -07:00 • committed by GitHub
commit b714d23b3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 33 deletions

View file

@ -71,7 +71,11 @@ export class LLMError extends Error {
}
export function isModelInstaller(provider: any): provider is ModelInstaller {
return provider && typeof provider.installModel === "function" && typeof provider.isInstallingModel === "function";;
return (
provider &&
typeof provider.installModel === "function" &&
typeof provider.isInstallingModel === "function"
);
}
type InteractionStatus = "in_progress" | "success" | "error" | "cancelled";
@ -816,8 +820,8 @@ export abstract class BaseLLM implements ILLM {
options: LLMFullCompletionOptions = {},
) {
let completion = "";
for await (const chunk of this.streamChat(messages, signal, options)) {
completion += chunk.content;
for await (const message of this.streamChat(messages, signal, options)) {
completion += renderChatMessage(message);
}
return { role: "assistant" as const, content: completion };
}

View file

@ -1,7 +1,11 @@
import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
import { BaseLLM } from "../index.js";
type MockMessage = ChatMessage | "REPEAT_LAST_MSG" | "REPEAT_SYSTEM_MSG";
type MockMessage =
| ChatMessage
| "REPEAT_LAST_MSG"
| "REPEAT_SYSTEM_MSG"
| "ERROR";
class MockLLM extends BaseLLM {
public completion: string = "Test Completion";
@ -49,6 +53,8 @@ class MockLLM extends BaseLLM {
messages.find((m) => m.role === "system")?.content || "",
};
break;
case "ERROR":
throw new Error("Intentional error");
default:
yield message;
}

View file

@ -34,43 +34,21 @@ describe("ChatDescriber", () => {
const message = "Test message";
const completionOptions: LLMFullCompletionOptions = { temperature: 0.7 };
testLLM.chat = jest.fn().mockResolvedValue({ content: "Test response" });
testLLM.chatStreams = [[{ role: "assistant", content: "Test response" }]];
await ChatDescriber.describe(testLLM, completionOptions, message);
expect(completionOptions.maxTokens).toBe(ChatDescriber.maxTokens);
});
it("should call model.chat with correct parameters", async () => {
const message = "Test message";
const cleanedMessage = "Test message";
const expectedPrompt = ChatDescriber.prompt + cleanedMessage;
const completionOptions: LLMFullCompletionOptions = {};
testLLM.chat = jest.fn().mockResolvedValue({ content: "Test response" });
await ChatDescriber.describe(testLLM, completionOptions, message);
expect(testLLM.chat).toHaveBeenCalledWith(
[
{
role: "user",
content: expectedPrompt,
},
],
expect.any(AbortSignal),
completionOptions,
);
});
it("should return processed content from the model response", async () => {
const message = "Test message";
const modelResponseContent = "Model response content";
const expectedResult = "Model response content";
testLLM.chat = jest
.fn()
.mockResolvedValue({ content: modelResponseContent });
testLLM.chatStreams = [
[{ role: "assistant", content: modelResponseContent }],
];
const result = await ChatDescriber.describe(testLLM, {}, message);
@ -81,11 +59,11 @@ describe("ChatDescriber", () => {
const message = "Test message";
const completionOptions: LLMFullCompletionOptions = {};
testLLM.chat = jest.fn().mockRejectedValue(new Error("Chat error"));
testLLM.chatStreams = [["ERROR"]];
await expect(
ChatDescriber.describe(testLLM, completionOptions, message),
).rejects.toThrow("Chat error");
).rejects.toThrow();
});
});
});

View file

@ -4,6 +4,7 @@ import { removeCodeBlocksAndTrim, removeQuotesAndEscapes } from ".";
import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
import type { IMessenger } from "../protocol/messenger";
import { renderChatMessage } from "./messageContent";
export class ChatDescriber {
static maxTokens = 12;
@ -42,7 +43,7 @@ export class ChatDescriber {
);
// Set the title
return removeQuotesAndEscapes(titleResponse.content.toString());
return removeQuotesAndEscapes(renderChatMessage(titleResponse));
}
// // TODO: Allow the user to manually set specific/tailored prompts to generate their titles