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

Commit 5e5f3fe

Browse files
committed
feature: integrate with extracted click prompt button
Signed-off-by: teobler <[email protected]>
1 parent b36e1c7 commit 5e5f3fe

File tree

19 files changed

+300
-845
lines changed

19 files changed

+300
-845
lines changed

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,34 @@
33
import React from "react";
44
import { DataTable } from "@/components/DataTable/DataTable";
55
import { createColumnHelper } from "@tanstack/react-table";
6-
import { ClickPromptButton } from "@/components/ClickPrompt/ClickPromptButton";
6+
import { ClickPromptButton } from "@/components/ClickPromptButton";
77

88
import gptCategorySamples from "@/assets/chatgpt/category/index.json";
99
import {
10-
Flex,
11-
Heading,
10+
Alert,
11+
AlertIcon,
12+
AlertTitle,
1213
Box,
1314
Card,
1415
CardBody,
1516
CardHeader,
16-
AlertIcon,
17-
AlertTitle,
18-
Alert,
17+
Flex,
18+
Heading,
1919
Link as NavLink,
2020
SimpleGrid,
2121
} from "@/components/ChakraUI";
2222
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";
2634

2735
type GeneralCommand = {
2836
type: string;
@@ -47,6 +55,18 @@ type CategoryGpt = {
4755

4856
type ChatgptSpecific = { type: string; description: string; example: string; prompt: string }[];
4957

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

@@ -64,7 +84,9 @@ function ChatGptGeneral({ locale, i18n, chatgptSpecific }: { chatgptSpecific: Ch
6484
}),
6585
columnHelper.accessor("clickPrompt", {
6686
cell: (info) => {
67-
return info.row.original.prompt !== "" ? <ClickPromptButton text={info.row.original.prompt} /> : null;
87+
return info.row.original.prompt !== "" ? (
88+
<ClickPromptButton text={info.row.original.prompt} llmServiceApi={llmServiceApi} />
89+
) : null;
6890
},
6991
header: "",
7092
}),
@@ -98,7 +120,7 @@ function ChatGptGeneral({ locale, i18n, chatgptSpecific }: { chatgptSpecific: Ch
98120
<CardHeader>
99121
<Flex justifyContent={"space-between"} alignItems={"center"}>
100122
<StyledTitle>{sample.name}</StyledTitle>
101-
<ClickPromptButton text={sample.ask} size={"sm"} />
123+
<ClickPromptButton text={sample.ask} size={"sm"} llmServiceApi={llmServiceApi} />
102124
</Flex>
103125
</CardHeader>
104126
<StyledCardBody maxH='320px' overflow='auto'>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,27 @@ import { Form, Formik } from "formik";
99
import { numberToChineseOrdinal } from "chinese-numbering";
1010

1111
import CopyComponent from "@/components/CopyComponent";
12-
import { ClickPromptButton } from "@/components/ClickPrompt/ClickPromptButton";
12+
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+
};
1333

1434
function ChatGptCotGenerator({ i18n, locale }: GeneralI18nProps) {
1535
const dict = i18n.dict;
@@ -86,7 +106,7 @@ ${dict["introduction-tail"]}`.replaceAll("<GameName>", name),
86106
</ReactMarkdown>
87107
<Box className='flex justify-end p-4'>
88108
<CopyComponent boxSize={10} value={markdown} />
89-
<ClickPromptButton text={markdown} />
109+
<ClickPromptButton text={markdown} llmServiceApi={llmServiceApi} />
90110
</Box>
91111
<Formik
92112
initialValues={{ name: "" }}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
"use client";
22

3-
import { useState, useRef } from "react";
3+
import { useRef, useState } from "react";
44
import { Heading, Input, Text } from "@chakra-ui/react";
55
import { createColumnHelper } from "@tanstack/react-table";
66
import { DataTable } from "@/components/DataTable/DataTable";
77
import { LinkIcon } from "@chakra-ui/icons";
88
import CopyComponent from "@/components/CopyComponent";
99
import Highlight from "@/components/Highlight";
10-
import { ClickPromptButton } from "@/components/ClickPrompt/ClickPromptButton";
11-
import { Pagination, usePagination, type PaginationState } from "@/components/Pagination";
10+
import { ClickPromptButton } from "@/components/ClickPromptButton";
11+
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";
1220

1321
type ActPrompt = {
1422
act: string;
@@ -19,6 +27,18 @@ type ActPrompt = {
1927

2028
const columnHelper = createColumnHelper<ActPrompt>();
2129

30+
const llmServiceApi: any = {
31+
login,
32+
logout,
33+
isLoggedIn,
34+
changeConversationName,
35+
createConversation,
36+
getChatsByConversationId,
37+
deleteConversation,
38+
deleteAllConversations,
39+
sendMsgWithStreamRes,
40+
};
41+
2242
const genColumns = (dict: Record<string, string>, highlight: string) => [
2343
columnHelper.accessor("act", {
2444
cell: (info) => <Highlight value={info.getValue()} keyword={highlight} />,
@@ -35,7 +55,9 @@ const genColumns = (dict: Record<string, string>, highlight: string) => [
3555
}),
3656
columnHelper.accessor("clickPrompt", {
3757
cell: (info) => {
38-
return info.row.original.prompt !== "" ? <ClickPromptButton text={info.row.original.prompt} /> : null;
58+
return info.row.original.prompt !== "" ? (
59+
<ClickPromptButton text={info.row.original.prompt} llmServiceApi={llmServiceApi} />
60+
) : null;
3961
},
4062
header: "",
4163
}),

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,42 @@ import React, { Fragment } from "react";
22
import CopyComponent from "@/components/CopyComponent";
33
import SimpleMarkdown from "@/components/markdown/SimpleMarkdown";
44
import { ChatGptIcon } from "@/components/CustomIcon";
5-
import { ClickPromptButton } from "@/components/ClickPrompt/ClickPromptButton";
5+
import { ClickPromptButton } from "@/components/ClickPromptButton";
66
import {
77
Avatar,
88
Box,
99
Breadcrumb,
1010
BreadcrumbItem,
1111
BreadcrumbLink,
12+
Flex,
1213
Heading,
1314
SimpleGrid,
14-
Flex,
1515
} from "@/components/ChakraUI";
1616
import { notFound } from "next/navigation";
1717
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+
};
2141

2242
const getSampleNames = async (locale: GeneralI18nProps["locale"]) => {
2343
const index = await import(`@/assets/chatgpt/samples/index_${locale}.json`).then((mod) => mod.default);
@@ -76,7 +96,7 @@ async function ChatGptSampleDetail({ params }: { params: { id: string } }) {
7696
</Flex>
7797
<Flex direction='row' gap='2'>
7898
<CopyComponent value={step.ask} />
79-
<ClickPromptButton size={"sm"} text={step.ask} />
99+
<ClickPromptButton size={"sm"} text={step.ask} llmServiceApi={llmServiceApi} />
80100
</Flex>
81101
</HumanBlock>
82102
<AiBlock direction='row' gap='2'>

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,45 @@ import {
55
Alert,
66
AlertIcon,
77
AlertTitle,
8+
Box,
89
Button,
9-
Flex,
1010
Card,
1111
CardBody,
1212
CardFooter,
1313
CardHeader,
14+
Flex,
1415
Heading,
1516
Link as NavLink,
1617
SimpleGrid,
1718
Stack,
18-
Box,
1919
Text,
2020
} from "@chakra-ui/react";
21-
2221
import Link from "next/link";
23-
2422
import { ExternalLinkIcon } from "@chakra-ui/icons";
2523
import SimpleMarkdown from "@/components/markdown/SimpleMarkdown";
26-
import { ClickPromptButton } from "@/components/ClickPrompt/ClickPromptButton";
24+
import { ClickPromptButton } from "@/components/ClickPromptButton";
2725
import { CP_GITHUB_ASSETS } from "@/configs/constants";
2826
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+
};
2947

3048
function ChatGptSamples({ i18n, samples }: { samples: Sample[] } & GeneralI18nProps) {
3149
const chatgptLink = `${CP_GITHUB_ASSETS}/chatgpt`;
@@ -63,7 +81,7 @@ function ChatGptSamples({ i18n, samples }: { samples: Sample[] } & GeneralI18nPr
6381
</Link>
6482
</Box>
6583
<Box>
66-
<ClickPromptButton text={sample.preview} />
84+
<ClickPromptButton text={sample.preview} llmServiceApi={llmServiceApi} />
6785
</Box>
6886
</Flex>
6987
</CardFooter>

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

3-
import { useState, MouseEventHandler, useMemo, ChangeEventHandler } from "react";
4-
import { Box, Card, CardBody, CardFooter, CardHeader, Flex, Text, Link, Stack, Select } from "@chakra-ui/react";
3+
import { ChangeEventHandler, MouseEventHandler, useMemo, useState } from "react";
4+
import { Box, Card, CardBody, CardFooter, CardHeader, Flex, Link, Select, Stack, Text } from "@chakra-ui/react";
55
import { ArrowDownIcon } from "@chakra-ui/icons";
66
import girl1_neutral from "@/assets/images/visual-novel/00055-3317647877.png";
77
import girl1_happy from "@/assets/images/visual-novel/00057-3317647877.png";
@@ -34,11 +34,17 @@ import restaurant from "@/assets/images/visual-novel/00146-2156326714.png";
3434

3535
import Image, { StaticImageData } from "next/image";
3636
import { upperFirst } from "lodash-es";
37-
import ExecutePromptButton from "@/components/ClickPrompt/ExecutePromptButton";
38-
import { ResponseSend } from "@/pages/api/chatgpt/chat";
37+
import { Chat, ExecutePromptButton } from "@/components/ClickPromptButton";
3938
import SimpleMarkdown from "@/components/markdown/SimpleMarkdown";
4039
import CopyComponent from "@/components/CopyComponent";
41-
import { fontSize } from "@mui/system";
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";
4248

4349
type StoryLine = {
4450
speaker: string;
@@ -53,6 +59,18 @@ type Scene = {
5359
story: StoryLine[];
5460
};
5561

62+
const llmServiceApi: any = {
63+
login,
64+
logout,
65+
isLoggedIn,
66+
changeConversationName,
67+
createConversation,
68+
getChatsByConversationId,
69+
deleteConversation,
70+
deleteAllConversations,
71+
sendMessage,
72+
};
73+
5674
function ChatGptVisualNovel({ i18n }: GeneralI18nProps) {
5775
const dict = i18n.dict;
5876
const genres = ["romance", "fantasy", "horror", "sci-fi", "crime"];
@@ -117,7 +135,7 @@ function ChatGptVisualNovel({ i18n }: GeneralI18nProps) {
117135
}
118136
};
119137

120-
const handleResponse = (response: ResponseSend) => {
138+
const handleResponse = (response: Chat[]) => {
121139
try {
122140
const newScene = JSON.parse(response[0].content.trim()) as Scene;
123141
if ("speaker" in newScene && "girls" in newScene && "story" in newScene) {
@@ -184,6 +202,7 @@ function ChatGptVisualNovel({ i18n }: GeneralI18nProps) {
184202
handleResponse={handleResponse}
185203
conversationId={conversationId}
186204
updateConversationId={updateConversationId}
205+
llmServiceApi={llmServiceApi}
187206
/>
188207
</Box>
189208
</Flex>
@@ -262,6 +281,7 @@ function ChatGptVisualNovel({ i18n }: GeneralI18nProps) {
262281
handleResponse={handleResponse}
263282
conversationId={conversationId}
264283
updateConversationId={updateConversationId}
284+
llmServiceApi={llmServiceApi}
265285
/>
266286
</Box>
267287
)}

0 commit comments

Comments
 (0)