Compare commits

..

1 Commits

Author SHA1 Message Date
ItzCrazyKns
ae132ebee8 feat(app): lint & beautify 2025-12-25 18:58:33 +05:30
6 changed files with 131 additions and 127 deletions

View File

@@ -1,5 +1,5 @@
import OpenAILLM from "../openai/openaiLLM"; import OpenAILLM from '../openai/openaiLLM';
class AnthropicLLM extends OpenAILLM {} class AnthropicLLM extends OpenAILLM {}
export default AnthropicLLM; export default AnthropicLLM;

View File

@@ -81,7 +81,7 @@ class AnthropicProvider extends BaseModelProvider<AnthropicConfig> {
return new AnthropicLLM({ return new AnthropicLLM({
apiKey: this.config.apiKey, apiKey: this.config.apiKey,
model: key, model: key,
baseURL: 'https://api.anthropic.com/v1' baseURL: 'https://api.anthropic.com/v1',
}); });
} }
@@ -112,4 +112,4 @@ class AnthropicProvider extends BaseModelProvider<AnthropicConfig> {
} }
} }
export default AnthropicProvider; export default AnthropicProvider;

View File

@@ -15,7 +15,7 @@ export const providers: Record<string, ProviderConstructor<any>> = {
transformers: TransformersProvider, transformers: TransformersProvider,
groq: GroqProvider, groq: GroqProvider,
lemonade: LemonadeProvider, lemonade: LemonadeProvider,
anthropic: AnthropicProvider anthropic: AnthropicProvider,
}; };
export const getModelProvidersUIConfigSection = export const getModelProvidersUIConfigSection =

View File

