mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Allow configuring multiple AI providers
This commit is contained in:
8 files changed
+415
-84
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import type { AIConnection } from '@/contexts/AISettingsContext';
|
||||
|
||||
export interface ParsedProviderModel {
|
||||
provider: string;
|
||||
model: string;
|
||||
connection: AIConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a provider/model string and return the provider connection and model name
|
||||
* Format: provider/model (e.g., "openai/gpt-4o", "openrouter/anthropic/claude-sonnet-4")
|
||||
* The first slash separates the provider from the model
|
||||
*/
|
||||
export function parseProviderModel(
|
||||
providerModelString: string,
|
||||
providers: Record<string, AIConnection>
|
||||
): ParsedProviderModel {
|
||||
const firstSlashIndex = providerModelString.indexOf('/');
|
||||
|
||||
if (firstSlashIndex === -1) {
|
||||
throw new Error('Invalid format. Use provider/model (e.g., "openai/gpt-4o")');
|
||||
}
|
||||
|
||||
const provider = providerModelString.substring(0, firstSlashIndex);
|
||||
const model = providerModelString.substring(firstSlashIndex + 1);
|
||||
|
||||
if (!provider || !model) {
|
||||
throw new Error('Invalid format. Both provider and model must be specified');
|
||||
}
|
||||
|
||||
const connection = providers[provider];
|
||||
if (!connection) {
|
||||
throw new Error(`Provider "${provider}" not found. Available providers: ${Object.keys(providers).join(', ')}`);
|
||||
}
|
||||
|
||||
if (!connection.apiKey) {
|
||||
throw new Error(`Provider "${provider}" is not configured with an API key`);
|
||||
}
|
||||
|
||||
return {
|
||||
provider,
|
||||
model,
|
||||
connection,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user