Skip to content

Commit

Permalink
fix: correct model settings for openai endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanrauf committed Feb 2, 2025
1 parent b448d9d commit 64c1b68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/app/core/chat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class ChatService:
"""Service for handling chat interactions with AI."""

DEFAULT_MODEL = "gpt-4"
DEFAULT_MODEL = "gpt-4o"
DEFAULT_MODEL_SETTINGS = {
"temperature": 0.7,
"max_tokens": 1000,
Expand Down
31 changes: 20 additions & 11 deletions frontend/src/components/chat/ChatInfoSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,41 @@ const badgeVariants = {

export function ChatInfoSidebar({ chatInfo, onUpdateSettings }: ChatInfoSidebarProps) {
const [modelSettings, setModelSettings] = useState<ModelSettings>(chatInfo.model_settings);
const [modelName, setModelName] = useState<string>(chatInfo.model_name);
const { toast } = useToast();
const [saveTimeout, setSaveTimeout] = useState<NodeJS.Timeout | null>(null);

useEffect(() => {
setModelSettings(chatInfo.model_settings);
}, [chatInfo.model_settings]);
setModelName(chatInfo.model_name);
}, [chatInfo.model_settings, chatInfo.model_name]);

const handleModelChange = async (newModelName: string) => {
setModelName(newModelName);
try {
// Update model_name at root level
await onUpdateSettings({ model_name: newModelName });
} catch (error) {
toast({
title: "Error",
description: "Failed to update model",
variant: "destructive",
});
}
};

const handleSettingChange = (key: keyof ModelSettings, value: number | string) => {
const newSettings = { ...modelSettings, [key]: value };
setModelSettings(newSettings);

// Clear existing timeout
if (saveTimeout) {
clearTimeout(saveTimeout);
}

// Set new timeout for auto-save
const timeout = setTimeout(async () => {
try {
await onUpdateSettings(newSettings);
// Update model_settings separately
await onUpdateSettings({ model_settings: newSettings });
} catch (error) {
toast({
title: "Error",
Expand All @@ -73,12 +88,6 @@ export function ChatInfoSidebar({ chatInfo, onUpdateSettings }: ChatInfoSidebarP
setSaveTimeout(timeout);
};

const handleModelChange = (modelName: string) => {
const newSettings = { ...modelSettings, model_name: modelName };
setModelSettings(newSettings);
void onUpdateSettings(newSettings);
};

return (
<div className="w-[350px] border-l bg-background">
<div className="p-4 border-b flex items-center justify-between">
Expand Down Expand Up @@ -230,7 +239,7 @@ export function ChatInfoSidebar({ chatInfo, onUpdateSettings }: ChatInfoSidebarP
<div className="space-y-2">
<Label className="text-xs text-muted-foreground">Model</Label>
<Select
value={modelSettings.model_name}
value={modelName}
onValueChange={handleModelChange}
>
<SelectTrigger className="w-full">
Expand Down

0 comments on commit 64c1b68

Please sign in to comment.