Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 30db07b

Browse files
committed
refactor: extract all llm related api
Signed-off-by: teobler <[email protected]>
1 parent 5e5f3fe commit 30db07b

File tree

11 files changed

+59
-209
lines changed

11 files changed

+59
-209
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { isLoggedIn, login, logout } from "@/api/user";
2+
import {
3+
changeConversationName,
4+
createConversation,
5+
deleteAllConversations,
6+
deleteConversation,
7+
} from "@/api/conversation";
8+
import { getChatsByConversationId, sendMessage, sendMsgWithStreamRes } from "@/api/chat";
9+
import { LlmServiceApi } from "@click-prompt/click-prompt-button";
10+
11+
export const llmServiceApiWithStream: LlmServiceApi = {
12+
login,
13+
logout,
14+
isLoggedIn,
15+
changeConversationName,
16+
createConversation,
17+
getChatsByConversationId,
18+
deleteConversation,
19+
deleteAllConversations,
20+
sendMsgWithStreamRes,
21+
};
22+
23+
export const llmServiceApi: LlmServiceApi = {
24+
login,
25+
logout,
26+
isLoggedIn,
27+
changeConversationName,
28+
createConversation,
29+
getChatsByConversationId,
30+
deleteConversation,
31+
deleteAllConversations,
32+
sendMessage,
33+
};

packages/click-prompt/src/app/[lang]/chatgpt-general/page.client.tsx

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,7 @@ import SimpleMarkdown from "@/components/markdown/SimpleMarkdown";
2323
import { ExternalLinkIcon } from "@chakra-ui/icons";
2424
import { CP_GITHUB_ASSETS } from "@/configs/constants";
2525
import styled from "@emotion/styled";
26-
import { isLoggedIn, login, logout } from "@/api/user";
27-
import {
28-
changeConversationName,
29-
createConversation,
30-
deleteAllConversations,
31-
deleteConversation,
32-
} from "@/api/conversation";
33-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
26+
import { llmServiceApiWithStream } from "@/api/llmService";
3427

