Update src/components/settings/settings.tsx
Browse files- src/components/settings/settings.tsx +120 -12
src/components/settings/settings.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
/* eslint-disable @typescript-eslint/no-explicit-any */
|
| 2 |
import classNames from "classnames";
|
| 3 |
-
|
| 4 |
import { PiGearSixFill } from "react-icons/pi";
|
| 5 |
// @ts-expect-error not needed
|
| 6 |
import { PROVIDERS } from "./../../../utils/providers";
|
|
@@ -11,13 +11,27 @@ function Settings({
|
|
| 11 |
provider,
|
| 12 |
error,
|
| 13 |
onChange,
|
|
|
|
|
|
|
| 14 |
}: {
|
| 15 |
open: boolean;
|
| 16 |
provider: string;
|
| 17 |
error?: string;
|
| 18 |
onClose: React.Dispatch<React.SetStateAction<boolean>>;
|
| 19 |
onChange: (provider: string) => void;
|
|
|
|
|
|
|
| 20 |
}) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
return (
|
| 22 |
<div className="">
|
| 23 |
<button
|
|
@@ -54,16 +68,6 @@ function Settings({
|
|
| 54 |
<main className="px-4 pt-3 pb-4 space-y-4">
|
| 55 |
{/* toggle using tailwind css */}
|
| 56 |
<div>
|
| 57 |
-
<a
|
| 58 |
-
href="https://huggingface.co/spaces/enzostvs/deepsite/discussions/74"
|
| 59 |
-
target="_blank"
|
| 60 |
-
className="w-full flex items-center justify-between text-gray-600 bg-gray-50 border border-gray-100 px-2 py-2 rounded-lg mb-3 text-sm font-medium hover:brightness-95"
|
| 61 |
-
>
|
| 62 |
-
How to use it locally?
|
| 63 |
-
<button className="bg-black text-white rounded-md px-3 py-1.5 text-xs font-semibold cursor-pointer">
|
| 64 |
-
See the guide
|
| 65 |
-
</button>
|
| 66 |
-
</a>
|
| 67 |
<div className="flex items-center justify-between">
|
| 68 |
<p className="text-gray-800 text-sm font-medium flex items-center justify-between">
|
| 69 |
Use auto-provider
|
|
@@ -128,10 +132,114 @@ function Settings({
|
|
| 128 |
</div>
|
| 129 |
))}
|
| 130 |
</div>
|
|
|
|
| 131 |
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
</main>
|
| 133 |
</div>
|
| 134 |
</div>
|
| 135 |
);
|
| 136 |
}
|
| 137 |
-
export default Settings;
|
|
|
|
| 1 |
/* eslint-disable @typescript-eslint/no-explicit-any */
|
| 2 |
import classNames from "classnames";
|
| 3 |
+
import { useEffect } from "react";
|
| 4 |
import { PiGearSixFill } from "react-icons/pi";
|
| 5 |
// @ts-expect-error not needed
|
| 6 |
import { PROVIDERS } from "./../../../utils/providers";
|
|
|
|
| 11 |
provider,
|
| 12 |
error,
|
| 13 |
onChange,
|
| 14 |
+
localSettings,
|
| 15 |
+
setLocalSettings,
|
| 16 |
}: {
|
| 17 |
open: boolean;
|
| 18 |
provider: string;
|
| 19 |
error?: string;
|
| 20 |
onClose: React.Dispatch<React.SetStateAction<boolean>>;
|
| 21 |
onChange: (provider: string) => void;
|
| 22 |
+
localSettings: any;
|
| 23 |
+
setLocalSettings: React.Dispatch<React.SetStateAction<any>>;
|
| 24 |
}) {
|
| 25 |
+
|
| 26 |
+
// persist the local settings to local storage
|
| 27 |
+
const persistLocalSettings = () => {
|
| 28 |
+
localStorage.setItem('localSettings', JSON.stringify(localSettings));
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
useEffect(() => {
|
| 32 |
+
persistLocalSettings();
|
| 33 |
+
}, [localSettings]);
|
| 34 |
+
|
| 35 |
return (
|
| 36 |
<div className="">
|
| 37 |
<button
|
|
|
|
| 68 |
<main className="px-4 pt-3 pb-4 space-y-4">
|
| 69 |
{/* toggle using tailwind css */}
|
| 70 |
<div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
<div className="flex items-center justify-between">
|
| 72 |
<p className="text-gray-800 text-sm font-medium flex items-center justify-between">
|
| 73 |
Use auto-provider
|
|
|
|
| 132 |
</div>
|
| 133 |
))}
|
| 134 |
</div>
|
| 135 |
+
<hr className="text-gray-800 text-sm font-medium mb-2" />
|
| 136 |
</label>
|
| 137 |
+
{provider === "local" && (
|
| 138 |
+
<div className="space-y-2">
|
| 139 |
+
<p className="text-gray-800 text-sm font-medium mb-2">
|
| 140 |
+
Make sure to run the local server first
|
| 141 |
+
</p>
|
| 142 |
+
<hr className="text-gray-800 text-sm font-medium mb-2" />
|
| 143 |
+
<label className="block">
|
| 144 |
+
<p className="text-gray-800 text-sm font-medium mb-1">
|
| 145 |
+
API Key
|
| 146 |
+
</p>
|
| 147 |
+
<input
|
| 148 |
+
type="text"
|
| 149 |
+
value={localSettings.apiKey}
|
| 150 |
+
onChange={(e) => {
|
| 151 |
+
setLocalSettings({ ...localSettings, apiKey: e.target.value });
|
| 152 |
+
}}
|
| 153 |
+
className="w-full border border-gray-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 154 |
+
/>
|
| 155 |
+
</label>
|
| 156 |
+
<label className="block">
|
| 157 |
+
<p className="text-gray-800 text-sm font-medium mb-1">
|
| 158 |
+
API URL
|
| 159 |
+
</p>
|
| 160 |
+
<input
|
| 161 |
+
type="text"
|
| 162 |
+
value={localSettings.apiUrl || "http://localhost:11434/v1"}
|
| 163 |
+
onChange={(e) => {
|
| 164 |
+
setLocalSettings({ ...localSettings, apiUrl: e.target.value });
|
| 165 |
+
}}
|
| 166 |
+
className="w-full border border-gray-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 167 |
+
/>
|
| 168 |
+
</label>
|
| 169 |
+
<label className="block">
|
| 170 |
+
<p className="text-gray-800 text-sm font-medium mb-1">
|
| 171 |
+
Model
|
| 172 |
+
</p>
|
| 173 |
+
<input
|
| 174 |
+
type="text"
|
| 175 |
+
value={localSettings.model || "gemma3:1b"}
|
| 176 |
+
onChange={(e) => {
|
| 177 |
+
setLocalSettings({ ...localSettings, model: e.target.value });
|
| 178 |
+
}}
|
| 179 |
+
className="w-full border border-gray-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 180 |
+
/>
|
| 181 |
+
</label>
|
| 182 |
+
</div>
|
| 183 |
+
)}
|
| 184 |
+
{provider === "openrouter" && (
|
| 185 |
+
<div className="space-y-2">
|
| 186 |
+
<p className="text-gray-800 text-sm font-medium mb-2">
|
| 187 |
+
Get your OpenRouter API key from
|
| 188 |
+
<a
|
| 189 |
+
href="https://openrouter.ai/
|
| 190 |
+
"
|
| 191 |
+
target="_blank"
|
| 192 |
+
rel="noopener noreferrer"
|
| 193 |
+
className="text-blue-500"
|
| 194 |
+
>
|
| 195 |
+
here
|
| 196 |
+
</a>
|
| 197 |
+
</p>
|
| 198 |
+
<hr className="text-gray-800 text-sm font-medium mb-2" />
|
| 199 |
+
<label className="block">
|
| 200 |
+
<p className="text-gray-800 text-sm font-medium mb-1">
|
| 201 |
+
API Key
|
| 202 |
+
</p>
|
| 203 |
+
<input
|
| 204 |
+
type="text"
|
| 205 |
+
value={localSettings.openRouterApiKey}
|
| 206 |
+
onChange={(e) => {
|
| 207 |
+
setLocalSettings({ ...localSettings, openRouterApiKey: e.target.value });
|
| 208 |
+
}}
|
| 209 |
+
className="w-full border border-gray-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 210 |
+
/>
|
| 211 |
+
</label>
|
| 212 |
+
<label className="block">
|
| 213 |
+
<p className="text-gray-800 text-sm font-medium mb-1">
|
| 214 |
+
Base URL
|
| 215 |
+
</p>
|
| 216 |
+
<input
|
| 217 |
+
type="text"
|
| 218 |
+
value={localSettings.openRouterApiUrl || "https://openrouter.ai/api/v1"}
|
| 219 |
+
onChange={(e) => {
|
| 220 |
+
setLocalSettings({ ...localSettings, openRouterApiUrl: e.target.value });
|
| 221 |
+
}}
|
| 222 |
+
className="w-full border border-gray-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 223 |
+
/>
|
| 224 |
+
</label>
|
| 225 |
+
<label className="block">
|
| 226 |
+
<p className="text-gray-800 text-sm font-medium mb-1">
|
| 227 |
+
Model
|
| 228 |
+
</p>
|
| 229 |
+
<input
|
| 230 |
+
type="text"
|
| 231 |
+
value={localSettings.openRouterModel || "deepseek/deepseek-chat-v3-0324:free"}
|
| 232 |
+
onChange={(e) => {
|
| 233 |
+
setLocalSettings({ ...localSettings, openRouterModel: e.target.value });
|
| 234 |
+
}}
|
| 235 |
+
className="w-full border border-gray-200 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 236 |
+
/>
|
| 237 |
+
</label>
|
| 238 |
+
</div>
|
| 239 |
+
)}
|
| 240 |
</main>
|
| 241 |
</div>
|
| 242 |
</div>
|
| 243 |
);
|
| 244 |
}
|
| 245 |
+
export default Settings;
|