Skip to content

Commit e1e4298

Browse files
authored
Merge pull request #618 from sugarforever/fix/issue-612-custom-service-not-saved
fix: the custom service is not saved
2 parents 48a6dd4 + 1fbd722 commit e1e4298

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

components/settings/CustomServerForm.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,24 @@ const defaultModelsMap: Record<ContextKeys['custom'][number]['aiType'], string[]
2727
const defaultState: ContextKeys['custom'][number] = { name: '', aiType: 'openai', endpoint: '', key: '', proxy: false, models: [] }
2828
const defaultAiType = props.value.aiType || aiTypes[0].value
2929
const state = reactive(Object.assign({}, defaultState, props.value, {
30-
aiType: defaultAiType,
31-
models: props.value.models.length === 0 ? defaultModelsMap[defaultAiType] : props.value.models,
30+
aiType: defaultAiType
3231
}))
3332
const modelName = ref('')
3433
const schema = computed(() => {
3534
return object({
35+
name: string().required(t('global.required')),
3636
aiType: string().required(t('global.required')),
3737
endpoint: string().url(t('global.invalidUrl')).required(t('global.required')),
3838
key: string().required(t('global.required')),
39-
models: array().min(1, t('global.required')),
4039
modelsEndpoint: string(),
40+
proxy: string().optional(),
4141
})
4242
})
4343
4444
watch(() => state.aiType, (type) => {
45-
state.models = defaultModelsMap[type] || []
45+
if (type !== 'openai') {
46+
state.models = defaultModelsMap[type] || []
47+
}
4648
})
4749
4850
function onSubmit() {

server/api/models/index.get.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,32 @@ export default defineEventHandler(async (event) => {
125125
if (MODEL_FAMILIES.hasOwnProperty(item.aiType) && item.name && item.endpoint && item.key) {
126126
try {
127127
// Only attempt API call if modelsEndpoint is provided
128-
if (item.modelsEndpoint) {
129-
const endpointWithSlash = item.endpoint.endsWith('/') ? item.endpoint : item.endpoint + '/'
130-
const modelsEndpoint = item.modelsEndpoint.startsWith('/') ? item.modelsEndpoint.substring(1) : item.modelsEndpoint
131-
const modelsUrl = new URL(modelsEndpoint, endpointWithSlash).toString()
132-
console.log(`Fetching models from ${modelsUrl}`)
133-
const response = await fetch(modelsUrl, {
134-
headers: {
135-
'Authorization': `Bearer ${item.key}`,
136-
}
137-
})
128+
const modelsEndpoint = item.modelsEndpoint || "/models"
129+
const endpointWithSlash = item.endpoint.endsWith('/') ? item.endpoint : item.endpoint + '/'
130+
131+
const normalizedModelsEndpoint = modelsEndpoint.startsWith('/') ? modelsEndpoint.substring(1) : modelsEndpoint
132+
const modelsUrl = new URL(normalizedModelsEndpoint, endpointWithSlash).toString()
133+
console.log(`Fetching models from ${modelsUrl}`)
134+
const response = await fetch(modelsUrl, {
135+
headers: {
136+
'Authorization': `Bearer ${item.key}`,
137+
}
138+
})
138139

139-
if (response.ok) {
140-
const data: ModelApiResponse = await response.json()
141-
console.log(`${item.name} models:`, data.data.map(d => d.id || d.name))
142-
data.data.forEach(model => {
143-
models.push({
144-
name: model.id || model.name,
145-
details: {
146-
family: item.name
147-
}
148-
})
140+
if (response.ok) {
141+
const data: ModelApiResponse = await response.json()
142+
console.log(`${item.name} models:`, data.data.map(d => d.id || d.name))
143+
data.data.forEach(model => {
144+
models.push({
145+
name: model.id || model.name,
146+
details: {
147+
family: item.name
148+
}
149149
})
150-
return // Skip the fallback if API call succeeds
151-
} else {
152-
console.error(`Failed to fetch models for custom endpoint ${item.name}:`, response)
153-
}
150+
})
151+
return // Skip the fallback if API call succeeds
152+
} else {
153+
console.error(`Failed to fetch models for custom endpoint ${item.name}:`, response)
154154
}
155155
} catch (error) {
156156
console.error(`Failed to fetch models for custom endpoint ${item.name}:`, error)

0 commit comments

Comments
 (0)