@@ -8,142 +8,146 @@ import BaseEmbedding from '../../base/embedding';
import LemonadeEmbedding from './lemonadeEmbedding'; import LemonadeEmbedding from './lemonadeEmbedding';
interface LemonadeConfig { interface LemonadeConfig {
baseURL: string; baseURL: string;
apiKey?: string; apiKey?: string;
} }
const providerConfigFields: UIConfigField[] = [ const providerConfigFields: UIConfigField[] = [
{ {
type: 'string', type: 'string',
name: 'Base URL', name: 'Base URL',
key: 'baseURL', key: 'baseURL',
description: 'The base URL for Lemonade API', description: 'The base URL for Lemonade API',
required: true, required: true,
placeholder: 'https://api.lemonade.ai/v1', placeholder: 'https://api.lemonade.ai/v1',
env: 'LEMONADE_BASE_URL', env: 'LEMONADE_BASE_URL',
scope: 'server', scope: 'server',
}, },
{ {
type: 'password', type: 'password',
name: 'API Key', name: 'API Key',
key: 'apiKey', key: 'apiKey',
description: 'Your Lemonade API key (optional)', description: 'Your Lemonade API key (optional)',
required: false, required: false,
placeholder: 'Lemonade API Key', placeholder: 'Lemonade API Key',
env: 'LEMONADE_API_KEY', env: 'LEMONADE_API_KEY',
scope: 'server', scope: 'server',
}, },
]; ];
class LemonadeProvider extends BaseModelProvider<LemonadeConfig> { class LemonadeProvider extends BaseModelProvider<LemonadeConfig> {
constructor(id: string, name: string, config: LemonadeConfig) { constructor(id: string, name: string, config: LemonadeConfig) {
super(id, name, config); super(id, name, config);
} }
async getDefaultModels(): Promise<ModelList> { async getDefaultModels(): Promise<ModelList> {
try { try {
const res = await fetch(`${this.config.baseURL}/models`, { const res = await fetch(`${this.config.baseURL}/models`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...this.config.apiKey ? {'Authorization': `Bearer ${this.config.apiKey}`} : {} ...(this.config.apiKey
}, ? { Authorization: `Bearer ${this.config.apiKey}` }
}); : {}),
},
});
const data = await res.json(); const data = await res.json();
const models: Model[] = data.data.filter((m: any) => m.recipe === 'llamacpp').map((m: any) => { const models: Model[] = data.data
return { .filter((m: any) => m.recipe === 'llamacpp')
name: m.id, .map((m: any) => {
key: m.id, return {
}; name: m.id,
}); key: m.id,
};
return {
embedding: models,
chat: models,
};
} catch (err) {
if (err instanceof TypeError) {
throw new Error(
'Error connecting to Lemonade API. Please ensure the base URL is correct and the service is available.',
);
}
throw err;
}
}
async getModelList(): Promise<ModelList> {
const defaultModels = await this.getDefaultModels();
const configProvider = getConfiguredModelProviderById(this.id)!;
return {
embedding: [
...defaultModels.embedding,
...configProvider.embeddingModels,
],
chat: [...defaultModels.chat, ...configProvider.chatModels],
};
}
async loadChatModel(key: string): Promise<BaseLLM<any>> {
const modelList = await this.getModelList();
const exists = modelList.chat.find((m) => m.key === key);
if (!exists) {
throw new Error(
'Error Loading Lemonade Chat Model. Invalid Model Selected',
);
}
return new LemonadeLLM({
apiKey: this.config.apiKey || 'not-needed',
model: key,
baseURL: this.config.baseURL,
}); });
return {
embedding: models,
chat: models,
};
} catch (err) {
if (err instanceof TypeError) {
throw new Error(
'Error connecting to Lemonade API. Please ensure the base URL is correct and the service is available.',
);
}
throw err;
}
}
async getModelList(): Promise<ModelList> {
const defaultModels = await this.getDefaultModels();
const configProvider = getConfiguredModelProviderById(this.id)!;
return {
embedding: [
...defaultModels.embedding,
...configProvider.embeddingModels,
],
chat: [...defaultModels.chat, ...configProvider.chatModels],
};
}
async loadChatModel(key: string): Promise<BaseLLM<any>> {
const modelList = await this.getModelList();
const exists = modelList.chat.find((m) => m.key === key);
if (!exists) {
throw new Error(
'Error Loading Lemonade Chat Model. Invalid Model Selected',
);
} }
async loadEmbeddingModel(key: string): Promise<BaseEmbedding<any>> { return new LemonadeLLM({
const modelList = await this.getModelList(); apiKey: this.config.apiKey || 'not-needed',
const exists = modelList.embedding.find((m) => m.key === key); model: key,
baseURL: this.config.baseURL,
});
}
if (!exists) { async loadEmbeddingModel(key: string): Promise<BaseEmbedding<any>> {
throw new Error( const modelList = await this.getModelList();
'Error Loading Lemonade Embedding Model. Invalid Model Selected.', const exists = modelList.embedding.find((m) => m.key === key);
);
}
return new LemonadeEmbedding({ if (!exists) {
apiKey: this.config.apiKey || 'not-needed', throw new Error(
model: key, 'Error Loading Lemonade Embedding Model. Invalid Model Selected.',
baseURL: this.config.baseURL, );
});
} }
static parseAndValidate(raw: any): LemonadeConfig { return new LemonadeEmbedding({
if (!raw || typeof raw !== 'object') apiKey: this.config.apiKey || 'not-needed',
throw new Error('Invalid config provided. Expected object'); model: key,
if (!raw.baseURL) baseURL: this.config.baseURL,
throw new Error('Invalid config provided. Base URL must be provided'); });
}
return { static parseAndValidate(raw: any): LemonadeConfig {
baseURL: String(raw.baseURL), if (!raw || typeof raw !== 'object')
apiKey: raw.apiKey ? String(raw.apiKey) : undefined, throw new Error('Invalid config provided. Expected object');
}; if (!raw.baseURL)
} throw new Error('Invalid config provided. Base URL must be provided');
static getProviderConfigFields(): UIConfigField[] { return {
return providerConfigFields; baseURL: String(raw.baseURL),
} apiKey: raw.apiKey ? String(raw.apiKey) : undefined,
};
}
static getProviderMetadata(): ProviderMetadata { static getProviderConfigFields(): UIConfigField[] {
return { return providerConfigFields;
key: 'lemonade', }
name: 'Lemonade',
}; static getProviderMetadata(): ProviderMetadata {
} return {
key: 'lemonade',
name: 'Lemonade',
};
}
} }
export default LemonadeProvider; export default LemonadeProvider;

View File

@@ -1,5 +1,5 @@
import OpenAIEmbedding from "../openai/openaiEmbedding"; import OpenAIEmbedding from '../openai/openaiEmbedding';
class LemonadeEmbedding extends OpenAIEmbedding {} class LemonadeEmbedding extends OpenAIEmbedding {}
export default LemonadeEmbedding; export default LemonadeEmbedding;

View File

@@ -1,5 +1,5 @@
import OpenAILLM from "../openai/openaiLLM"; import OpenAILLM from '../openai/openaiLLM';
class LemonadeLLM extends OpenAILLM {} class LemonadeLLM extends OpenAILLM {}
export default LemonadeLLM; export default LemonadeLLM;