3528
type GeneralCommand = {
3629
type: string;
@@ -55,18 +48,6 @@ type CategoryGpt = {
5548

5649
type ChatgptSpecific = { type: string; description: string; example: string; prompt: string }[];
5750

58-
const llmServiceApi: any = {
59-
login,
60-
logout,
61-
isLoggedIn,
62-
changeConversationName,
63-
createConversation,
64-
getChatsByConversationId,
65-
deleteConversation,
66-
deleteAllConversations,
67-
sendMsgWithStreamRes,
68-
};
69-
7051
function ChatGptGeneral({ locale, i18n, chatgptSpecific }: { chatgptSpecific: ChatgptSpecific } & GeneralI18nProps) {
7152
const dict = i18n.dict;
7253

@@ -85,7 +66,7 @@ function ChatGptGeneral({ locale, i18n, chatgptSpecific }: { chatgptSpecific: Ch
8566
columnHelper.accessor("clickPrompt", {
8667
cell: (info) => {
8768
return info.row.original.prompt !== "" ? (
88-
<ClickPromptButton text={info.row.original.prompt} llmServiceApi={llmServiceApi} />
69+
<ClickPromptButton text={info.row.original.prompt} llmServiceApi={llmServiceApiWithStream} />
8970
) : null;
9071
},
9172
header: "",
@@ -120,7 +101,7 @@ function ChatGptGeneral({ locale, i18n, chatgptSpecific }: { chatgptSpecific: Ch
120101
<CardHeader>
121102
<Flex justifyContent={"space-between"} alignItems={"center"}>
122103
<StyledTitle>{sample.name}</StyledTitle>
123-
<ClickPromptButton text={sample.ask} size={"sm"} llmServiceApi={llmServiceApi} />
104+
<ClickPromptButton text={sample.ask} size={"sm"} llmServiceApi={llmServiceApiWithStream} />
124105
</Flex>
125106
</CardHeader>
126107
<StyledCardBody maxH='320px' overflow='auto'>

packages/click-prompt/src/app/[lang]/chatgpt-generator-cot/page.client.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,7 @@ import { numberToChineseOrdinal } from "chinese-numbering";
1010

1111
import CopyComponent from "@/components/CopyComponent";
1212
import { ClickPromptButton } from "@/components/ClickPromptButton";
13-
import { isLoggedIn, login, logout } from "@/api/user";
14-
import {
15-
changeConversationName,
16-
createConversation,
17-
deleteAllConversations,
18-
deleteConversation,
19-
} from "@/api/conversation";
20-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
21-
22-
const llmServiceApi: any = {
23-
login,
24-
logout,
25-
isLoggedIn,
26-
changeConversationName,
27-
createConversation,
28-
getChatsByConversationId,
29-
deleteConversation,
30-
deleteAllConversations,
31-
sendMsgWithStreamRes,
32-
};
13+
import { llmServiceApiWithStream } from "@/api/llmService";
3314

3415
function ChatGptCotGenerator({ i18n, locale }: GeneralI18nProps) {
3516
const dict = i18n.dict;
@@ -106,7 +87,7 @@ ${dict["introduction-tail"]}`.replaceAll("<GameName>", name),
10687
</ReactMarkdown>
10788
<Box className='flex justify-end p-4'>
10889
<CopyComponent boxSize={10} value={markdown} />
109-
<ClickPromptButton text={markdown} llmServiceApi={llmServiceApi} />
90+
<ClickPromptButton text={markdown} llmServiceApi={llmServiceApiWithStream} />
11091
</Box>
11192
<Formik
11293
initialValues={{ name: "" }}

packages/click-prompt/src/app/[lang]/chatgpt-prompt-role-play/page.client.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ import CopyComponent from "@/components/CopyComponent";
99
import Highlight from "@/components/Highlight";
1010
import { ClickPromptButton } from "@/components/ClickPromptButton";
1111
import { Pagination, type PaginationState, usePagination } from "@/components/Pagination";
12-
import { isLoggedIn, login, logout } from "@/api/user";
13-
import {
14-
changeConversationName,
15-
createConversation,
16-
deleteAllConversations,
17-
deleteConversation,
18-
} from "@/api/conversation";
19-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
12+
import { llmServiceApiWithStream } from "@/api/llmService";
2013

2114
type ActPrompt = {
2215
act: string;
@@ -27,18 +20,6 @@ type ActPrompt = {
2720

2821
const columnHelper = createColumnHelper<ActPrompt>();
2922

30-
const llmServiceApi: any = {
31-
login,
32-
logout,
33-
isLoggedIn,
34-
changeConversationName,
35-
createConversation,
36-
getChatsByConversationId,
37-
deleteConversation,
38-
deleteAllConversations,
39-
sendMsgWithStreamRes,
40-
};
41-
4223
const genColumns = (dict: Record<string, string>, highlight: string) => [
4324
columnHelper.accessor("act", {
4425
cell: (info) => <Highlight value={info.getValue()} keyword={highlight} />,
@@ -56,7 +37,7 @@ const genColumns = (dict: Record<string, string>, highlight: string) => [
5637
columnHelper.accessor("clickPrompt", {
5738
cell: (info) => {
5839
return info.row.original.prompt !== "" ? (
59-
<ClickPromptButton text={info.row.original.prompt} llmServiceApi={llmServiceApi} />
40+
<ClickPromptButton text={info.row.original.prompt} llmServiceApi={llmServiceApiWithStream} />
6041
) : null;
6142
},
6243
header: "",

packages/click-prompt/src/app/[lang]/chatgpt-samples/[id]/page.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,7 @@ import { AiBlock } from "@/components/chatgpt/AiBlock";
1818
import { HumanBlock } from "@/components/chatgpt/HumanBlock";
1919
import { getAppData } from "@/i18n";
2020
import type { Sample, SampleDetail } from "../type";
21-
import { isLoggedIn, login, logout } from "@/api/user";
22-
import {
23-
changeConversationName,
24-
createConversation,
25-
deleteAllConversations,
26-
deleteConversation,
27-
} from "@/api/conversation";
28-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
29-
30-
const llmServiceApi: any = {
31-
login,
32-
logout,
33-
isLoggedIn,
34-
changeConversationName,
35-
createConversation,
36-
getChatsByConversationId,
37-
deleteConversation,
38-
deleteAllConversations,
39-
sendMsgWithStreamRes,
40-
};
21+
import { llmServiceApiWithStream } from "@/api/llmService";
4122

4223
const getSampleNames = async (locale: GeneralI18nProps["locale"]) => {
4324
const index = await import(`@/assets/chatgpt/samples/index_${locale}.json`).then((mod) => mod.default);
@@ -96,7 +77,7 @@ async function ChatGptSampleDetail({ params }: { params: { id: string } }) {
9677
</Flex>
9778
<Flex direction='row' gap='2'>
9879
<CopyComponent value={step.ask} />
99-
<ClickPromptButton size={"sm"} text={step.ask} llmServiceApi={llmServiceApi} />
80+
<ClickPromptButton size={"sm"} text={step.ask} llmServiceApi={llmServiceApiWithStream} />
10081
</Flex>
10182
</HumanBlock>
10283
<AiBlock direction='row' gap='2'>

packages/click-prompt/src/app/[lang]/chatgpt-samples/page.client.tsx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,7 @@ import SimpleMarkdown from "@/components/markdown/SimpleMarkdown";
2424
import { ClickPromptButton } from "@/components/ClickPromptButton";
2525
import { CP_GITHUB_ASSETS } from "@/configs/constants";
2626
import type { Sample } from "./type";
27-
import { isLoggedIn, login, logout } from "@/api/user";
28-
import {
29-
changeConversationName,
30-
createConversation,
31-
deleteAllConversations,
32-
deleteConversation,
33-
} from "@/api/conversation";
34-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
35-
36-
const llmServiceApi: any = {
37-
login,
38-
logout,
39-
isLoggedIn,
40-
changeConversationName,
41-
createConversation,
42-
getChatsByConversationId,
43-
deleteConversation,
44-
deleteAllConversations,
45-
sendMsgWithStreamRes,
46-
};
27+
import { llmServiceApiWithStream } from "@/api/llmService";
4728

4829
function ChatGptSamples({ i18n, samples }: { samples: Sample[] } & GeneralI18nProps) {
4930
const chatgptLink = `${CP_GITHUB_ASSETS}/chatgpt`;
@@ -81,7 +62,7 @@ function ChatGptSamples({ i18n, samples }: { samples: Sample[] } & GeneralI18nPr
8162
</Link>
8263
</Box>
8364
<Box>
84-
<ClickPromptButton text={sample.preview} llmServiceApi={llmServiceApi} />
65+
<ClickPromptButton text={sample.preview} llmServiceApi={llmServiceApiWithStream} />
8566
</Box>
8667
</Flex>
8768
</CardFooter>

packages/click-prompt/src/app/[lang]/chatgpt-visual-novel/page.client.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ import { upperFirst } from "lodash-es";
3737
import { Chat, ExecutePromptButton } from "@/components/ClickPromptButton";
3838
import SimpleMarkdown from "@/components/markdown/SimpleMarkdown";
3939
import CopyComponent from "@/components/CopyComponent";
40-
import { isLoggedIn, login, logout } from "@/api/user";
41-
import {
42-
changeConversationName,
43-
createConversation,
44-
deleteAllConversations,
45-
deleteConversation,
46-
} from "@/api/conversation";
47-
import { getChatsByConversationId, sendMessage } from "@/api/chat";
40+
import { llmServiceApi } from "@/api/llmService";
4841

4942
type StoryLine = {
5043
speaker: string;
@@ -59,18 +52,6 @@ type Scene = {
5952
story: StoryLine[];
6053
};
6154

62-
const llmServiceApi: any = {
63-
login,
64-
logout,
65-
isLoggedIn,
66-
changeConversationName,
67-
createConversation,
68-
getChatsByConversationId,
69-
deleteConversation,
70-
deleteAllConversations,
71-
sendMessage,
72-
};
73-
7455
function ChatGptVisualNovel({ i18n }: GeneralI18nProps) {
7556
const dict = i18n.dict;
7657
const genres = ["romance", "fantasy", "horror", "sci-fi", "crime"];

packages/click-prompt/src/app/[lang]/chatgpt/page.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,8 @@ import React from "react";
44
import { cookies } from "next/headers";
55
import { SITE_USER_COOKIE } from "@/configs/constants";
66
import { ChatGPTApp } from "@/components/ClickPromptButton";
7-
import { isLoggedIn, login, logout } from "@/api/user";
8-
import {
9-
changeConversationName,
10-
createConversation,
11-
deleteAllConversations,
12-
deleteConversation,
13-
} from "@/api/conversation";
14-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
15-
16-
const llmServiceApi: any = {
17-
login,
18-
logout,
19-
isLoggedIn,
20-
changeConversationName,
21-
createConversation,
22-
getChatsByConversationId,
23-
deleteConversation,
24-
deleteAllConversations,
25-
sendMsgWithStreamRes,
26-
};
7+
import { isLoggedIn } from "@/api/user";
8+
import { llmServiceApiWithStream } from "@/api/llmService";
279

2810
export default async function ChatGPTPage() {
2911
const hashedKey = cookies().get(SITE_USER_COOKIE)?.value as string;
@@ -38,7 +20,7 @@ export default async function ChatGPTPage() {
3820

3921
return (
4022
<div className='bg-[#343541] flex h-[85vh] overflow-y-auto rounded-md items-center justify-center'>
41-
<ChatGPTApp loggedIn={isLoggedin} llmServiceApi={llmServiceApi} />
23+
<ChatGPTApp loggedIn={isLoggedin} llmServiceApi={llmServiceApiWithStream} />
4224
</div>
4325
);
4426
}

packages/click-prompt/src/app/[lang]/click-flow/[id]/StartlingStepDetail.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,7 @@ import CopyComponent from "@/components/CopyComponent";
1515
import PostFlowAction from "@/flows/components/PostFlowAction";
1616
import PreFlowAction from "@/flows/components/PreFlowAction";
1717
import { fillStepWithValued, FlowStep } from "@/flows/types/flow-step";
18-
import { isLoggedIn, login, logout } from "@/api/user";
19-
import {
20-
changeConversationName,
21-
createConversation,
22-
deleteAllConversations,
23-
deleteConversation,
24-
} from "@/api/conversation";
25-
import { getChatsByConversationId, sendMessage } from "@/api/chat";
26-
27-
const llmServiceApi: any = {
28-
login,
29-
logout,
30-
isLoggedIn,
31-
changeConversationName,
32-
createConversation,
33-
getChatsByConversationId,
34-
deleteConversation,
35-
deleteAllConversations,
36-
sendMessage,
37-
};
18+
import { llmServiceApi } from "@/api/llmService";
3819

3920
type StepProps = {
4021
index: number;

packages/click-prompt/src/app/[lang]/page.client.tsx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,7 @@ import { ClickPromptHome } from "@/components/CustomIcon";
55
import { GITHUB_URL } from "@/configs/constants";
66
import { ClickPromptButton } from "@/components/ClickPromptButton";
77
import React from "react";
8-
import { isLoggedIn, login, logout } from "@/api/user";
9-
import {
10-
changeConversationName,
11-
createConversation,
12-
deleteAllConversations,
13-
deleteConversation,
14-
} from "@/api/conversation";
15-
import { getChatsByConversationId, sendMsgWithStreamRes } from "@/api/chat";
16-
17-
const llmServiceApi: any = {
18-
login,
19-
logout,
20-
isLoggedIn,
21-
changeConversationName,
22-
createConversation,
23-
getChatsByConversationId,
24-
deleteConversation,
25-
deleteAllConversations,
26-
sendMsgWithStreamRes,
27-
};
8+
import { llmServiceApiWithStream } from "@/api/llmService";
289

2910
export const HomeClient = ({ dict }: { dict: Record<string, string> }) => {
3011
return (
@@ -62,7 +43,13 @@ export const HomeClient = ({ dict }: { dict: Record<string, string> }) => {
6243
<Button as='a' size='lg' h='4rem' px='40px' fontSize='1.2rem' href={GITHUB_URL} target='__blank'>
6344
GitHub
6445
</Button>
65-
<ClickPromptButton size='lg' h='4rem' px='40px' text='Hello World' llmServiceApi={llmServiceApi} />
46+
<ClickPromptButton
47+
size='lg'
48+
h='4rem'
49+
px='40px'
50+
text='Hello World'
51+
llmServiceApi={llmServiceApiWithStream}
52+
/>
6653
</Stack>
6754
</Box>
6855
</Container>

0 commit comments

Comments
 (0)