mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Merge pull request #555 from dairui1/feat/openrouter_base_url
feat: Add openRouterBaseUrl option
This commit is contained in:
@@ -27,7 +27,7 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
|
|||||||
constructor(options: ApiHandlerOptions) {
|
constructor(options: ApiHandlerOptions) {
|
||||||
this.options = options
|
this.options = options
|
||||||
this.client = new OpenAI({
|
this.client = new OpenAI({
|
||||||
baseURL: "https://openrouter.ai/api/v1",
|
baseURL: this.options.openRouterBaseUrl || "https://openrouter.ai/api/v1",
|
||||||
apiKey: this.options.openRouterApiKey,
|
apiKey: this.options.openRouterApiKey,
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
|
"HTTP-Referer": "https://github.com/RooVetGit/Roo-Cline",
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ type GlobalStateKey =
|
|||||||
| "openAiStreamingEnabled"
|
| "openAiStreamingEnabled"
|
||||||
| "openRouterModelId"
|
| "openRouterModelId"
|
||||||
| "openRouterModelInfo"
|
| "openRouterModelInfo"
|
||||||
|
| "openRouterBaseUrl"
|
||||||
| "openRouterUseMiddleOutTransform"
|
| "openRouterUseMiddleOutTransform"
|
||||||
| "allowedCommands"
|
| "allowedCommands"
|
||||||
| "soundEnabled"
|
| "soundEnabled"
|
||||||
@@ -1293,6 +1294,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
azureApiVersion,
|
azureApiVersion,
|
||||||
openAiStreamingEnabled,
|
openAiStreamingEnabled,
|
||||||
openRouterModelId,
|
openRouterModelId,
|
||||||
|
openRouterBaseUrl,
|
||||||
openRouterModelInfo,
|
openRouterModelInfo,
|
||||||
openRouterUseMiddleOutTransform,
|
openRouterUseMiddleOutTransform,
|
||||||
vsCodeLmModelSelector,
|
vsCodeLmModelSelector,
|
||||||
@@ -1331,6 +1333,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
await this.updateGlobalState("openAiStreamingEnabled", openAiStreamingEnabled)
|
await this.updateGlobalState("openAiStreamingEnabled", openAiStreamingEnabled)
|
||||||
await this.updateGlobalState("openRouterModelId", openRouterModelId)
|
await this.updateGlobalState("openRouterModelId", openRouterModelId)
|
||||||
await this.updateGlobalState("openRouterModelInfo", openRouterModelInfo)
|
await this.updateGlobalState("openRouterModelInfo", openRouterModelInfo)
|
||||||
|
await this.updateGlobalState("openRouterBaseUrl", openRouterBaseUrl)
|
||||||
await this.updateGlobalState("openRouterUseMiddleOutTransform", openRouterUseMiddleOutTransform)
|
await this.updateGlobalState("openRouterUseMiddleOutTransform", openRouterUseMiddleOutTransform)
|
||||||
await this.updateGlobalState("vsCodeLmModelSelector", vsCodeLmModelSelector)
|
await this.updateGlobalState("vsCodeLmModelSelector", vsCodeLmModelSelector)
|
||||||
await this.storeSecret("mistralApiKey", mistralApiKey)
|
await this.storeSecret("mistralApiKey", mistralApiKey)
|
||||||
@@ -1954,6 +1957,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
openAiStreamingEnabled,
|
openAiStreamingEnabled,
|
||||||
openRouterModelId,
|
openRouterModelId,
|
||||||
openRouterModelInfo,
|
openRouterModelInfo,
|
||||||
|
openRouterBaseUrl,
|
||||||
openRouterUseMiddleOutTransform,
|
openRouterUseMiddleOutTransform,
|
||||||
lastShownAnnouncementId,
|
lastShownAnnouncementId,
|
||||||
customInstructions,
|
customInstructions,
|
||||||
@@ -2022,6 +2026,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
this.getGlobalState("openAiStreamingEnabled") as Promise<boolean | undefined>,
|
this.getGlobalState("openAiStreamingEnabled") as Promise<boolean | undefined>,
|
||||||
this.getGlobalState("openRouterModelId") as Promise<string | undefined>,
|
this.getGlobalState("openRouterModelId") as Promise<string | undefined>,
|
||||||
this.getGlobalState("openRouterModelInfo") as Promise<ModelInfo | undefined>,
|
this.getGlobalState("openRouterModelInfo") as Promise<ModelInfo | undefined>,
|
||||||
|
this.getGlobalState("openRouterBaseUrl") as Promise<string | undefined>,
|
||||||
this.getGlobalState("openRouterUseMiddleOutTransform") as Promise<boolean | undefined>,
|
this.getGlobalState("openRouterUseMiddleOutTransform") as Promise<boolean | undefined>,
|
||||||
this.getGlobalState("lastShownAnnouncementId") as Promise<string | undefined>,
|
this.getGlobalState("lastShownAnnouncementId") as Promise<string | undefined>,
|
||||||
this.getGlobalState("customInstructions") as Promise<string | undefined>,
|
this.getGlobalState("customInstructions") as Promise<string | undefined>,
|
||||||
@@ -2107,6 +2112,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
openAiStreamingEnabled,
|
openAiStreamingEnabled,
|
||||||
openRouterModelId,
|
openRouterModelId,
|
||||||
openRouterModelInfo,
|
openRouterModelInfo,
|
||||||
|
openRouterBaseUrl,
|
||||||
openRouterUseMiddleOutTransform,
|
openRouterUseMiddleOutTransform,
|
||||||
vsCodeLmModelSelector,
|
vsCodeLmModelSelector,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export interface ApiHandlerOptions {
|
|||||||
openRouterApiKey?: string
|
openRouterApiKey?: string
|
||||||
openRouterModelId?: string
|
openRouterModelId?: string
|
||||||
openRouterModelInfo?: ModelInfo
|
openRouterModelInfo?: ModelInfo
|
||||||
|
openRouterBaseUrl?: string
|
||||||
awsAccessKey?: string
|
awsAccessKey?: string
|
||||||
awsSecretKey?: string
|
awsSecretKey?: string
|
||||||
awsSessionToken?: string
|
awsSessionToken?: string
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
const [vsCodeLmModels, setVsCodeLmModels] = useState<vscodemodels.LanguageModelChatSelector[]>([])
|
const [vsCodeLmModels, setVsCodeLmModels] = useState<vscodemodels.LanguageModelChatSelector[]>([])
|
||||||
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
|
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
|
||||||
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
|
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
|
||||||
|
const [openRouterBaseUrlSelected, setOpenRouterBaseUrlSelected] = useState(!!apiConfiguration?.openRouterBaseUrl)
|
||||||
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
|
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
|
||||||
|
|
||||||
const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => {
|
const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => {
|
||||||
@@ -303,12 +304,38 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
|
|||||||
<span style={{ fontWeight: 500 }}>OpenRouter API Key</span>
|
<span style={{ fontWeight: 500 }}>OpenRouter API Key</span>
|
||||||
</VSCodeTextField>
|
</VSCodeTextField>
|
||||||
{!apiConfiguration?.openRouterApiKey && (
|
{!apiConfiguration?.openRouterApiKey && (
|
||||||
|
<p>
|
||||||
<VSCodeButtonLink
|
<VSCodeButtonLink
|
||||||
href={getOpenRouterAuthUrl(uriScheme)}
|
href={getOpenRouterAuthUrl(uriScheme)}
|
||||||
style={{ margin: "5px 0 0 0" }}
|
style={{ margin: "5px 0 0 0" }}
|
||||||
appearance="secondary">
|
appearance="secondary">
|
||||||
Get OpenRouter API Key
|
Get OpenRouter API Key
|
||||||
</VSCodeButtonLink>
|
</VSCodeButtonLink>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<Checkbox
|
||||||
|
checked={openRouterBaseUrlSelected}
|
||||||
|
onChange={(checked: boolean) => {
|
||||||
|
setOpenRouterBaseUrlSelected(checked)
|
||||||
|
if (!checked) {
|
||||||
|
handleInputChange("openRouterBaseUrl")({
|
||||||
|
target: {
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
Use custom base URL
|
||||||
|
</Checkbox>
|
||||||
|
|
||||||
|
{openRouterBaseUrlSelected && (
|
||||||
|
<VSCodeTextField
|
||||||
|
value={apiConfiguration?.openRouterBaseUrl || ""}
|
||||||
|
style={{ width: "100%", marginTop: 3 }}
|
||||||
|
type="url"
|
||||||
|
onInput={handleInputChange("openRouterBaseUrl")}
|
||||||
|
placeholder="Default: https://openrouter.ai/api/v1"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
<p
|
<p
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
Reference in New Issue
Block a user