mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-03-09 21:50:36 +00:00
Added dynamic openrouter model list
This commit is contained in:
parent
c575ee316b
commit
feb19509f6
@ -60,7 +60,9 @@ const PROVIDER_LIST: ProviderInfo[] = [
|
|||||||
{ name: 'qwen/qwen-110b-chat', label: 'OpenRouter Qwen 110b Chat (OpenRouter)', provider: 'OpenRouter' },
|
{ name: 'qwen/qwen-110b-chat', label: 'OpenRouter Qwen 110b Chat (OpenRouter)', provider: 'OpenRouter' },
|
||||||
{ name: 'cohere/command', label: 'Cohere Command (OpenRouter)', provider: 'OpenRouter' }
|
{ name: 'cohere/command', label: 'Cohere Command (OpenRouter)', provider: 'OpenRouter' }
|
||||||
],
|
],
|
||||||
getApiKeyLink: 'https://openrouter.ai/settings/keys'
|
getDynamicModels: getOpenRouterModels,
|
||||||
|
getApiKeyLink: 'https://openrouter.ai/settings/keys',
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
name: 'Google',
|
name: 'Google',
|
||||||
staticModels: [
|
staticModels: [
|
||||||
@ -183,7 +185,34 @@ async function getOpenAILikeModels(): Promise<ModelInfo[]> {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type OpenRouterModelsResponse = {
|
||||||
|
data: {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
context_length: number;
|
||||||
|
pricing: {
|
||||||
|
prompt: number;
|
||||||
|
completion: number;
|
||||||
|
}
|
||||||
|
}[]
|
||||||
|
};
|
||||||
|
|
||||||
|
async function getOpenRouterModels(): Promise<ModelInfo[]> {
|
||||||
|
const data: OpenRouterModelsResponse = await (await fetch('https://openrouter.ai/api/v1/models', {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})).json();
|
||||||
|
|
||||||
|
return data.data.sort((a, b) => a.name.localeCompare(b.name)).map(m => ({
|
||||||
|
name: m.id,
|
||||||
|
label: `${m.name} - in:$${(m.pricing.prompt * 1_000_000).toFixed(
|
||||||
|
2)} out:$${(m.pricing.completion * 1_000_000).toFixed(2)} - context ${Math.floor(
|
||||||
|
m.context_length / 1000)}k`,
|
||||||
|
provider: 'OpenRouter'
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLMStudioModels(): Promise<ModelInfo[]> {
|
async function getLMStudioModels(): Promise<ModelInfo[]> {
|
||||||
@ -202,10 +231,11 @@ async function getLMStudioModels(): Promise<ModelInfo[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function initializeModelList(): Promise<void> {
|
|
||||||
|
async function initializeModelList(): Promise<ModelInfo[]> {
|
||||||
MODEL_LIST = [...(await Promise.all(
|
MODEL_LIST = [...(await Promise.all(
|
||||||
PROVIDER_LIST.filter(p => !!p.getDynamicModels).map(p => p.getDynamicModels()))).flat(), ...staticModels];
|
PROVIDER_LIST.filter(p => !!p.getDynamicModels).map(p => p.getDynamicModels()))).flat(), ...staticModels];
|
||||||
|
return MODEL_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeModelList().then();
|
export { getOllamaModels, getOpenAILikeModels, getLMStudioModels, initializeModelList, getOpenRouterModels, PROVIDER_LIST };
|
||||||
export { getOllamaModels, getOpenAILikeModels, getLMStudioModels, initializeModelList, PROVIDER_LIST };
|
|
||||||
|
Loading…
Reference in New Issue
Block a user