-
-
Notifications
You must be signed in to change notification settings - Fork 303
feature about chat completions reasoning, support gemini-3-pro works ok and support claude model enable thinking #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
29668ce
a2467d3
58f7a45
3fa5519
dfb40d2
7657d87
7f8187b
cbe12eb
ebcacb2
0d6f7aa
dcafbe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,6 @@ | ||||||||||
| import type { Model } from "~/services/copilot/get-models" | ||||||||||
|
|
||||||||||
| import { state } from "~/lib/state" | ||||||||||
| import { | ||||||||||
| type ChatCompletionResponse, | ||||||||||
| type ChatCompletionsPayload, | ||||||||||
|
|
@@ -29,11 +32,15 @@ import { mapOpenAIStopReasonToAnthropic } from "./utils" | |||||||||
| export function translateToOpenAI( | ||||||||||
| payload: AnthropicMessagesPayload, | ||||||||||
| ): ChatCompletionsPayload { | ||||||||||
| const modelId = translateModelName(payload.model) | ||||||||||
| const model = state.models?.data.find((m) => m.id === modelId) | ||||||||||
| const thinkingBudget = getThinkingBudget(payload, model) | ||||||||||
| return { | ||||||||||
| model: translateModelName(payload.model), | ||||||||||
| model: modelId, | ||||||||||
| messages: translateAnthropicMessagesToOpenAI( | ||||||||||
| payload.messages, | ||||||||||
| payload.system, | ||||||||||
| modelId, | ||||||||||
| ), | ||||||||||
| max_tokens: payload.max_tokens, | ||||||||||
| stop: payload.stop_sequences, | ||||||||||
|
|
@@ -43,14 +50,36 @@ export function translateToOpenAI( | |||||||||
| user: payload.metadata?.user_id, | ||||||||||
| tools: translateAnthropicToolsToOpenAI(payload.tools), | ||||||||||
| tool_choice: translateAnthropicToolChoiceToOpenAI(payload.tool_choice), | ||||||||||
| thinking_budget: thinkingBudget, | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function getThinkingBudget( | ||||||||||
| payload: AnthropicMessagesPayload, | ||||||||||
| model: Model | undefined, | ||||||||||
| ): number | undefined { | ||||||||||
| const thinking = payload.thinking | ||||||||||
| if (model && thinking) { | ||||||||||
| const maxThinkingBudget = Math.min( | ||||||||||
| model.capabilities.supports.max_thinking_budget ?? 0, | ||||||||||
| (model.capabilities.limits.max_output_tokens ?? 0) - 1, | ||||||||||
| ) | ||||||||||
| if (maxThinkingBudget > 0 && thinking.budget_tokens !== undefined) { | ||||||||||
| const budgetTokens = Math.min(thinking.budget_tokens, maxThinkingBudget) | ||||||||||
| return Math.max( | ||||||||||
| budgetTokens, | ||||||||||
| model.capabilities.supports.min_thinking_budget ?? 1024, | ||||||||||
| ) | ||||||||||
| } | ||||||||||
| } | ||||||||||
| return undefined | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function translateModelName(model: string): string { | ||||||||||
| // Subagent requests use a specific model number which Copilot doesn't support | ||||||||||
| if (model.startsWith("claude-sonnet-4-")) { | ||||||||||
| return model.replace(/^claude-sonnet-4-.*/, "claude-sonnet-4") | ||||||||||
| } else if (model.startsWith("claude-opus-")) { | ||||||||||
| } else if (model.startsWith("claude-opus-4-")) { | ||||||||||
| return model.replace(/^claude-opus-4-.*/, "claude-opus-4") | ||||||||||
|
Comment on lines
+82
to
83
|
||||||||||
| } else if (model.startsWith("claude-opus-4-")) { | |
| return model.replace(/^claude-opus-4-.*/, "claude-opus-4") | |
| } else if (model.startsWith("claude-opus-")) { | |
| return model.replace(/^claude-opus-.*/, "claude-opus") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copilotBaseUrlshould not blindly templatestate.accountType(host correctness + potential SSRF surface).If
accountTypeisn’t strictly validated to a small enum, this can generate invalid/unexpected hosts. Consider mapping known values and defaulting/throwing on unknowns.🤖 Prompt for AI Agents