diff --git a/src/components/Common/SaveButton.tsx b/src/components/Common/SaveButton.tsx index 0767aa6..1a15ff2 100644 --- a/src/components/Common/SaveButton.tsx +++ b/src/components/Common/SaveButton.tsx @@ -1,5 +1,5 @@ import { useState } from "react" - +import { CheckIcon } from "lucide-react" type Props = { onClick?: () => void disabled?: boolean @@ -23,13 +23,16 @@ export const SaveButton = ({ type={btnType} onClick={() => { setClickedSave(true) - onClick() + if (onClick) { + onClick() + } setTimeout(() => { setClickedSave(false) }, 1000) }} disabled={disabled} className={`inline-flex mt-4 items-center rounded-md border border-transparent bg-black px-2 py-2 text-sm font-medium leading-4 text-white shadow-sm dark:bg-white dark:text-gray-800 disabled:opacity-50 ${className}`}> + {clickedSave ? : null} {clickedSave ? textOnSave : text} ) diff --git a/src/components/Option/Playground/PlaygroundForm.tsx b/src/components/Option/Playground/PlaygroundForm.tsx index dbe1e21..459c971 100644 --- a/src/components/Option/Playground/PlaygroundForm.tsx +++ b/src/components/Option/Playground/PlaygroundForm.tsx @@ -262,9 +262,7 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { {!isSending ? ( { key: 1, label: ( setSendWhenEnter(e.target.checked) }> diff --git a/src/components/Option/Settings/ollama.tsx b/src/components/Option/Settings/ollama.tsx index 404a3eb..da5939c 100644 --- a/src/components/Option/Settings/ollama.tsx +++ b/src/components/Option/Settings/ollama.tsx @@ -1,54 +1,144 @@ -import { useQuery } from "@tanstack/react-query" -import { useEffect, useState } from "react" +import { useMutation, useQuery } from "@tanstack/react-query" +import { Form, InputNumber, Select, Skeleton } from "antd" +import { useState } from "react" import { SaveButton } from "~components/Common/SaveButton" -import { getOllamaURL, setOllamaURL as saveOllamaURL } from "~services/ollama" +import { + defaultEmbeddingChunkOverlap, + defaultEmbeddingChunkSize, + defaultEmbeddingModelForRag, + getAllModels, + getOllamaURL, + saveForRag, + setOllamaURL as saveOllamaURL +} from "~services/ollama" export const SettingsOllama = () => { const [ollamaURL, setOllamaURL] = useState("") - const { data: ollamaInfo } = useQuery({ + const { data: ollamaInfo, status } = useQuery({ queryKey: ["fetchOllamURL"], queryFn: async () => { - const ollamaURL = await getOllamaURL() + const [ollamaURL, allModels, chunkOverlap, chunkSize, defaultEM] = + await Promise.all([ + getOllamaURL(), + getAllModels(), + defaultEmbeddingChunkOverlap(), + defaultEmbeddingChunkSize(), + defaultEmbeddingModelForRag() + ]) + setOllamaURL(ollamaURL) return { - ollamaURL + models: allModels, + chunkOverlap, + chunkSize, + defaultEM } } }) - - useEffect(() => { - if (ollamaInfo?.ollamaURL) { - setOllamaURL(ollamaInfo.ollamaURL) + const { mutate: saveRAG, isPending: isSaveRAGPending } = useMutation({ + mutationFn: async (data: { + model: string + chunkSize: number + overlap: number + }) => { + await saveForRag(data.model, data.chunkSize, data.overlap) } - }, [ollamaInfo]) + }) return ( -
-
- - { - setOllamaURL(e.target.value) - }} - placeholder="Your Ollama URL" - className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100" - /> -
-
- { - saveOllamaURL(ollamaURL) - }} - className="mt-2" - /> -
+
+ {status === "pending" && } + {status === "success" && ( + <> +
+ + { + setOllamaURL(e.target.value) + }} + placeholder="Your Ollama URL" + className="w-full p-2 border border-gray-300 rounded-md dark:bg-[#262626] dark:text-gray-100" + /> +
+
+ { + saveOllamaURL(ollamaURL) + }} + className="mt-2" + /> +
+ +
{ + saveRAG({ + model: data.defaultEM, + chunkSize: data.chunkSize, + overlap: data.chunkOverlap + }) + }} + initialValues={{ + chunkSize: ollamaInfo?.chunkSize, + chunkOverlap: ollamaInfo?.chunkOverlap, + defaultEM: ollamaInfo?.defaultEM + }}> + +