mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-09 03:17:58 +00:00
Merge 17321d5042 into c3cae397a1
This commit is contained in:
commit
dcff9f8c35
3 changed files with 46 additions and 4 deletions
|
|
@ -373,7 +373,7 @@ export const mainlandZAiModels = {
|
||||||
},
|
},
|
||||||
} as const satisfies Record<string, ModelInfo>
|
} as const satisfies Record<string, ModelInfo>
|
||||||
|
|
||||||
export const ZAI_DEFAULT_TEMPERATURE = 0.6
|
export const ZAI_DEFAULT_TEMPERATURE = 1
|
||||||
|
|
||||||
export const zaiApiLineConfigs = {
|
export const zaiApiLineConfigs = {
|
||||||
international_coding: {
|
international_coding: {
|
||||||
|
|
|
||||||
|
|
@ -395,6 +395,7 @@ describe("ZAiHandler", () => {
|
||||||
model: modelId,
|
model: modelId,
|
||||||
max_tokens: expectedMaxTokens,
|
max_tokens: expectedMaxTokens,
|
||||||
temperature: ZAI_DEFAULT_TEMPERATURE,
|
temperature: ZAI_DEFAULT_TEMPERATURE,
|
||||||
|
top_p: 0.95,
|
||||||
messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]),
|
messages: expect.arrayContaining([{ role: "system", content: systemPrompt }]),
|
||||||
stream: true,
|
stream: true,
|
||||||
stream_options: { include_usage: true },
|
stream_options: { include_usage: true },
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override createStream to handle GLM-4.7's thinking mode.
|
* Override createStream to handle GLM-4.7's thinking mode and add top_p parameter.
|
||||||
* GLM-4.7 has thinking enabled by default in the API, so we need to
|
* GLM-4.7 has thinking enabled by default in the API, so we need to
|
||||||
* explicitly send { type: "disabled" } when the user turns off reasoning.
|
* explicitly send { type: "disabled" } when the user turns off reasoning.
|
||||||
*/
|
*/
|
||||||
|
|
@ -64,8 +64,48 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
||||||
return this.createStreamWithThinking(systemPrompt, messages, metadata, useReasoning)
|
return this.createStreamWithThinking(systemPrompt, messages, metadata, useReasoning)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For non-thinking models, use the default behavior
|
// For non-thinking models, use the default behavior with added top_p
|
||||||
return super.createStream(systemPrompt, messages, metadata, requestOptions)
|
return this.createStreamWithTopP(systemPrompt, messages, metadata, requestOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a stream with top_p parameter for non-thinking models
|
||||||
|
*/
|
||||||
|
private createStreamWithTopP(
|
||||||
|
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 ?? info.defaultTemperature ?? this.defaultTemperature
|
||||||
|
|
||||||
|
const params: OpenAI.Chat.ChatCompletionCreateParamsStreaming = {
|
||||||
|
model,
|
||||||
|
max_tokens,
|
||||||
|
temperature,
|
||||||
|
top_p: 0.95,
|
||||||
|
messages: [
|
||||||
|
{ role: "system", content: systemPrompt },
|
||||||
|
...convertToZAiFormat(messages, { mergeToolResultText: true }),
|
||||||
|
],
|
||||||
|
stream: true,
|
||||||
|
stream_options: { include_usage: true },
|
||||||
|
tools: this.convertToolsForOpenAI(metadata?.tools),
|
||||||
|
tool_choice: metadata?.tool_choice,
|
||||||
|
parallel_tool_calls: metadata?.parallelToolCalls ?? false,
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client.chat.completions.create(params, requestOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,6 +136,7 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
|
||||||
model,
|
model,
|
||||||
max_tokens,
|
max_tokens,
|
||||||
temperature,
|
temperature,
|
||||||
|
top_p: 0.95,
|
||||||
messages: [{ role: "system", content: systemPrompt }, ...convertedMessages],
|
messages: [{ role: "system", content: systemPrompt }, ...convertedMessages],
|
||||||
stream: true,
|
stream: true,
|
||||||
stream_options: { include_usage: true },
|
stream_options: { include_usage: true },
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue