mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
commit
4b492b9d97
@ -43,6 +43,12 @@ OPENAI_LIKE_API_KEY=
|
|||||||
# You only need this environment variable set if you want to use Mistral models
|
# You only need this environment variable set if you want to use Mistral models
|
||||||
MISTRAL_API_KEY=
|
MISTRAL_API_KEY=
|
||||||
|
|
||||||
|
|
||||||
|
# Get LMStudio Base URL from LM Studio Developer Console
|
||||||
|
# Make sure to enable CORS
|
||||||
|
# Example: http://localhost:1234
|
||||||
|
LMSTUDIO_API_BASE_URL=
|
||||||
|
|
||||||
# Get your xAI API key
|
# Get your xAI API key
|
||||||
# https://x.ai/api
|
# https://x.ai/api
|
||||||
# You only need this environment variable set if you want to use xAI models
|
# You only need this environment variable set if you want to use xAI models
|
||||||
|
@ -49,6 +49,9 @@ const ModelSelector = ({ model, setModel, provider, setProvider, modelList, prov
|
|||||||
<option key="OpenAILike" value="OpenAILike">
|
<option key="OpenAILike" value="OpenAILike">
|
||||||
OpenAILike
|
OpenAILike
|
||||||
</option>
|
</option>
|
||||||
|
<option key="LMStudio" value="LMStudio">
|
||||||
|
LMStudio
|
||||||
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<select
|
<select
|
||||||
value={model}
|
value={model}
|
||||||
|
@ -42,6 +42,8 @@ export function getBaseURL(cloudflareEnv: Env, provider: string) {
|
|||||||
switch (provider) {
|
switch (provider) {
|
||||||
case 'OpenAILike':
|
case 'OpenAILike':
|
||||||
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL;
|
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL;
|
||||||
|
case 'LMStudio':
|
||||||
|
return env.LMSTUDIO_API_BASE_URL || cloudflareEnv.LMSTUDIO_API_BASE_URL || "http://localhost:1234";
|
||||||
case 'Ollama':
|
case 'Ollama':
|
||||||
let baseUrl = env.OLLAMA_API_BASE_URL || cloudflareEnv.OLLAMA_API_BASE_URL || "http://localhost:11434";
|
let baseUrl = env.OLLAMA_API_BASE_URL || cloudflareEnv.OLLAMA_API_BASE_URL || "http://localhost:11434";
|
||||||
if (env.RUNNING_IN_DOCKER === 'true') {
|
if (env.RUNNING_IN_DOCKER === 'true') {
|
||||||
|
@ -83,6 +83,15 @@ export function getOpenRouterModel(apiKey: string, model: string) {
|
|||||||
return openRouter.chat(model);
|
return openRouter.chat(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLMStudioModel(baseURL: string, model: string) {
|
||||||
|
const lmstudio = createOpenAI({
|
||||||
|
baseUrl: `${baseURL}/v1`,
|
||||||
|
apiKey: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
return lmstudio(model);
|
||||||
|
}
|
||||||
|
|
||||||
export function getXAIModel(apiKey: string, model: string) {
|
export function getXAIModel(apiKey: string, model: string) {
|
||||||
const openai = createOpenAI({
|
const openai = createOpenAI({
|
||||||
baseURL: 'https://api.x.ai/v1',
|
baseURL: 'https://api.x.ai/v1',
|
||||||
@ -105,13 +114,15 @@ export function getModel(provider: string, model: string, env: Env, apiKeys?: Re
|
|||||||
case 'OpenRouter':
|
case 'OpenRouter':
|
||||||
return getOpenRouterModel(apiKey, model);
|
return getOpenRouterModel(apiKey, model);
|
||||||
case 'Google':
|
case 'Google':
|
||||||
return getGoogleModel(apiKey, model)
|
return getGoogleModel(apiKey, model);
|
||||||
case 'OpenAILike':
|
case 'OpenAILike':
|
||||||
return getOpenAILikeModel(baseURL,apiKey, model);
|
return getOpenAILikeModel(baseURL,apiKey, model);
|
||||||
case 'Deepseek':
|
case 'Deepseek':
|
||||||
return getDeepseekModel(apiKey, model)
|
return getDeepseekModel(apiKey, model);
|
||||||
case 'Mistral':
|
case 'Mistral':
|
||||||
return getMistralModel(apiKey, model);
|
return getMistralModel(apiKey, model);
|
||||||
|
case 'LMStudio':
|
||||||
|
return getLMStudioModel(baseURL, model);
|
||||||
case 'xAI':
|
case 'xAI':
|
||||||
return getXAIModel(apiKey, model);
|
return getXAIModel(apiKey, model);
|
||||||
default:
|
default:
|
||||||
|
@ -107,10 +107,28 @@ async function getOpenAILikeModels(): Promise<ModelInfo[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getLMStudioModels(): Promise<ModelInfo[]> {
|
||||||
|
try {
|
||||||
|
const base_url = import.meta.env.LMSTUDIO_API_BASE_URL || "http://localhost:1234";
|
||||||
|
const response = await fetch(`${base_url}/v1/models`);
|
||||||
|
const data = await response.json() as any;
|
||||||
|
return data.data.map((model: any) => ({
|
||||||
|
name: model.id,
|
||||||
|
label: model.id,
|
||||||
|
provider: 'LMStudio',
|
||||||
|
}));
|
||||||
|
} catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function initializeModelList(): Promise<void> {
|
async function initializeModelList(): Promise<void> {
|
||||||
const ollamaModels = await getOllamaModels();
|
const ollamaModels = await getOllamaModels();
|
||||||
const openAiLikeModels = await getOpenAILikeModels();
|
const openAiLikeModels = await getOpenAILikeModels();
|
||||||
MODEL_LIST = [...ollamaModels, ...openAiLikeModels, ...staticModels];
|
const lmstudioModels = await getLMStudioModels();
|
||||||
|
MODEL_LIST = [...ollamaModels,...openAiLikeModels, ...staticModels,...lmstudioModels,];
|
||||||
}
|
}
|
||||||
initializeModelList().then();
|
initializeModelList().then();
|
||||||
export { getOllamaModels, getOpenAILikeModels, initializeModelList };
|
export { getOllamaModels,getOpenAILikeModels,getLMStudioModels,initializeModelList };
|
@ -27,7 +27,7 @@ export default defineConfig((config) => {
|
|||||||
chrome129IssuePlugin(),
|
chrome129IssuePlugin(),
|
||||||
config.mode === 'production' && optimizeCssModules({ apply: 'build' }),
|
config.mode === 'production' && optimizeCssModules({ apply: 'build' }),
|
||||||
],
|
],
|
||||||
envPrefix:["VITE_","OPENAI_LIKE_API_","OLLAMA_API_BASE_URL"],
|
envPrefix:["VITE_","OPENAI_LIKE_API_","OLLAMA_API_BASE_URL","LMSTUDIO_API_BASE_URL"],
|
||||||
css: {
|
css: {
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
scss: {
|
scss: {
|
||||||
|
1
worker-configuration.d.ts
vendored
1
worker-configuration.d.ts
vendored
@ -7,4 +7,5 @@ interface Env {
|
|||||||
OPENAI_LIKE_API_KEY: string;
|
OPENAI_LIKE_API_KEY: string;
|
||||||
OPENAI_LIKE_API_BASE_URL: string;
|
OPENAI_LIKE_API_BASE_URL: string;
|
||||||
DEEPSEEK_API_KEY: string;
|
DEEPSEEK_API_KEY: string;
|
||||||
|
LMSTUDIO_API_BASE_URL: string;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user