-
Notifications
You must be signed in to change notification settings - Fork 161
feat: Add Anthropic Custom provider with configurable model parameters #754
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: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||
| type AnthropicModelId, | ||||||||||||||||||||||||||||||||||||||||||||||||
| anthropicDefaultModelId, | ||||||||||||||||||||||||||||||||||||||||||||||||
| anthropicModels, | ||||||||||||||||||||||||||||||||||||||||||||||||
| openAiModelInfoSaneDefaults, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ANTHROPIC_DEFAULT_MAX_TOKENS, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ApiProviderError, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } from "@roo-code/types" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -38,12 +39,17 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa | |||||||||||||||||||||||||||||||||||||||||||||||
| super() | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.options = options | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| const baseURL = this.options.anthropicCustomBaseUrl || this.options.anthropicBaseUrl || undefined | ||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKey = this.options.anthropicCustomApiKey || this.options.apiKey | ||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKeyFieldName = | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.options.anthropicBaseUrl && this.options.anthropicUseAuthToken ? "authToken" : "apiKey" | ||||||||||||||||||||||||||||||||||||||||||||||||
| baseURL && this.options.anthropicUseAuthToken && !this.options.anthropicCustomApiKey | ||||||||||||||||||||||||||||||||||||||||||||||||
| ? "authToken" | ||||||||||||||||||||||||||||||||||||||||||||||||
| : "apiKey" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| this.client = new Anthropic({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| baseURL: this.options.anthropicBaseUrl || undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||
| [apiKeyFieldName]: this.options.apiKey, | ||||||||||||||||||||||||||||||||||||||||||||||||
| baseURL, | ||||||||||||||||||||||||||||||||||||||||||||||||
| [apiKeyFieldName]: apiKey, | ||||||||||||||||||||||||||||||||||||||||||||||||
| defaultHeaders: this.options.anthropicCustomHeaders, | ||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: this.timeoutMs, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -352,9 +358,14 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa | |||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| getModel() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const modelId = this.options.apiModelId | ||||||||||||||||||||||||||||||||||||||||||||||||
| const id = modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId | ||||||||||||||||||||||||||||||||||||||||||||||||
| let info: ModelInfo = anthropicModels[id] | ||||||||||||||||||||||||||||||||||||||||||||||||
| const customModelId = this.options.anthropicCustomModelId | ||||||||||||||||||||||||||||||||||||||||||||||||
| const modelId = customModelId || this.options.apiModelId | ||||||||||||||||||||||||||||||||||||||||||||||||
| const id = | ||||||||||||||||||||||||||||||||||||||||||||||||
| customModelId || | ||||||||||||||||||||||||||||||||||||||||||||||||
| (modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let info: ModelInfo = customModelId | ||||||||||||||||||||||||||||||||||||||||||||||||
| ? this.options.anthropicCustomModelInfo || openAiModelInfoSaneDefaults | ||||||||||||||||||||||||||||||||||||||||||||||||
| : anthropicModels[id as AnthropicModelId] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+361
to
+368
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Fallback to built-in Anthropic metadata for known custom model IDs.
Suggested patch const customModelId = this.options.anthropicCustomModelId
const modelId = customModelId || this.options.apiModelId
const id =
customModelId ||
(modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId)
- let info: ModelInfo = customModelId
- ? this.options.anthropicCustomModelInfo || openAiModelInfoSaneDefaults
- : anthropicModels[id as AnthropicModelId]
+ const builtInCustomInfo =
+ customModelId && customModelId in anthropicModels
+ ? anthropicModels[customModelId as AnthropicModelId]
+ : undefined
+ let info: ModelInfo = customModelId
+ ? {
+ ...(builtInCustomInfo ?? openAiModelInfoSaneDefaults),
+ ...(this.options.anthropicCustomModelInfo ?? {}),
+ }
+ : anthropicModels[id as AnthropicModelId]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // If 1M context beta is enabled for supported models, update the model info | ||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Keep
anthropic-customisolated from the standard Anthropic connection fields.This fallback chain mixes the two provider namespaces. If a profile still has
anthropicBaseUrlpopulated from the standard Anthropic setup, selectinganthropic-customwith its custom base URL disabled will still route prompts to that old proxy instead of Anthropic’s default endpoint. The same bleed-through can happen with credentials becausebuildApiHandler()no longer passesapiProviderinto the handler, so this constructor has no way to tell which namespace should win. Please derive endpoint/auth strictly from the active provider instead of falling back acrossanthropic*andanthropicCustom*.🤖 Prompt for AI Agents