Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SettingConfig(TypedDict):
"supported_models": [
{
"provider": ModelProvider.OPENAI.value,
"models": ["gpt-4o", "gpt-4o-mini", "o1"],
"models": ["gpt-4.5-preview", "gpt-4o", "gpt-4o-mini", "o1"],
},
{
"provider": ModelProvider.ANTHROPIC.value,
Expand Down
1 change: 1 addition & 0 deletions app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ export default function ChatPage() {
provider={currentSettings?.selectedProvider || ""}
isOpen={showApiKeyModal}
onSubmit={handleApiKeySubmit}
onClose={() => setShowApiKeyModal(false)}
/>
</>
);
Expand Down
1 change: 1 addition & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export default function Home() {
provider={currentSettings?.selectedProvider || ""}
isOpen={showApiKeyModal}
onSubmit={handleApiKeySubmit}
onClose={() => setShowApiKeyModal(false)}
/>
</main>
);
Expand Down
12 changes: 10 additions & 2 deletions components/ui/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ interface AuthModalProps {
provider: string;
isOpen: boolean;
onSubmit: (key: string) => void;
onClose?: () => void;
}

export function AuthModal({ provider, isOpen, onSubmit }: AuthModalProps) {
export function AuthModal({ provider, isOpen, onSubmit, onClose }: AuthModalProps) {
const [apiKey, setApiKey] = useState("");
const [error, setError] = useState("");

Expand All @@ -35,7 +36,14 @@ export function AuthModal({ provider, isOpen, onSubmit }: AuthModalProps) {
};

return (
<Dialog open={isOpen} onOpenChange={() => {}}>
<Dialog
open={isOpen}
onOpenChange={open => {
if (!open && onClose) {
onClose();
}
}}
>
<DialogContent
className={cn(
"flex w-[400px] shrink-0 flex-col",
Expand Down
85 changes: 80 additions & 5 deletions components/ui/SettingsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import { Info, Settings } from "lucide-react";
import { useRouter } from "next/navigation";

import { AuthModal } from "@/components/ui/AuthModal";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
Expand Down Expand Up @@ -190,6 +191,8 @@ function SettingInput({
function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
const { currentSettings, updateSettings } = useSettings();
const [apiKey, setApiKey] = useState("");
const [showApiKeyModal, setShowApiKeyModal] = useState(false);
const [pendingModelChange, setPendingModelChange] = useState<string | null>(null);
const router = useRouter();
const { clearInitialState } = useChatContext();
const { resetSession } = useSteelContext();
Expand Down Expand Up @@ -239,14 +242,23 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
(m: SupportedModel) => m.provider === currentSettings.selectedProvider
);

// Only reset the model if the current provider doesn't support it
if (
providerModels &&
providerModels.models.length > 0 &&
!providerModels.models.includes(currentSettings.selectedModel)
!providerModels.models.includes(currentSettings.selectedModel) &&
currentSettings.selectedProvider === providerModels.provider
) {
// Don't auto-switch to GPT-4.5-preview if no API key
const defaultModel =
providerModels.models[0] === "gpt-4.5-preview" &&
!currentSettings.providerApiKeys?.[currentSettings.selectedProvider]
? providerModels.models[1] // Use the next available model
: providerModels.models[0];

updateSettings({
...currentSettings,
selectedModel: providerModels.models[0],
selectedModel: defaultModel,
});
}
}
Expand All @@ -273,6 +285,28 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
}
};

const handleApiKeySubmit = (key: string) => {
if (!currentSettings) return;

const currentKeys = currentSettings.providerApiKeys || {};
const updatedSettings = {
...currentSettings,
providerApiKeys: {
...currentKeys,
[currentSettings.selectedProvider]: key,
},
};

// If there was a pending model change, apply it now
if (pendingModelChange) {
updatedSettings.selectedModel = pendingModelChange;
setPendingModelChange(null);
}

updateSettings(updatedSettings);
setShowApiKeyModal(false);
};

if (!currentSettings?.selectedAgent) {
return null;
}
Expand Down Expand Up @@ -413,10 +447,29 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
(m: SupportedModel) => m.provider === value
);
if (providerModels && providerModels.models.length > 0) {
// Keep the current model if it's available in the new provider's list
let newModel = providerModels.models.includes(currentSettings.selectedModel)
? currentSettings.selectedModel
: providerModels.models[0];

// If switching to GPT-4.5-preview but no API key, show modal
if (
newModel === "gpt-4.5-preview" &&
!currentSettings.providerApiKeys?.[value]
) {
setPendingModelChange(newModel);
updateSettings({
...currentSettings,
selectedProvider: value,
});
setShowApiKeyModal(true);
return;
}

updateSettings({
...currentSettings,
selectedProvider: value,
selectedModel: providerModels.models[0],
selectedModel: newModel,
});
}
}}
Expand Down Expand Up @@ -450,6 +503,17 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
});
return;
}

// Check if trying to use GPT-4.5-preview without an API key
if (
value === "gpt-4.5-preview" &&
!currentSettings.providerApiKeys?.[currentSettings.selectedProvider]
) {
setPendingModelChange(value);
setShowApiKeyModal(true);
return;
}

updateSettings({
...currentSettings,
selectedModel: value,
Expand Down Expand Up @@ -598,7 +662,7 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
</p>
<p className="mb-2 text-sm text-[--gray-11]">
2. Install Ollama from{" "}
<span className="text-[--blue-11] cursor-not-allowed">ollama.com</span>
<span className="cursor-not-allowed text-[--blue-11]">ollama.com</span>
</p>
<p className="mb-2 text-sm text-[--gray-11]">
3. Run Ollama locally with the model of your choice:
Expand All @@ -608,7 +672,7 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
</p>
<p className="text-sm text-[--gray-11]">
Visit{" "}
<span className="text-[--blue-11] cursor-not-allowed">
<span className="cursor-not-allowed text-[--blue-11]">
our GitHub repository
</span>{" "}
for detailed setup instructions.
Expand Down Expand Up @@ -752,6 +816,17 @@ function SettingsContent({ closeSettings }: { closeSettings: () => void }) {
</div>
</div>
</div>

{/* API Key Modal */}
<AuthModal
provider={currentSettings?.selectedProvider || ""}
isOpen={showApiKeyModal}
onSubmit={handleApiKeySubmit}
onClose={() => {
setShowApiKeyModal(false);
setPendingModelChange(null); // Clear any pending model change
}}
/>
</SheetContent>
);
}