1d40812f2a
Each AI provider now has its own module implementing a ProviderModule interface with createGateway, getAuthHeaders, and fetchModels methods. This replaces the monolithic switch statements in ai-provider.ts and models.post.ts with a clean registry pattern.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { Ok } from '~~/types/result';
|
|
import type { ProviderModule } from '.';
|
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
|
|
export default {
|
|
id: 'vllm',
|
|
baseUrl: '',
|
|
modelsEndpoint: '/models',
|
|
|
|
createGateway({ apiKey, baseURL }) {
|
|
return Ok({
|
|
gateway: createOpenAICompatible({ name: 'vLLM', apiKey, baseURL, includeUsage: true }),
|
|
streamTransformer: undefined,
|
|
textTransformer: undefined,
|
|
});
|
|
},
|
|
|
|
getAuthHeaders(apiKey) {
|
|
return apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
|
|
},
|
|
|
|
async fetchModels({ baseURL, apiKey }) {
|
|
const res = await fetch(`${baseURL}/models`, {
|
|
method: 'GET',
|
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
});
|
|
const data = await res.json();
|
|
|
|
if (!res.ok) {
|
|
throw createError({ statusCode: res.status, message: JSON.stringify(data) });
|
|
}
|
|
|
|
return data.data.map((model: any) => ({
|
|
id: model.id,
|
|
attributes: {
|
|
inputModalities: ['text'],
|
|
outputModalities: ['text'],
|
|
contextWindow: model.max_model_len,
|
|
}
|
|
}));
|
|
},
|
|
} satisfies ProviderModule;
|