mirror of
https://github.com/voideditor/void
synced 2026-05-24 01:48:25 +00:00
add OpenRouter - Fixes Add OpenRouter hosting option #20
This commit is contained in:
parent
bb74cbb56b
commit
07fd622901
3 changed files with 35 additions and 4 deletions
|
|
@ -22,6 +22,7 @@
|
|||
"description": "Choose an API provider.",
|
||||
"enum": [
|
||||
"openAI",
|
||||
"openRouter",
|
||||
"openAICompatible",
|
||||
"anthropic",
|
||||
"azure",
|
||||
|
|
@ -236,6 +237,16 @@
|
|||
"smollm:1.7b"
|
||||
]
|
||||
},
|
||||
"void.openRouter.model": {
|
||||
"type": "string",
|
||||
"default": "openai/gpt-4o",
|
||||
"description": "OpenRouter model to use."
|
||||
},
|
||||
"void.openRouter.apiKey": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "OpenRouter API key."
|
||||
},
|
||||
"void.openAICompatible.endpoint": {
|
||||
"type": "string",
|
||||
"default": "http://127.0.0.1:11434/v1",
|
||||
|
|
@ -279,7 +290,8 @@
|
|||
"command": "void.toggleThreadSelector",
|
||||
"title": "View past chats",
|
||||
"icon": "$(history)"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"command": "void.openSettings",
|
||||
"title": "Void settings",
|
||||
"icon": "$(settings-gear)"
|
||||
|
|
@ -377,4 +389,4 @@
|
|||
"openai": "^4.57.0",
|
||||
"diff": "^7.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,10 @@ export type ApiConfig = {
|
|||
endpoint: string,
|
||||
model: string,
|
||||
apikey: string
|
||||
},
|
||||
openRouter: {
|
||||
model: string,
|
||||
apikey: string
|
||||
}
|
||||
whichApi: string
|
||||
}
|
||||
|
|
@ -108,7 +112,7 @@ const sendClaudeMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinal
|
|||
|
||||
|
||||
|
||||
// OpenAI and OpenAICompatible
|
||||
// OpenAI, OpenRouter, OpenAICompatible
|
||||
const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, apiConfig }) => {
|
||||
|
||||
let didAbort = false
|
||||
|
|
@ -126,6 +130,16 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinal
|
|||
openai = new OpenAI({ apiKey: apiConfig.openAI.apikey, dangerouslyAllowBrowser: true });
|
||||
options = { model: apiConfig.openAI.model, messages: messages, stream: true, }
|
||||
}
|
||||
else if (apiConfig.whichApi === 'openRouter') {
|
||||
openai = new OpenAI({
|
||||
baseURL: "https://openrouter.ai/api/v1", apiKey: apiConfig.openRouter.apikey, dangerouslyAllowBrowser: true,
|
||||
defaultHeaders: {
|
||||
"HTTP-Referer": 'https://voideditor.com', // Optional, for including your app on openrouter.ai rankings.
|
||||
"X-Title": 'Void Editor', // Optional. Shows in rankings on openrouter.ai.
|
||||
},
|
||||
});
|
||||
options = { model: apiConfig.openRouter.model, messages: messages, stream: true, }
|
||||
}
|
||||
else if (apiConfig.whichApi === 'openAICompatible') {
|
||||
openai = new OpenAI({ baseURL: apiConfig.openAICompatible.endpoint, apiKey: apiConfig.openAICompatible.apikey, dangerouslyAllowBrowser: true })
|
||||
options = { model: apiConfig.openAICompatible.model, messages: messages, stream: true, }
|
||||
|
|
@ -286,6 +300,7 @@ export const sendLLMMessage: SendLLMMessageFnTypeExternal = ({ messages, onText,
|
|||
case 'anthropic':
|
||||
return sendClaudeMsg({ messages, onText, onFinalMessage, apiConfig });
|
||||
case 'openAI':
|
||||
case 'openRouter':
|
||||
case 'openAICompatible':
|
||||
return sendOpenAIMsg({ messages, onText, onFinalMessage, apiConfig });
|
||||
case 'greptile':
|
||||
|
|
|
|||
|
|
@ -36,8 +36,12 @@ const getApiConfig = () => {
|
|||
},
|
||||
openAICompatible: {
|
||||
endpoint: vscode.workspace.getConfiguration('void.openAICompatible').get('endpoint') ?? '',
|
||||
apikey: vscode.workspace.getConfiguration('void.openAICompatible').get('apiKey') ?? '',
|
||||
model: vscode.workspace.getConfiguration('void.openAICompatible').get('model') ?? '',
|
||||
apikey: vscode.workspace.getConfiguration('void.openAICompatible').get('apiKey') ?? '',
|
||||
},
|
||||
openRouter: {
|
||||
model: vscode.workspace.getConfiguration('void.openRouter').get('model') ?? '',
|
||||
apikey: vscode.workspace.getConfiguration('void.openRouter').get('apiKey') ?? '',
|
||||
},
|
||||
whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? ''
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue