refactor: remove gpt demo

This commit is contained in:
Tristan Yang
2023-04-11 09:39:37 +08:00
parent b700a24011
commit 8d3fd646c3
4 changed files with 0 additions and 78 deletions
-1
View File
@@ -27,7 +27,6 @@ const whiteList = [
"createAdmin",
"getBotRelatedChannels",
"sendMessageByBot",
"replyWithChatGPT",
"getAgoraVoicingList"
];
-8
View File
@@ -195,13 +195,6 @@ export const messageApi = createApi({
}
}
}),
replyWithChatGPT: builder.mutation<{ message: string, prompt: string }, string>({
query: (prompt) => ({
url: `https://official.voce.chat/chatgpt/complete`,
method: "POST",
body: { prompt, api_key: "test" }
})
}),
replyMessage: builder.mutation<
number,
{ from_uid: number, reply_mid: number; content: string; type: ContentTypeKey, properties?: {} }
@@ -265,6 +258,5 @@ export const {
useLazyDeleteMessageQuery,
useReadMessageMutation,
useCreateArchiveMutation,
useReplyWithChatGPTMutation,
useLazyLoadMoreMessagesQuery
} = messageApi;
-67
View File
@@ -1,67 +0,0 @@
import { useState, useEffect, FormEvent } from 'react';
import { JellyTriangle } from '@uiball/loaders';
import { useReplyWithChatGPTMutation } from '../app/services/message';
import Textarea from '../common/component/styled/Textarea';
import Button from '../common/component/styled/Button';
import clsx from 'clsx';
// type Props = {}
type Conversation = {
type: "prompt" | "reply", content: string
}[]
const GPTDemo = () => {
// const promptRef = useRef<HTMLTextAreaElement | undefined>();
// const [prompt, setPrompt] = useState("");
const [talk, setTalk] = useState<Conversation>([]);
const [feedTheGPT, { data, isSuccess, isLoading }] = useReplyWithChatGPTMutation();
const handleSend = (evt: FormEvent<HTMLFormElement>) => {
evt.preventDefault();
const form = evt.currentTarget;
// 检查格式
if (!form?.checkValidity()) {
form?.reportValidity();
return;
}
const content = new FormData(form).get("prompt") as string;
feedTheGPT(content);
setTalk(prevs => {
return [...prevs, { type: "prompt", content }];
});
form.reset();
};
useEffect(() => {
if (isSuccess && data) {
const { message } = data;
setTalk(prevs => {
return [...prevs, { type: "reply", content: message }];
});
}
}, [isSuccess, data]);
return (
<section className='flex-center flex-col gap-2 max-w-3xl m-auto w-screen h-screen overflow-scroll'>
<div className="flex flex-col gap-2 w-full mb-10 px-2">
{talk.map(({ type, content }) => {
return <div className="flex items-start gap-3" key={content}>
<span className='text-sm text-gray-500 uppercase min-w-[65px] text-right'>{type}:</span>
<div className={clsx("text-xl font-bold border border-solid border-gray-200 p-2", type == "reply" && 'bg-green-600 text-white')}>{content}</div>
</div>;
})}
</div>
{isLoading &&
<JellyTriangle
size={30}
color="#555"
/>}
<form onSubmit={handleSend} className="w-full flex flex-col gap-2 items-center sticky bottom-0">
<div className='w-full'>
<Textarea rows={8} required name='prompt' placeholder='Input prompt please' />
</div>
<Button type='submit' disabled={isLoading} >Send</Button>
</form>
</section>
);
};
export default GPTDemo;
-2
View File
@@ -22,7 +22,6 @@ const SettingChannelPage = lazy(() => import("./settingChannel"));
const SettingDMPage = lazy(() => import("./settingDM"));
const SettingPage = lazy(() => import("./setting"));
const ResourceManagement = lazy(() => import("./resources"));
const GPTDemo = lazy(() => import("./gptDemo"));
const GuestLogin = lazy(() => import("./guest"));
const ChatPage = lazy(() => import("./chat"));
const HomePage = lazy(() => import("./home"));
@@ -59,7 +58,6 @@ const PageRoutes = () => {
return (
<HashRouter>
<Routes>
<Route path="/gpt" element={<LazyIt><GPTDemo /></LazyIt>} />
<Route path="/guest_login" element={<LazyIt><GuestLogin /></LazyIt>} />
<Route path="/cb/:type/:payload" element={<LazyIt><CallbackPage /></LazyIt>} />
<Route path="/oauth/:token" element={<LazyIt><OAuthPage /></LazyIt>} />