mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: include assistant messages in codex-mini-latest conversation context
- Updated convertMessagesToInput to include both user and assistant messages - Added role prefixes (User:/Assistant:) to maintain conversation context - Added test for multi-turn conversations to ensure proper handling - This fixes the issue where assistant responses were excluded in multi-turn conversations
This commit is contained in:
parent
d0c92ea82f
commit
dc71125eb7
2 changed files with 44 additions and 10 deletions
|
|
@ -483,7 +483,7 @@ describe("OpenAiNativeHandler", () => {
|
|||
expect(mockResponsesStream).toHaveBeenCalledWith({
|
||||
model: "codex-mini-latest",
|
||||
instructions: systemPrompt,
|
||||
input: "Hello!",
|
||||
input: "User: Hello!",
|
||||
})
|
||||
|
||||
const textChunks = chunks.filter((chunk) => chunk.type === "text")
|
||||
|
|
@ -492,6 +492,35 @@ describe("OpenAiNativeHandler", () => {
|
|||
expect(textChunks[1].text).toBe(" world")
|
||||
})
|
||||
|
||||
it("should handle multi-turn conversations with assistant messages", async () => {
|
||||
const multiTurnMessages: Anthropic.Messages.MessageParam[] = [
|
||||
{
|
||||
role: "user",
|
||||
content: "What is 2+2?",
|
||||
},
|
||||
{
|
||||
role: "assistant",
|
||||
content: "2+2 equals 4.",
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: "What about 3+3?",
|
||||
},
|
||||
]
|
||||
|
||||
const responseStream = handler.createMessage(systemPrompt, multiTurnMessages)
|
||||
const chunks: any[] = []
|
||||
for await (const chunk of responseStream) {
|
||||
chunks.push(chunk)
|
||||
}
|
||||
|
||||
expect(mockResponsesStream).toHaveBeenCalledWith({
|
||||
model: "codex-mini-latest",
|
||||
instructions: systemPrompt,
|
||||
input: "User: What is 2+2?\n\nAssistant: 2+2 equals 4.\n\nUser: What about 3+3?",
|
||||
})
|
||||
})
|
||||
|
||||
it("should handle non-streaming completion via v1/responses", async () => {
|
||||
const result = await handler.completePrompt("Test prompt")
|
||||
|
||||
|
|
|
|||
|
|
@ -173,15 +173,20 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
|
|||
private convertMessagesToInput(messages: Anthropic.Messages.MessageParam[]): string {
|
||||
return messages
|
||||
.map((msg) => {
|
||||
if (msg.role === "user") {
|
||||
if (typeof msg.content === "string") {
|
||||
return msg.content
|
||||
} else if (Array.isArray(msg.content)) {
|
||||
return msg.content
|
||||
.filter((part) => part.type === "text")
|
||||
.map((part) => part.text)
|
||||
.join("\n")
|
||||
}
|
||||
let content = ""
|
||||
|
||||
if (typeof msg.content === "string") {
|
||||
content = msg.content
|
||||
} else if (Array.isArray(msg.content)) {
|
||||
content = msg.content
|
||||
.filter((part) => part.type === "text")
|
||||
.map((part) => part.text)
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
// Include role prefix to maintain conversation context
|
||||
if (content) {
|
||||
return msg.role === "user" ? `User: ${content}` : `Assistant: ${content}`
|
||||
}
|
||||
return ""
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue