mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-19 22:08:15 +00:00
feat(models): add id
& name
fields, move getUIConfigSection
to seperate file
This commit is contained in:
@@ -6,7 +6,6 @@ import { Embeddings } from '@langchain/core/embeddings';
|
||||
import { UIConfigField } from '@/lib/config/types';
|
||||
|
||||
interface OpenAIConfig {
|
||||
name: string;
|
||||
apiKey: string;
|
||||
baseURL: string;
|
||||
}
|
||||
@@ -90,15 +89,6 @@ const defaultEmbeddingModels: Model[] = [
|
||||
];
|
||||
|
||||
const providerConfigFields: UIConfigField[] = [
|
||||
/* {
|
||||
type: 'string',
|
||||
name: 'Name (Optional)',
|
||||
key: 'name',
|
||||
description: 'An optional name for this provider configuration',
|
||||
required: false,
|
||||
placeholder: 'Provider Name',
|
||||
scope: 'server',
|
||||
}, */ /* FOR NAME DIRECTLY CREATE INPUT IN FRONTEND */
|
||||
{
|
||||
type: 'password',
|
||||
name: 'API Key',
|
||||
@@ -123,8 +113,8 @@ const providerConfigFields: UIConfigField[] = [
|
||||
];
|
||||
|
||||
class OpenAIProvider extends BaseModelProvider<OpenAIConfig> {
|
||||
constructor(config: OpenAIConfig) {
|
||||
super(config);
|
||||
constructor(id: string, name: string, config: OpenAIConfig) {
|
||||
super(id, name, config);
|
||||
}
|
||||
|
||||
async getDefaultModels(): Promise<ModelList> {
|
||||
@@ -192,6 +182,20 @@ class OpenAIProvider extends BaseModelProvider<OpenAIConfig> {
|
||||
});
|
||||
}
|
||||
|
||||
static parseAndValidate(raw: any): OpenAIConfig {
|
||||
if (!raw || typeof raw !== 'object')
|
||||
throw new Error('Invalid config provided. Expected object');
|
||||
if (!raw.apiKey || !raw.baseURL)
|
||||
throw new Error(
|
||||
'Invalid config provided. API key and base URL must be provided',
|
||||
);
|
||||
|
||||
return {
|
||||
apiKey: String(raw.apiKey),
|
||||
baseURL: String(raw.baseURL),
|
||||
};
|
||||
}
|
||||
|
||||
static getProviderConfigFields(): UIConfigField[] {
|
||||
return providerConfigFields;
|
||||
}
|
||||
|
Reference in New Issue
Block a user