@@ -125,32 +125,32 @@ export default defineEventHandler(async (event) => {
125
125
if ( MODEL_FAMILIES . hasOwnProperty ( item . aiType ) && item . name && item . endpoint && item . key ) {
126
126
try {
127
127
// 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
+ } )
138
139
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
+ }
149
149
} )
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 )
154
154
}
155
155
} catch ( error ) {
156
156
console . error ( `Failed to fetch models for custom endpoint ${ item . name } :` , error )
0 commit comments