2024-01-29 13:35:24 +08:00
|
|
|
"use client";
|
|
|
|
|
2024-01-21 23:08:25 +08:00
|
|
|
// Settings.tsx
|
|
|
|
import { useAppDispatch, useAppSelector } from "@/app/store";
|
2024-01-29 13:35:24 +08:00
|
|
|
import {
|
|
|
|
setApiKey,
|
|
|
|
setUpsreamUrl,
|
|
|
|
setSystemPrompt,
|
|
|
|
} from "@/app/store/slices/authSlice";
|
2024-02-20 10:52:33 +08:00
|
|
|
import {
|
|
|
|
setIsJumpToReference,
|
|
|
|
setIsEvaluateTopicMatch,
|
|
|
|
} from "@/app/store/slices/stateSlice";
|
2024-01-29 13:35:24 +08:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import Link from "next/link";
|
2024-02-09 11:45:14 +08:00
|
|
|
import { useLocalStorage } from "react-use";
|
2024-02-12 20:55:14 +08:00
|
|
|
import { useTranslation } from "@/app/i18n/client";
|
2024-02-09 11:45:14 +08:00
|
|
|
|
2024-02-12 20:55:14 +08:00
|
|
|
const Settings = ({ lng }: { lng: string }) => {
|
|
|
|
//i18n
|
|
|
|
const { t } = useTranslation(lng);
|
|
|
|
const CONFIG_OPTIONS = [
|
|
|
|
{
|
2024-02-23 12:35:27 +08:00
|
|
|
name: t("configurations.蒙恬大将军"),
|
|
|
|
apiKey: "sk-jokVJ90l5Swxr5dt2f3b0988C8A442A69f97Ee4eAf7aDcF4",
|
|
|
|
upstreamUrl: "https://freeapi.iil.im",
|
2024-02-12 20:55:14 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: t("configurations.deepseek-chat"),
|
|
|
|
apiKey: "sk-ffe19ebe9fa44d00884330ff1c18cf82",
|
|
|
|
upstreamUrl: "https://api.deepseek.com",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: t("configurations.caifree"),
|
2024-02-24 09:54:12 +08:00
|
|
|
apiKey: "sk-pg92xYjZA208m6gnD56118E299B5448eB71f892cF68351D9",
|
2024-02-12 20:55:14 +08:00
|
|
|
upstreamUrl: "https://one.caifree.com",
|
|
|
|
},
|
2024-02-20 09:59:11 +08:00
|
|
|
{
|
|
|
|
name: t("configurations.linuxdo"),
|
|
|
|
apiKey: "nk-2311676378",
|
|
|
|
upstreamUrl: "https://chat.flssedu1.top/api/openai",
|
|
|
|
},
|
2024-02-20 22:11:02 +08:00
|
|
|
{
|
|
|
|
name: t("configurations.vv佬"),
|
|
|
|
apiKey: "nk-23118",
|
|
|
|
upstreamUrl: "https://cocopilot-pool.aivvm.com",
|
|
|
|
},
|
2024-02-23 12:35:27 +08:00
|
|
|
|
2024-02-12 20:55:14 +08:00
|
|
|
{
|
|
|
|
name: t("configurations.custom"),
|
|
|
|
apiKey: "",
|
|
|
|
upstreamUrl: "",
|
|
|
|
},
|
|
|
|
];
|
2024-02-14 21:37:52 +08:00
|
|
|
//https://freeapi.iil.im sk-GdUOBeCCCpeB16G877C8C62b849c4653A561550bEb79Fe7e
|
2024-02-05 23:14:40 +08:00
|
|
|
//redux
|
2024-01-21 23:08:25 +08:00
|
|
|
const dispatch = useAppDispatch();
|
2024-01-22 08:53:58 +08:00
|
|
|
const apiKey = useAppSelector((state) => state.auth.apiKey);
|
2024-01-27 23:25:07 +08:00
|
|
|
const upstreamUrl = useAppSelector((state) => state.auth.upsreamUrl);
|
2024-01-29 13:35:24 +08:00
|
|
|
const systemPrompt = useAppSelector((state) => state.auth.systemPrompt);
|
2024-02-13 16:32:04 +08:00
|
|
|
const isJumpToReference = useAppSelector(
|
|
|
|
(state) => state.state.isJumpToReference
|
|
|
|
);
|
2024-02-20 10:52:33 +08:00
|
|
|
const isEvaluateTopicMatch = useAppSelector(
|
|
|
|
(state) => state.state.isEvaluateTopicMatch
|
|
|
|
);
|
2024-02-09 11:45:14 +08:00
|
|
|
//state
|
|
|
|
const [userConfigNumber, setUserConfigNumber] = useLocalStorage(
|
|
|
|
"userConfigNumber",
|
|
|
|
"2"
|
|
|
|
);
|
2024-02-20 10:52:33 +08:00
|
|
|
const toggleSwitch = (currentState: any, setState: any) => {
|
|
|
|
setState(!currentState);
|
2024-02-13 16:32:04 +08:00
|
|
|
};
|
2024-01-21 23:08:25 +08:00
|
|
|
return (
|
2024-02-07 16:12:40 +08:00
|
|
|
<div className="max-w-md rounded overflow-hidden shadow-lg bg-blue-gray-100 z-1000 mx-auto ">
|
|
|
|
<h1 className="font-bold text-3xl">settings</h1>
|
|
|
|
<br />
|
|
|
|
<div className="flex justify-end mt-4 mr-4">
|
|
|
|
<Link href="/" aria-label="Settings">
|
2024-02-11 14:28:03 +08:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faArrowLeft}
|
|
|
|
size="2x"
|
|
|
|
className="icon-hover"
|
|
|
|
/>
|
2024-02-07 16:12:40 +08:00
|
|
|
</Link>
|
|
|
|
</div>
|
2024-02-09 11:45:14 +08:00
|
|
|
{/* 配置选择器 */}
|
|
|
|
<label
|
|
|
|
className="block text-gray-700 text-sm font-bold mb-2"
|
|
|
|
htmlFor="config-selector"
|
|
|
|
>
|
2024-02-12 20:55:14 +08:00
|
|
|
{t("配置选择器")}
|
2024-02-09 11:45:14 +08:00
|
|
|
</label>
|
|
|
|
<select
|
|
|
|
id="config-selector"
|
|
|
|
className="mb-4 block appearance-none w-full bg-white border border-gray-400 hover:border-gray-500 px-4 py-2 pr-8 rounded shadow leading-tight focus:outline-none focus:shadow-outline"
|
|
|
|
onChange={(event) => {
|
|
|
|
const selectedConfig = CONFIG_OPTIONS[Number(event.target.value)];
|
|
|
|
dispatch(setApiKey(selectedConfig.apiKey));
|
|
|
|
dispatch(setUpsreamUrl(selectedConfig.upstreamUrl));
|
|
|
|
setUserConfigNumber(event.target.value);
|
|
|
|
console.log("userConfigNumber", userConfigNumber);
|
|
|
|
}}
|
|
|
|
value={userConfigNumber}
|
|
|
|
>
|
|
|
|
{CONFIG_OPTIONS.map((option, index) => (
|
|
|
|
<option key={index} value={index}>
|
|
|
|
{option.name}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
2024-02-07 16:12:40 +08:00
|
|
|
{/* api key */}
|
|
|
|
<div className="mb-4">
|
|
|
|
<label
|
|
|
|
className="block text-gray-700 text-sm font-bold mb-2"
|
|
|
|
htmlFor="api-key"
|
|
|
|
>
|
|
|
|
API Key:
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
id="api-key"
|
2024-02-09 11:45:14 +08:00
|
|
|
type="password"
|
2024-02-20 13:26:12 +08:00
|
|
|
autoComplete="off"
|
2024-02-07 16:12:40 +08:00
|
|
|
value={apiKey}
|
|
|
|
onChange={(event) => dispatch(setApiKey(event.target.value))}
|
|
|
|
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
|
|
|
/>
|
|
|
|
{/* upstream-url */}
|
2024-01-27 23:25:07 +08:00
|
|
|
<div className="mb-4">
|
|
|
|
<label
|
|
|
|
className="block text-gray-700 text-sm font-bold mb-2"
|
2024-02-07 16:12:40 +08:00
|
|
|
htmlFor="upstream-url"
|
2024-01-27 23:25:07 +08:00
|
|
|
>
|
2024-02-12 20:55:14 +08:00
|
|
|
{t("Upstream URL:")}
|
2024-01-27 23:25:07 +08:00
|
|
|
</label>
|
|
|
|
<input
|
2024-02-07 16:12:40 +08:00
|
|
|
id="upstream-url"
|
2024-01-27 23:25:07 +08:00
|
|
|
type="text"
|
2024-02-07 16:12:40 +08:00
|
|
|
value={upstreamUrl}
|
|
|
|
onChange={(event) => dispatch(setUpsreamUrl(event.target.value))}
|
|
|
|
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{/* systemPrompt */}
|
|
|
|
<div className="mb-4">
|
|
|
|
<label
|
|
|
|
className="block text-gray-700 text-sm font-bold mb-2"
|
|
|
|
htmlFor="system-prompt"
|
|
|
|
>
|
2024-02-12 20:55:14 +08:00
|
|
|
{t("System Prompt(Paper2AI):")}
|
2024-02-07 16:12:40 +08:00
|
|
|
</label>
|
|
|
|
<textarea
|
|
|
|
id="system-prompt"
|
|
|
|
value={systemPrompt}
|
2024-02-08 23:28:33 +08:00
|
|
|
onChange={(event) => dispatch(setSystemPrompt(event.target.value))}
|
2024-01-29 13:35:24 +08:00
|
|
|
className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
|
2024-02-07 16:12:40 +08:00
|
|
|
rows={8}
|
2024-01-29 13:35:24 +08:00
|
|
|
/>
|
|
|
|
</div>
|
2024-01-22 08:53:58 +08:00
|
|
|
</div>
|
2024-02-13 16:32:04 +08:00
|
|
|
<label className="relative inline-flex items-center cursor-pointer">
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
className="sr-only peer"
|
|
|
|
checked={isJumpToReference}
|
2024-02-20 10:52:33 +08:00
|
|
|
onChange={() =>
|
|
|
|
toggleSwitch(isJumpToReference, (value: any) =>
|
|
|
|
dispatch(setIsJumpToReference(value))
|
|
|
|
)
|
|
|
|
}
|
2024-02-13 16:32:04 +08:00
|
|
|
/>
|
|
|
|
<div className="w-10 h-4 bg-gray-200 rounded-full peer-checked:bg-blue-600 peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 transition-colors ease-in-out duration-200"></div>
|
|
|
|
<span
|
|
|
|
className={`absolute block bg-white w-3 h-3 rounded-full transition ease-in-out duration-200 transform ${
|
|
|
|
isJumpToReference ? "translate-x-6" : "translate-x-1"
|
|
|
|
} -translate-y-1/2 top-1/2`}
|
|
|
|
></span>
|
|
|
|
{t("鼠标点击段落中的上标跳转到文献引用?")}
|
|
|
|
</label>
|
2024-02-20 10:52:33 +08:00
|
|
|
<label className="relative inline-flex items-center cursor-pointer">
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
className="sr-only peer"
|
|
|
|
checked={isEvaluateTopicMatch}
|
|
|
|
onChange={() =>
|
|
|
|
toggleSwitch(isEvaluateTopicMatch, (value: any) =>
|
|
|
|
dispatch(setIsEvaluateTopicMatch(value))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<div className="w-10 h-4 bg-gray-200 rounded-full peer-checked:bg-blue-600 peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 transition-colors ease-in-out duration-200"></div>
|
|
|
|
<span
|
|
|
|
className={`absolute block bg-white w-3 h-3 rounded-full transition ease-in-out duration-200 transform ${
|
|
|
|
isJumpToReference ? "translate-x-6" : "translate-x-1"
|
|
|
|
} -translate-y-1/2 top-1/2`}
|
|
|
|
></span>
|
|
|
|
{t("是否检查文献与主题相关性(如果不相关则不会传给AI引用)")}
|
|
|
|
</label>
|
2024-02-07 16:12:40 +08:00
|
|
|
</div>
|
2024-01-21 23:08:25 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Settings;
|