mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Merge pull request #86 from RooVetGit/fix-openai-compatible-streaming
Add 'Include stream options' checkbox for OpenAI-compatible providers
This commit is contained in:
@@ -32,18 +32,24 @@ export class OpenAiHandler implements ApiHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include stream_options for OpenAI Compatible providers if the checkbox is checked
|
||||||
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
|
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
|
||||||
const openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
|
const openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
|
||||||
{ role: "system", content: systemPrompt },
|
{ role: "system", content: systemPrompt },
|
||||||
...convertToOpenAiMessages(messages),
|
...convertToOpenAiMessages(messages),
|
||||||
]
|
]
|
||||||
const stream = await this.client.chat.completions.create({
|
const requestOptions: OpenAI.Chat.ChatCompletionCreateParams = {
|
||||||
model: this.options.openAiModelId ?? "",
|
model: this.options.openAiModelId ?? "",
|
||||||
messages: openAiMessages,
|
messages: openAiMessages,
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
stream: true,
|
stream: true,
|
||||||
stream_options: { include_usage: true },
|
}
|
||||||
})
|
|
||||||
|
if (this.options.includeStreamOptions ?? true) {
|
||||||
|
requestOptions.stream_options = { include_usage: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
const stream = await this.client.chat.completions.create(requestOptions)
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
const delta = chunk.choices[0]?.delta
|
const delta = chunk.choices[0]?.delta
|
||||||
if (delta?.content) {
|
if (delta?.content) {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ export interface ApiHandlerOptions {
|
|||||||
openAiNativeApiKey?: string
|
openAiNativeApiKey?: string
|
||||||
azureApiVersion?: string
|
azureApiVersion?: string
|
||||||
openRouterUseMiddleOutTransform?: boolean
|
openRouterUseMiddleOutTransform?: boolean
|
||||||
|
includeStreamOptions?: boolean
|
||||||
|
setAzureApiVersion?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ApiConfiguration = ApiHandlerOptions & {
|
export type ApiConfiguration = ApiHandlerOptions & {
|
||||||
|
|||||||
@@ -445,6 +445,24 @@ const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage }:
|
|||||||
placeholder={"Enter Model ID..."}>
|
placeholder={"Enter Model ID..."}>
|
||||||
<span style={{ fontWeight: 500 }}>Model ID</span>
|
<span style={{ fontWeight: 500 }}>Model ID</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
<VSCodeCheckbox
|
||||||
|
checked={apiConfiguration?.includeStreamOptions ?? true}
|
||||||
|
onChange={(e: any) => {
|
||||||
|
const isChecked = e.target.checked
|
||||||
|
setApiConfiguration({
|
||||||
|
...apiConfiguration,
|
||||||
|
includeStreamOptions: isChecked
|
||||||
|
})
|
||||||
|
}}>
|
||||||
|
Include stream options
|
||||||
|
</VSCodeCheckbox>
|
||||||
|
<span
|
||||||
|
className="codicon codicon-info"
|
||||||
|
title="Stream options are for { include_usage: true }. Some providers may not support this option."
|
||||||
|
style={{ marginLeft: '5px', cursor: 'help' }}
|
||||||
|
></span>
|
||||||
|
</div>
|
||||||
<VSCodeCheckbox
|
<VSCodeCheckbox
|
||||||
checked={azureApiVersionSelected}
|
checked={azureApiVersionSelected}
|
||||||
onChange={(e: any) => {
|
onChange={(e: any) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user