Skip to content

Commit 6984c10

Browse files
authored
Merge pull request #571 from n4ze3m/next
v1.5.11
2 parents 75e2cc6 + 8fbe4fd commit 6984c10

File tree

17 files changed

+609
-63
lines changed

17 files changed

+609
-63
lines changed

bun.lockb

864 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@tailwindcss/forms": "^0.5.7",
3434
"@tailwindcss/typography": "^0.5.10",
3535
"@tanstack/react-query": "^5.17.19",
36+
"@tanstack/react-virtual": "^3.13.6",
3637
"@vitejs/plugin-react": "^4.2.1",
3738
"antd": "^5.13.3",
3839
"axios": "^1.6.7",

src/components/Layouts/Layout.tsx

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTranslation } from "react-i18next"
77

88
import { CurrentChatModelSettings } from "../Common/Settings/CurrentChatModelSettings"
99
import { Header } from "./Header"
10-
import { EraserIcon } from "lucide-react"
10+
import { EraserIcon, XIcon } from "lucide-react"
1111
import { PageAssitDatabase } from "@/db"
1212
import { useMessageOption } from "@/hooks/useMessageOption"
1313
import { useQueryClient } from "@tanstack/react-query"
@@ -52,39 +52,47 @@ export default function OptionLayout({
5252
<div className="flex items-center justify-between">
5353
{t("sidebarTitle")}
5454

55-
<Tooltip
56-
title={t(
57-
"settings:generalSettings.system.deleteChatHistory.label"
58-
)}
59-
placement="right">
60-
<button
61-
onClick={async () => {
62-
const confirm = window.confirm(
63-
t(
64-
"settings:generalSettings.system.deleteChatHistory.confirm"
55+
<div className="flex items-center space-x-3">
56+
<Tooltip
57+
title={t(
58+
"settings:generalSettings.system.deleteChatHistory.label"
59+
)}
60+
placement="right">
61+
<button
62+
onClick={async () => {
63+
const confirm = window.confirm(
64+
t(
65+
"settings:generalSettings.system.deleteChatHistory.confirm"
66+
)
6567
)
66-
)
6768

68-
if (confirm) {
69-
const db = new PageAssitDatabase()
70-
await db.deleteAllChatHistory()
71-
await queryClient.invalidateQueries({
72-
queryKey: ["fetchChatHistory"]
73-
})
74-
clearChat()
75-
}
76-
}}
77-
className="text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100">
78-
<EraserIcon className="size-5" />
69+
if (confirm) {
70+
const db = new PageAssitDatabase()
71+
await db.deleteAllChatHistory()
72+
await queryClient.invalidateQueries({
73+
queryKey: ["fetchChatHistory"]
74+
})
75+
clearChat()
76+
}
77+
}}
78+
className="text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100">
79+
<EraserIcon className="size-5" />
80+
</button>
81+
</Tooltip>
82+
<button
83+
onClick={() => setSidebarOpen(false)}
84+
className="md:hidden">
85+
<XIcon className="h-5 w-5 text-gray-500 dark:text-gray-400" />
7986
</button>
80-
</Tooltip>
87+
</div>
8188
</div>
8289
}
8390
placement="left"
8491
closeIcon={null}
8592
onClose={() => setSidebarOpen(false)}
8693
open={sidebarOpen}>
8794
<Sidebar
95+
isOpen={sidebarOpen}
8896
onClose={() => setSidebarOpen(false)}
8997
setMessages={setMessages}
9098
setHistory={setHistory}

src/components/Layouts/SettingsOptionLayout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export const SettingsLayout = ({ children }: { children: React.ReactNode }) => {
9696
name={t("openai:settings")}
9797
icon={CpuIcon}
9898
current={location.pathname}
99-
beta
10099
/>
101100
<LinkComponent
102101
href="/settings/model"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { SaveButton } from "@/components/Common/SaveButton"
2+
import { getModelSettings, setModelSettings } from "@/services/model-settings"
3+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
4+
import {
5+
Collapse,
6+
Form,
7+
Input,
8+
InputNumber,
9+
Modal,
10+
Skeleton,
11+
Switch
12+
} from "antd"
13+
import { Loader2 } from "lucide-react"
14+
import React from "react"
15+
import { useTranslation } from "react-i18next"
16+
17+
type Props = {
18+
model_id: string
19+
open: boolean
20+
setOpen: (open: boolean) => void
21+
}
22+
23+
export const AddUpdateOAIModelSettings: React.FC<Props> = ({
24+
model_id,
25+
open,
26+
setOpen
27+
}) => {
28+
const [form] = Form.useForm()
29+
const { t } = useTranslation("common")
30+
const queryClient = useQueryClient()
31+
32+
const { status, isError } = useQuery({
33+
queryKey: ["fetchModelSettings", model_id],
34+
queryFn: async () => {
35+
const data = await getModelSettings(model_id)
36+
form.setFieldsValue(data)
37+
return data
38+
},
39+
staleTime: 0
40+
})
41+
42+
const { mutate, isPending } = useMutation({
43+
mutationFn: setModelSettings,
44+
onSuccess: async () => {
45+
await queryClient.invalidateQueries({
46+
queryKey: ["fetchModel"]
47+
})
48+
await queryClient.invalidateQueries({
49+
queryKey: ["fetchAllModels"]
50+
})
51+
await queryClient.invalidateQueries({
52+
queryKey: ["fetchCustomModels"]
53+
})
54+
55+
setOpen(false)
56+
}
57+
})
58+
59+
return (
60+
<Modal
61+
title={t("modelSettings.label")}
62+
open={open}
63+
onCancel={() => {
64+
setOpen(false)
65+
}}
66+
footer={null}>
67+
{status === "pending" && <Skeleton active />}
68+
{status === "success" && (
69+
<Form
70+
onFinish={(values: any) => {
71+
mutate({
72+
model_id,
73+
settings: values
74+
})
75+
}}
76+
form={form}
77+
layout="vertical">
78+
<Form.Item
79+
name="temperature"
80+
label={t("modelSettings.form.temperature.label")}>
81+
<InputNumber
82+
size="large"
83+
style={{ width: "100%" }}
84+
placeholder={t("modelSettings.form.temperature.placeholder")}
85+
/>
86+
</Form.Item>
87+
<Form.Item
88+
name="numPredict"
89+
label={t("modelSettings.form.numPredict.label")}>
90+
<InputNumber
91+
style={{ width: "100%" }}
92+
placeholder={t("modelSettings.form.numPredict.placeholder")}
93+
/>
94+
</Form.Item>
95+
<Form.Item name="topP" label={t("modelSettings.form.topP.label")}>
96+
<InputNumber
97+
style={{ width: "100%" }}
98+
size="large"
99+
placeholder={t("modelSettings.form.topP.placeholder")}
100+
/>
101+
</Form.Item>
102+
<Form.Item
103+
name="reasoningEffort"
104+
label={t("modelSettings.form.reasoningEffort.label")}>
105+
<Input
106+
style={{ width: "100%" }}
107+
placeholder={t("modelSettings.form.reasoningEffort.placeholder")}
108+
/>
109+
</Form.Item>
110+
111+
<button
112+
type="submit"
113+
className="inline-flex justify-center w-full text-center 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 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 dark:bg-white dark:text-gray-800 dark:hover:bg-gray-100 dark:focus:ring-gray-500 dark:focus:ring-offset-gray-100 disabled:opacity-50 ">
114+
{isPending ? (
115+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
116+
) : (
117+
t("save")
118+
)}
119+
</button>
120+
</Form>
121+
)}
122+
</Modal>
123+
)
124+
}

src/components/Option/Models/CustomModelsTable.tsx

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { getAllCustomModels, deleteModel } from "@/db/models"
22
import { useStorage } from "@plasmohq/storage/hook"
33
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query"
44
import { Avatar, Skeleton, Table, Tag, Tooltip } from "antd"
5-
import { Pencil, Trash2 } from "lucide-react"
5+
import { Pencil, Settings, Trash2 } from "lucide-react"
66
import { useState } from "react"
77
import { useTranslation } from "react-i18next"
88
import { ModelNickModelNicknameModal } from "./ModelNicknameModal"
9+
import { AddUpdateOAIModelSettings } from "./AddUpdateOAIModelSettings"
910

1011
export const CustomModelsTable = () => {
1112
const [selectedModel, setSelectedModel] = useStorage("selectedModel")
@@ -20,7 +21,7 @@ export const CustomModelsTable = () => {
2021
model_avatar: ""
2122
})
2223
const { t } = useTranslation(["openai", "common"])
23-
24+
const [openSettingsModal, setOpenSettingsModal] = useState(false)
2425
const queryClient = useQueryClient()
2526

2627
const { data, status } = useQuery({
@@ -96,22 +97,39 @@ export const CustomModelsTable = () => {
9697
{
9798
title: t("manageModels.columns.actions"),
9899
render: (_, record) => (
99-
<Tooltip title={t("manageModels.tooltip.delete")}>
100-
<button
101-
onClick={() => {
102-
if (
103-
window.confirm(t("manageModels.confirm.delete"))
104-
) {
105-
deleteCustomModel(record.id)
106-
if (selectedModel && selectedModel === record.id) {
107-
setSelectedModel(null)
100+
<div className="flex gap-2">
101+
<Tooltip title={t("common:modelSettings.label")}>
102+
<button
103+
onClick={() => {
104+
setModel({
105+
model_id: record.id
106+
})
107+
setOpenSettingsModal(true)
108+
}}
109+
className="text-gray-700 dark:text-gray-400">
110+
<Settings className="size-4" />
111+
</button>
112+
</Tooltip>
113+
<Tooltip title={t("manageModels.tooltip.delete")}>
114+
<button
115+
onClick={() => {
116+
if (
117+
window.confirm(t("manageModels.confirm.delete"))
118+
) {
119+
deleteCustomModel(record.id)
120+
if (
121+
selectedModel &&
122+
selectedModel === record.id
123+
) {
124+
setSelectedModel(null)
125+
}
108126
}
109-
}
110-
}}
111-
className="text-red-500 dark:text-red-400">
112-
<Trash2 className="w-5 h-5" />
113-
</button>
114-
</Tooltip>
127+
}}
128+
className="text-red-500 dark:text-red-400">
129+
<Trash2 className="w-5 h-5" />
130+
</button>
131+
</Tooltip>
132+
</div>
115133
)
116134
}
117135
]}
@@ -128,6 +146,12 @@ export const CustomModelsTable = () => {
128146
model_name={model.model_name}
129147
model_avatar={model.model_avatar}
130148
/>
149+
150+
<AddUpdateOAIModelSettings
151+
model_id={model.model_id}
152+
open={openSettingsModal}
153+
setOpen={setOpenSettingsModal}
154+
/>
131155
</div>
132156
)
133157
}

src/components/Option/Settings/openai.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export const OpenAIApp = () => {
209209
dataSource={configs}
210210
loading={isLoading}
211211
rowKey="id"
212+
bordered
212213
/>
213214

214215
<Modal

src/components/Option/Sidebar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Props = {
4040
temporaryChat: boolean
4141
historyId: string
4242
history: any
43+
isOpen: boolean
4344
}
4445

4546
export const Sidebar = ({
@@ -52,7 +53,8 @@ export const Sidebar = ({
5253
clearChat,
5354
historyId,
5455
setSystemPrompt,
55-
temporaryChat
56+
temporaryChat,
57+
isOpen
5658
}: Props) => {
5759
const { t } = useTranslation(["option", "common"])
5860
const client = useQueryClient()
@@ -112,7 +114,8 @@ export const Sidebar = ({
112114

113115
return groups
114116
},
115-
placeholderData: (prev) => prev
117+
placeholderData: (prev) => prev,
118+
enabled: isOpen,
116119
})
117120

118121
const { mutate: deleteHistory } = useMutation({

src/components/Sidepanel/Chat/header.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
EraserIcon,
1010
// EraserIcon,
1111
HistoryIcon,
12-
PlusSquare
12+
PlusSquare,
13+
XIcon
1314
} from "lucide-react"
1415
import { useTranslation } from "react-i18next"
1516
import { CurrentChatModelSettings } from "@/components/Common/Settings/CurrentChatModelSettings"
@@ -115,14 +116,21 @@ export const SidepanelHeader = () => {
115116
<Drawer
116117
title={
117118
<div className="flex items-center justify-between">
118-
{t("tooltip.history")}
119+
<div className="flex items-center justify-between">
120+
{t("tooltip.history")}
121+
</div>
122+
123+
<button onClick={() => setSidebarOpen(false)}>
124+
<XIcon className="h-5 w-5 text-gray-500 dark:text-gray-400" />
125+
</button>
119126
</div>
120127
}
121128
placement="left"
122129
closeIcon={null}
123130
onClose={() => setSidebarOpen(false)}
124131
open={sidebarOpen}>
125132
<Sidebar
133+
isOpen={sidebarOpen}
126134
onClose={() => setSidebarOpen(false)}
127135
setMessages={setMessages}
128136
setHistory={setHistory}

0 commit comments

Comments
 (0)