mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
tui: fix model validation to prevent invalid provider/model combinations
This commit is contained in:
parent
f85574f534
commit
82a50e72d8
1 changed files with 16 additions and 2 deletions
|
|
@ -92,17 +92,31 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
|||
})
|
||||
|
||||
const fallback = createMemo(() => {
|
||||
function isValid(providerID: string, modelID: string) {
|
||||
const provider = sync.data.provider.find((x) => x.id === providerID)
|
||||
if (!provider) return false
|
||||
const model = provider.models[modelID]
|
||||
if (!model) return false
|
||||
return true
|
||||
}
|
||||
|
||||
if (sync.data.config.model) {
|
||||
const [providerID, modelID] = sync.data.config.model.split("/")
|
||||
if (sync.data.provider.find((x) => x.id === providerID)?.models[modelID]) {
|
||||
if (isValid(providerID, modelID)) {
|
||||
return {
|
||||
providerID,
|
||||
modelID,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (store.recent.length) return store.recent[0]
|
||||
|
||||
for (const item of store.recent) {
|
||||
if (isValid(item.providerID, item.modelID)) {
|
||||
return item
|
||||
}
|
||||
}
|
||||
const provider = sync.data.provider[0]
|
||||
console.log(provider)
|
||||
const model = Object.values(provider.models)[0]
|
||||
return {
|
||||
providerID: provider.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue