feat: Add ModelSelect component to SidepanelForm
This commit is contained in:
		
							parent
							
								
									f630addefc
								
							
						
					
					
						commit
						88ad1fcab7
					
				
							
								
								
									
										63
									
								
								src/components/Common/ModelSelect.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/components/Common/ModelSelect.tsx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | |||||||
|  | import { useQuery } from "@tanstack/react-query" | ||||||
|  | import { Dropdown, Tooltip } from "antd" | ||||||
|  | import { LucideBrain } from "lucide-react" | ||||||
|  | import React from "react" | ||||||
|  | import { useTranslation } from "react-i18next" | ||||||
|  | import { OllamaIcon } from "../Icons/Ollama" | ||||||
|  | import { fetchChatModels } from "@/services/ollama" | ||||||
|  | import { useMessage } from "@/hooks/useMessage" | ||||||
|  | 
 | ||||||
|  | export const ModelSelect: React.FC = () => { | ||||||
|  |   const { t } = useTranslation("common") | ||||||
|  |   const { setSelectedModel, selectedModel } = useMessage() | ||||||
|  |   const { data } = useQuery({ | ||||||
|  |     queryKey: ["getAllModelsForSelect"], | ||||||
|  |     queryFn: async () => { | ||||||
|  |       const models = await fetchChatModels({ returnEmpty: false }) | ||||||
|  |       return models | ||||||
|  |     } | ||||||
|  |   }) | ||||||
|  | 
 | ||||||
|  |   return ( | ||||||
|  |     <> | ||||||
|  |       {data && data.length > 0 && ( | ||||||
|  |         <Dropdown | ||||||
|  |           menu={{ | ||||||
|  |             items: | ||||||
|  |               data?.map((d) => ({ | ||||||
|  |                 key: d.name, | ||||||
|  |                 label: ( | ||||||
|  |                   <div className="w-52 gap-2 text-lg truncate inline-flex line-clamp-3  items-center  dark:border-gray-700"> | ||||||
|  |                     <div> | ||||||
|  |                       <OllamaIcon className="h-6 w-6 text-gray-400" /> | ||||||
|  |                     </div> | ||||||
|  |                     {d.name} | ||||||
|  |                   </div> | ||||||
|  |                 ), | ||||||
|  |                 onClick: () => { | ||||||
|  |                   if (selectedModel === d.name) { | ||||||
|  |                     setSelectedModel(null) | ||||||
|  |                   } else { | ||||||
|  |                     setSelectedModel(d.name) | ||||||
|  |                   } | ||||||
|  |                 } | ||||||
|  |               })) || [], | ||||||
|  |             style: { | ||||||
|  |               maxHeight: 500, | ||||||
|  |               overflowY: "scroll" | ||||||
|  |             }, | ||||||
|  |             className: "no-scrollbar", | ||||||
|  |             activeKey: selectedModel | ||||||
|  |           }} | ||||||
|  |           placement={"topLeft"} | ||||||
|  |           trigger={["click"]}> | ||||||
|  |           <Tooltip title={t("selectAModel")}> | ||||||
|  |             <button type="button" className="dark:text-gray-300"> | ||||||
|  |               <LucideBrain className="h-5 w-5"/> | ||||||
|  |             </button> | ||||||
|  |           </Tooltip> | ||||||
|  |         </Dropdown> | ||||||
|  |       )} | ||||||
|  |     </> | ||||||
|  |   ) | ||||||
|  | } | ||||||
| @ -1,4 +1,4 @@ | |||||||
| import { useQuery } from "@tanstack/react-query" | import { useQuery, useQueryClient } from "@tanstack/react-query" | ||||||
| import { Select } from "antd" | import { Select } from "antd" | ||||||
| import { RotateCcw } from "lucide-react" | import { RotateCcw } from "lucide-react" | ||||||
| import { useEffect, useState } from "react" | import { useEffect, useState } from "react" | ||||||
| @ -15,6 +15,7 @@ import { | |||||||
| export const EmptySidePanel = () => { | export const EmptySidePanel = () => { | ||||||
|   const [ollamaURL, setOllamaURL] = useState<string>("") |   const [ollamaURL, setOllamaURL] = useState<string>("") | ||||||
|   const { t } = useTranslation(["playground", "common"]) |   const { t } = useTranslation(["playground", "common"]) | ||||||
|  |   const queryClient = useQueryClient() | ||||||
|   const { |   const { | ||||||
|     data: ollamaInfo, |     data: ollamaInfo, | ||||||
|     status: ollamaStatus, |     status: ollamaStatus, | ||||||
| @ -26,7 +27,9 @@ export const EmptySidePanel = () => { | |||||||
|       const ollamaURL = await getOllamaURL() |       const ollamaURL = await getOllamaURL() | ||||||
|       const isOk = await isOllamaRunning() |       const isOk = await isOllamaRunning() | ||||||
|       const models = await fetchChatModels({ returnEmpty: false }) |       const models = await fetchChatModels({ returnEmpty: false }) | ||||||
| 
 |       queryClient.invalidateQueries({ | ||||||
|  |         queryKey: ["getAllModelsForSelect"] | ||||||
|  |       }) | ||||||
|       return { |       return { | ||||||
|         isOk, |         isOk, | ||||||
|         models, |         models, | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ import { useWebUI } from "~/store/webui" | |||||||
| import { defaultEmbeddingModelForRag } from "~/services/ollama" | import { defaultEmbeddingModelForRag } from "~/services/ollama" | ||||||
| import { ImageIcon, MicIcon, StopCircleIcon, X } from "lucide-react" | import { ImageIcon, MicIcon, StopCircleIcon, X } from "lucide-react" | ||||||
| import { useTranslation } from "react-i18next" | import { useTranslation } from "react-i18next" | ||||||
|  | import { ModelSelect } from "@/components/Common/ModelSelect" | ||||||
| 
 | 
 | ||||||
| type Props = { | type Props = { | ||||||
|   dropedFile: File | undefined |   dropedFile: File | undefined | ||||||
| @ -186,6 +187,7 @@ export const SidepanelForm = ({ dropedFile }: Props) => { | |||||||
|                 {...form.getInputProps("message")} |                 {...form.getInputProps("message")} | ||||||
|               /> |               /> | ||||||
|               <div className="flex mt-4 justify-end gap-3"> |               <div className="flex mt-4 justify-end gap-3"> | ||||||
|  |                 <ModelSelect /> | ||||||
|                 <Tooltip title={t("tooltip.speechToText")}> |                 <Tooltip title={t("tooltip.speechToText")}> | ||||||
|                   <button |                   <button | ||||||
|                     type="button" |                     type="button" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user