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 { RotateCcw } from "lucide-react"
|
||||
import { useEffect, useState } from "react"
|
||||
@ -15,6 +15,7 @@ import {
|
||||
export const EmptySidePanel = () => {
|
||||
const [ollamaURL, setOllamaURL] = useState<string>("")
|
||||
const { t } = useTranslation(["playground", "common"])
|
||||
const queryClient = useQueryClient()
|
||||
const {
|
||||
data: ollamaInfo,
|
||||
status: ollamaStatus,
|
||||
@ -26,7 +27,9 @@ export const EmptySidePanel = () => {
|
||||
const ollamaURL = await getOllamaURL()
|
||||
const isOk = await isOllamaRunning()
|
||||
const models = await fetchChatModels({ returnEmpty: false })
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["getAllModelsForSelect"]
|
||||
})
|
||||
return {
|
||||
isOk,
|
||||
models,
|
||||
|
@ -10,6 +10,7 @@ import { useWebUI } from "~/store/webui"
|
||||
import { defaultEmbeddingModelForRag } from "~/services/ollama"
|
||||
import { ImageIcon, MicIcon, StopCircleIcon, X } from "lucide-react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { ModelSelect } from "@/components/Common/ModelSelect"
|
||||
|
||||
type Props = {
|
||||
dropedFile: File | undefined
|
||||
@ -186,6 +187,7 @@ export const SidepanelForm = ({ dropedFile }: Props) => {
|
||||
{...form.getInputProps("message")}
|
||||
/>
|
||||
<div className="flex mt-4 justify-end gap-3">
|
||||
<ModelSelect />
|
||||
<Tooltip title={t("tooltip.speechToText")}>
|
||||
<button
|
||||
type="button"
|
||||
|
Loading…
x
Reference in New Issue
Block a user