feat: Support LMStudio models

Adds support for LMStudio models, allowing users to access and use them within the application. This involves:

- Adding new functions to `db/models.ts` to handle LMStudio model IDs and fetch their information from the OpenAI API.
- Modifying the `ollamaFormatAllCustomModels` function to include LMStudio models in the list of available models.
- Introducing a timeout mechanism in `libs/openai.ts` to prevent API requests from hanging.

This change enhances the model selection experience, providing users with a wider range of models to choose from.
This commit is contained in:
n4ze3m
2024-10-12 19:05:21 +05:30
parent f1e40d5908
commit ddb8993f17
3 changed files with 89 additions and 8 deletions

View File

@@ -14,10 +14,16 @@ export const getAllOpenAIModels = async (baseUrl: string, apiKey?: string) => {
}
: {}
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 10000)
const res = await fetch(url, {
headers
headers,
signal: controller.signal
})
clearTimeout(timeoutId)
if (!res.ok) {
return []
}
@@ -27,14 +33,18 @@ export const getAllOpenAIModels = async (baseUrl: string, apiKey?: string) => {
return data.map(model => ({
id: model.id,
name: model.display_name,
}))
})) as Model[]
}
const data = (await res.json()) as { data: Model[] }
return data.data
} catch (e) {
console.log(e)
if (e instanceof DOMException && e.name === 'AbortError') {
console.log('Request timed out')
} else {
console.log(e)
}
return []
}
}