mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: remove stream_options parameter from SambaNova API calls to resolve 400 error
- Override createStream method in SambaNovaHandler to exclude stream_options - SambaNova API does not support stream_options parameter - Update test to verify stream_options is not included in requests - Fixes #9975
This commit is contained in:
parent
a1d3a43aa5
commit
c649bd2d32
2 changed files with 56 additions and 2 deletions
|
|
@ -113,7 +113,7 @@ describe("SambaNovaHandler", () => {
|
|||
expect(firstChunk.value).toMatchObject({ type: "usage", inputTokens: 10, outputTokens: 20 })
|
||||
})
|
||||
|
||||
it("createMessage should pass correct parameters to SambaNova client", async () => {
|
||||
it("createMessage should pass correct parameters to SambaNova client without stream_options", async () => {
|
||||
const modelId: SambaNovaModelId = "Meta-Llama-3.3-70B-Instruct"
|
||||
const modelInfo = sambaNovaModels[modelId]
|
||||
const handlerWithModel = new SambaNovaHandler({
|
||||
|
|
@ -137,6 +137,7 @@ describe("SambaNovaHandler", () => {
|
|||
const messageGenerator = handlerWithModel.createMessage(systemPrompt, messages)
|
||||
await messageGenerator.next()
|
||||
|
||||
// Verify that stream_options is NOT included in the request
|
||||
expect(mockCreate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
model: modelId,
|
||||
|
|
@ -144,9 +145,12 @@ describe("SambaNovaHandler", () => {
|
|||
temperature: 0.7,
|
||||
messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]),
|
||||
stream: true,
|
||||
stream_options: { include_usage: true },
|
||||
}),
|
||||
undefined,
|
||||
)
|
||||
|
||||
// Explicitly verify stream_options is not present
|
||||
const callArgs = mockCreate.mock.calls[0][0]
|
||||
expect(callArgs).not.toHaveProperty("stream_options")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
import { Anthropic } from "@anthropic-ai/sdk"
|
||||
import OpenAI from "openai"
|
||||
|
||||
import { type SambaNovaModelId, sambaNovaDefaultModelId, sambaNovaModels } from "@roo-code/types"
|
||||
|
||||
import type { ApiHandlerOptions } from "../../shared/api"
|
||||
import { getModelMaxOutputTokens } from "../../shared/api"
|
||||
import { convertToOpenAiMessages } from "../transform/openai-format"
|
||||
import type { ApiHandlerCreateMessageMetadata } from "../index"
|
||||
|
||||
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
|
||||
|
||||
|
|
@ -16,4 +22,48 @@ export class SambaNovaHandler extends BaseOpenAiCompatibleProvider<SambaNovaMode
|
|||
defaultTemperature: 0.7,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Override createStream to exclude stream_options parameter.
|
||||
* SambaNova API does not support the stream_options parameter and returns a 400 error when it's included.
|
||||
*/
|
||||
protected override createStream(
|
||||
systemPrompt: string,
|
||||
messages: Anthropic.Messages.MessageParam[],
|
||||
metadata?: ApiHandlerCreateMessageMetadata,
|
||||
requestOptions?: OpenAI.RequestOptions,
|
||||
) {
|
||||
const { id: model, info } = this.getModel()
|
||||
|
||||
const max_tokens =
|
||||
getModelMaxOutputTokens({
|
||||
modelId: model,
|
||||
model: info,
|
||||
settings: this.options,
|
||||
format: "openai",
|
||||
}) ?? undefined
|
||||
|
||||
const temperature = this.options.modelTemperature ?? this.defaultTemperature
|
||||
|
||||
const params: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
|
||||
model,
|
||||
max_tokens,
|
||||
temperature,
|
||||
messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
|
||||
stream: true,
|
||||
// Note: stream_options is intentionally excluded for SambaNova compatibility
|
||||
...(metadata?.tools && { tools: this.convertToolsForOpenAI(metadata.tools) }),
|
||||
...(metadata?.tool_choice && { tool_choice: metadata.tool_choice }),
|
||||
...(metadata?.toolProtocol === "native" && {
|
||||
parallel_tool_calls: metadata.parallelToolCalls ?? false,
|
||||
}),
|
||||
}
|
||||
|
||||
// Add thinking parameter if reasoning is enabled and model supports it
|
||||
if (this.options.enableReasoningEffort && info.supportsReasoningBinary) {
|
||||
;(params as any).thinking = { type: "enabled" }
|
||||
}
|
||||
|
||||
return this.client.chat.completions.create(params, requestOptions)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue