mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Clean up AI Settings Dialog
This commit is contained in:
1 parent
4aff40688e
commit
7df79ae65a
1 file changed
+90
-75
@@ -15,46 +15,46 @@ interface PresetProvider {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
baseURL: string;
|
baseURL: string;
|
||||||
description: string;
|
apiKeysURL: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PRESET_PROVIDERS: PresetProvider[] = [
|
const PRESET_PROVIDERS: PresetProvider[] = [
|
||||||
{
|
{
|
||||||
id: 'openai',
|
id: "openrouter",
|
||||||
name: 'OpenAI',
|
name: "OpenRouter",
|
||||||
baseURL: 'https://api.openai.com/v1',
|
baseURL: "https://openrouter.ai/api/v1",
|
||||||
description: 'GPT-4, GPT-3.5 Turbo, and other OpenAI models'
|
apiKeysURL: "https://openrouter.ai/settings/keys",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'anthropic',
|
id: "ppq",
|
||||||
name: 'Anthropic',
|
name: "PayPerQ",
|
||||||
baseURL: 'https://api.anthropic.com/v1',
|
baseURL: "https://api.ppq.ai",
|
||||||
description: 'Claude 3.5 Sonnet, Claude 3 Opus, and other Claude models'
|
apiKeysURL: "https://ppq.ai/api-docs",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'openrouter',
|
id: "zai",
|
||||||
name: 'OpenRouter',
|
name: "Z.ai",
|
||||||
baseURL: 'https://openrouter.ai/api/v1',
|
baseURL: "https://api.z.ai/api/paas/v4",
|
||||||
description: 'Access to hundreds of models from various providers'
|
apiKeysURL: "https://z.ai/manage-apikey/apikey-list",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'together',
|
id: "moonshot",
|
||||||
name: 'Together AI',
|
name: "Moonshot",
|
||||||
baseURL: 'https://api.together.xyz/v1',
|
baseURL: "https://api.moonshot.ai/v1",
|
||||||
description: 'Open-source models like Llama, Mistral, and more'
|
apiKeysURL: "https://platform.moonshot.ai/console/api-keys",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'groq',
|
id: "openai",
|
||||||
name: 'Groq',
|
name: "OpenAI",
|
||||||
baseURL: 'https://api.groq.com/openai/v1',
|
baseURL: "https://api.openai.com/v1",
|
||||||
description: 'Ultra-fast inference for Llama, Mixtral, and Gemma models'
|
apiKeysURL: "https://platform.openai.com/api-keys",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'deepseek',
|
id: "anthropic",
|
||||||
name: 'DeepSeek',
|
name: "Anthropic",
|
||||||
baseURL: 'https://api.deepseek.com/v1',
|
baseURL: "https://api.anthropic.com/v1",
|
||||||
description: 'DeepSeek-V2.5 and other high-performance models'
|
apiKeysURL: "https://console.anthropic.com/settings/keys",
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
interface AISettingsDialogProps {
|
interface AISettingsDialogProps {
|
||||||
@@ -72,6 +72,8 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
const [localProviders, setLocalProviders] = useState(settings.providers);
|
const [localProviders, setLocalProviders] = useState(settings.providers);
|
||||||
const [customProviderName, setCustomProviderName] = useState('');
|
const [customProviderName, setCustomProviderName] = useState('');
|
||||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||||
|
const [customApiKey, setCustomApiKey] = useState('');
|
||||||
|
const [presetApiKeys, setPresetApiKeys] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
updateSettings({ providers: localProviders });
|
updateSettings({ providers: localProviders });
|
||||||
@@ -82,19 +84,30 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
setLocalProviders(settings.providers);
|
setLocalProviders(settings.providers);
|
||||||
setCustomProviderName('');
|
setCustomProviderName('');
|
||||||
setCustomBaseURL('');
|
setCustomBaseURL('');
|
||||||
|
setCustomApiKey('');
|
||||||
|
setPresetApiKeys({});
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddPresetProvider = (preset: PresetProvider) => {
|
const handleAddPresetProvider = (preset: PresetProvider) => {
|
||||||
|
const apiKey = presetApiKeys[preset.id] || '';
|
||||||
|
if (!apiKey.trim()) return;
|
||||||
|
|
||||||
const newProvider: AIConnection = {
|
const newProvider: AIConnection = {
|
||||||
baseURL: preset.baseURL,
|
baseURL: preset.baseURL,
|
||||||
apiKey: '',
|
apiKey: apiKey.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
setLocalProviders(prev => ({
|
setLocalProviders(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
[preset.id]: newProvider,
|
[preset.id]: newProvider,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Clear the API key input for this preset
|
||||||
|
setPresetApiKeys(prev => ({
|
||||||
|
...prev,
|
||||||
|
[preset.id]: '',
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddCustomProvider = () => {
|
const handleAddCustomProvider = () => {
|
||||||
@@ -102,7 +115,7 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
|
|
||||||
const newProvider: AIConnection = {
|
const newProvider: AIConnection = {
|
||||||
baseURL: customBaseURL.trim(),
|
baseURL: customBaseURL.trim(),
|
||||||
apiKey: '',
|
apiKey: customApiKey.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
setLocalProviders(prev => ({
|
setLocalProviders(prev => ({
|
||||||
@@ -111,6 +124,7 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
}));
|
}));
|
||||||
setCustomProviderName('');
|
setCustomProviderName('');
|
||||||
setCustomBaseURL('');
|
setCustomBaseURL('');
|
||||||
|
setCustomApiKey('');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveProvider = (name: string) => {
|
const handleRemoveProvider = (name: string) => {
|
||||||
@@ -191,9 +205,15 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
</AccordionTrigger>
|
</AccordionTrigger>
|
||||||
<AccordionContent className="px-4 pb-4">
|
<AccordionContent className="px-4 pb-4">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{preset && (
|
<div className="grid gap-2">
|
||||||
<p className="text-sm text-muted-foreground">{preset.description}</p>
|
<Label htmlFor={`${providerId}-baseURL`}>Base URL</Label>
|
||||||
)}
|
<Input
|
||||||
|
id={`${providerId}-baseURL`}
|
||||||
|
placeholder="https://api.example.com/v1"
|
||||||
|
value={provider?.baseURL || ''}
|
||||||
|
onChange={(e) => handleUpdateProvider(providerId, { baseURL: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor={`${providerId}-apiKey`}>API Key</Label>
|
<Label htmlFor={`${providerId}-apiKey`}>API Key</Label>
|
||||||
<Input
|
<Input
|
||||||
@@ -204,20 +224,6 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
onChange={(e) => handleUpdateProvider(providerId, { apiKey: e.target.value })}
|
onChange={(e) => handleUpdateProvider(providerId, { apiKey: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
|
||||||
<Label htmlFor={`${providerId}-baseURL`}>Base URL</Label>
|
|
||||||
<Input
|
|
||||||
id={`${providerId}-baseURL`}
|
|
||||||
placeholder="https://api.example.com/v1"
|
|
||||||
value={provider?.baseURL || ''}
|
|
||||||
onChange={(e) => handleUpdateProvider(providerId, { baseURL: e.target.value })}
|
|
||||||
/>
|
|
||||||
{preset && (
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Default: {preset.baseURL}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
@@ -233,25 +239,41 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
{availablePresets.length > 0 && (
|
{availablePresets.length > 0 && (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<h4 className="text-sm font-medium">Add Provider</h4>
|
<h4 className="text-sm font-medium">Add Provider</h4>
|
||||||
<div className="grid gap-3">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||||
{availablePresets.map((preset) => (
|
{availablePresets.map((preset) => (
|
||||||
<Card key={preset.id} className="cursor-pointer hover:bg-muted/50 transition-colors">
|
<Card key={preset.id}>
|
||||||
<CardContent className="p-4">
|
<CardContent className="p-4 space-y-3">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="space-y-1">
|
<h5 className="font-medium">{preset.name}</h5>
|
||||||
<div className="flex items-center gap-2">
|
<button
|
||||||
<h5 className="font-medium">{preset.name}</h5>
|
type="button"
|
||||||
<Badge variant="secondary" className="text-xs">Preset</Badge>
|
className="text-xs text-muted-foreground underline hover:text-foreground"
|
||||||
</div>
|
onClick={() => window.open(preset.apiKeysURL, '_blank')}
|
||||||
<p className="text-sm text-muted-foreground">{preset.description}</p>
|
>
|
||||||
<p className="text-xs text-muted-foreground font-mono">{preset.baseURL}</p>
|
Get API key
|
||||||
</div>
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Input
|
||||||
|
placeholder="Enter your API key"
|
||||||
|
type="password"
|
||||||
|
className="flex-1"
|
||||||
|
value={presetApiKeys[preset.id] || ''}
|
||||||
|
onChange={(e) => setPresetApiKeys(prev => ({
|
||||||
|
...prev,
|
||||||
|
[preset.id]: e.target.value,
|
||||||
|
}))}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) {
|
||||||
|
handleAddPresetProvider(preset);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleAddPresetProvider(preset)}
|
onClick={() => handleAddPresetProvider(preset)}
|
||||||
|
disabled={!presetApiKeys[preset.id]?.trim()}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="gap-2"
|
|
||||||
>
|
>
|
||||||
<Check className="h-4 w-4" />
|
|
||||||
Add
|
Add
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -287,6 +309,16 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
onChange={(e) => setCustomBaseURL(e.target.value)}
|
onChange={(e) => setCustomBaseURL(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<Label htmlFor="custom-apikey">API Key</Label>
|
||||||
|
<Input
|
||||||
|
id="custom-apikey"
|
||||||
|
type="password"
|
||||||
|
placeholder="Enter your API key (optional)"
|
||||||
|
value={customApiKey}
|
||||||
|
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleAddCustomProvider}
|
onClick={handleAddCustomProvider}
|
||||||
disabled={
|
disabled={
|
||||||
@@ -308,23 +340,6 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Usage Instructions */}
|
|
||||||
<div className="bg-muted/50 rounded-lg p-4 space-y-2">
|
|
||||||
<h4 className="text-sm font-medium">Usage</h4>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
In the chat, use the format <code className="bg-background px-1 rounded">provider/model</code> to specify which provider and model to use.
|
|
||||||
</p>
|
|
||||||
<div className="text-sm text-muted-foreground space-y-1">
|
|
||||||
<p><strong>Examples:</strong></p>
|
|
||||||
<ul className="list-disc list-inside ml-2 space-y-0.5">
|
|
||||||
<li><code className="bg-background px-1 rounded">openrouter/anthropic/claude-3.5-sonnet</code></li>
|
|
||||||
<li><code className="bg-background px-1 rounded">openai/gpt-4o</code></li>
|
|
||||||
<li><code className="bg-background px-1 rounded">anthropic/claude-3-5-sonnet-20241022</code></li>
|
|
||||||
<li><code className="bg-background px-1 rounded">groq/llama-3.1-70b-versatile</code></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
|
|||||||
Reference in new issue
Block a user