diff --git a/frontend/src/app/api/mutations/useUpdateFlowSettingMutation.ts b/frontend/src/app/api/mutations/useUpdateFlowSettingMutation.ts new file mode 100644 index 00000000..80adff97 --- /dev/null +++ b/frontend/src/app/api/mutations/useUpdateFlowSettingMutation.ts @@ -0,0 +1,55 @@ +import { + useMutation, + useQueryClient, + UseMutationOptions, +} from "@tanstack/react-query"; + +interface UpdateFlowSettingVariables { + llm_model?: string; + system_prompt?: string; + ocr?: boolean; + picture_descriptions?: boolean; + chunk_size?: number; + chunk_overlap?: number; +} + +interface UpdateFlowSettingResponse { + message: string; +} + +export const useUpdateFlowSettingMutation = ( + options?: Omit< + UseMutationOptions, + "mutationFn" + >, +) => { + const queryClient = useQueryClient(); + + async function updateFlowSetting( + variables: UpdateFlowSettingVariables, + ): Promise { + const response = await fetch("/api/settings", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(variables), + }); + + if (!response.ok) { + const error = await response.json(); + throw new Error(error.error || "Failed to update settings"); + } + + return response.json(); + } + + return useMutation({ + mutationFn: updateFlowSetting, + onSuccess: () => { + // Invalidate settings query to refetch updated data + queryClient.invalidateQueries({ queryKey: ["settings"] }); + }, + ...options, + }); +}; \ No newline at end of file diff --git a/frontend/src/app/settings/page.tsx b/frontend/src/app/settings/page.tsx index e7250394..65020743 100644 --- a/frontend/src/app/settings/page.tsx +++ b/frontend/src/app/settings/page.tsx @@ -17,8 +17,11 @@ import { import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Textarea } from "@/components/ui/textarea"; import { useAuth } from "@/contexts/auth-context"; import { useTask } from "@/contexts/task-context"; +import { useUpdateFlowSettingMutation } from "@/app/api/mutations/useUpdateFlowSettingMutation"; interface GoogleDriveFile { id: string; @@ -93,6 +96,20 @@ function KnowledgeSourcesPage() { const [langflowIngestEditUrl, setLangflowIngestEditUrl] = useState(""); const [publicLangflowUrl, setPublicLangflowUrl] = useState(""); + // Agent Behavior state + const [selectedModel, setSelectedModel] = useState("gpt-4"); + const [systemPrompt, setSystemPrompt] = useState(""); + + // Mutations + const updateFlowSettingMutation = useUpdateFlowSettingMutation({ + onSuccess: () => { + console.log("Setting updated successfully"); + }, + onError: (error) => { + console.error("Failed to update setting:", error.message); + }, + }); + // Fetch settings from backend const fetchSettings = useCallback(async () => { @@ -115,12 +132,29 @@ function KnowledgeSourcesPage() { if (settings.langflow_public_url) { setPublicLangflowUrl(settings.langflow_public_url); } + if (settings.agent?.llm_model) { + setSelectedModel(settings.agent.llm_model); + } + if (settings.agent?.system_prompt) { + setSystemPrompt(settings.agent.system_prompt); + } } } catch (error) { console.error("Failed to fetch settings:", error); } }, []); + // Update model selection immediately + const handleModelChange = (newModel: string) => { + setSelectedModel(newModel); + updateFlowSettingMutation.mutate({ llm_model: newModel }); + }; + + // Update system prompt with save button + const handleSystemPromptSave = () => { + updateFlowSettingMutation.mutate({ system_prompt: systemPrompt }); + }; + // Helper function to get connector icon const getConnectorIcon = (iconName: string) => { const iconMap: { [key: string]: React.ReactElement } = { @@ -594,6 +628,61 @@ function KnowledgeSourcesPage() { + +
+
+ + +
+
+ +