Commit 6a27fa97 authored by 文旺-丰林-DEV's avatar 文旺-丰林-DEV

chat add promptword api

parent 8b542a3f
...@@ -2,86 +2,34 @@ import { Row, Col, Grid } from 'antd'; ...@@ -2,86 +2,34 @@ import { Row, Col, Grid } from 'antd';
import type { FC } from 'react'; import type { FC } from 'react';
import styles from './content.less'; import styles from './content.less';
import ProductionCard from './productionCard'; import ProductionCard from './productionCard';
import { IPromptWord } from '@/services/chatGLM/api';
const { useBreakpoint } = Grid; const { useBreakpoint } = Grid;
interface ChatFirstContentProps { interface ChatFirstContentProps {
list: IPromptWord[];
onChange?: (text: string) => void; onChange?: (text: string) => void;
} }
const ChatFirstContent: FC<ChatFirstContentProps> = (props) => { const ChatFirstContent: FC<ChatFirstContentProps> = (props) => {
const { onChange } = props; const { onChange, list } = props;
const screen = useBreakpoint(); const screen = useBreakpoint();
const isMobile = screen.xs; const isMobile = screen.xs;
const cardList = [
{
title: '市场营销',
content:
'请为我编写一个杨过大战钢铁侠的额电影脚本,要足够精彩,细节丰富,好像好莱坞大片,有场景有对话,叨叨剧本要求',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
title: '技术文档',
content: '请为我们的新款智能手表撰写一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
title: '灵感提示',
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
{
content: '请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项',
onclick: (text: string) => {
onChange && onChange(text);
},
},
];
return ( return (
<div className={styles.CardContent}> <div className={styles.CardContent}>
<Row gutter={1}> <Row gutter={1}>
{cardList.map((item, index) => { {list.map((item, index) => {
return ( return (
<Col lg={8} md={12} span={8} xs={24} sm={16} key={`${item.title}-card-${index}`}> <Col lg={8} md={12} span={8} xs={24} sm={16} key={`${item.title}-card-${index}`}>
<Row justify={isMobile && 'center'} className={styles.cardPadding}> <Row justify={isMobile && 'center'} className={styles.cardPadding}>
<ProductionCard title={item.title} content={item.content} onChange={item.onclick} /> <ProductionCard
title={item.title}
content={item.content}
onChange={() => {
onChange && onChange(item.content);
}}
/>
</Row> </Row>
</Col> </Col>
); );
......
...@@ -16,7 +16,7 @@ import { history } from 'umi'; ...@@ -16,7 +16,7 @@ import { history } from 'umi';
import LoginModal from '@/components/loginModal'; import LoginModal from '@/components/loginModal';
import NewSession from '@/components/newSession'; import NewSession from '@/components/newSession';
import { useWebSocket, useRequest } from 'ahooks'; import { useWebSocket, useRequest } from 'ahooks';
import { GetChatGLMToken } from '@/services/chatGLM/api'; import { GetChatGLMToken, GetPromptList } from '@/services/chatGLM/api';
const { useBreakpoint } = Grid; const { useBreakpoint } = Grid;
const { Title } = Typography; const { Title } = Typography;
...@@ -36,12 +36,15 @@ const Chat: React.FC = () => { ...@@ -36,12 +36,15 @@ const Chat: React.FC = () => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [selectSiderTabs, setSelectSiderTabs] = useState(''); const [selectSiderTabs, setSelectSiderTabs] = useState('');
const { data: glmToken } = useRequest(GetChatGLMToken); const { data: glmToken } = useRequest(GetChatGLMToken);
const { data: promptList, loading: promptLoading } = useRequest(GetPromptList);
const [answer, setAnswer] = useState(''); const [answer, setAnswer] = useState('');
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const messageHistory = useRef<IHistory[]>([]); const messageHistory = useRef<IHistory[]>([]);
const { sendMessage } = useWebSocket('wss://glm-api.baibaomen.com/ws', { const { sendMessage } = useWebSocket('wss://glm-api.baibaomen.com/ws', {
onMessage: (event) => { onMessage: (event) => {
const text = event.data; const text = event.data;
console.log(text);
if (text == '{{BBMCPLT}}') { if (text == '{{BBMCPLT}}') {
setLoading(false); setLoading(false);
} else { } else {
...@@ -251,7 +254,7 @@ const Chat: React.FC = () => { ...@@ -251,7 +254,7 @@ const Chat: React.FC = () => {
) : ( ) : (
<div className={classNames(isMobile && styles.mobileContent)}> <div className={classNames(isMobile && styles.mobileContent)}>
<Item name="firstInput"> <Item name="firstInput">
<ChatFirstContent /> <ChatFirstContent list={promptList?.items || []} />
</Item> </Item>
</div> </div>
)} )}
......
...@@ -32,6 +32,10 @@ export function loginChatGLM(options: ILoginParams) { ...@@ -32,6 +32,10 @@ export function loginChatGLM(options: ILoginParams) {
}); });
} }
export interface IPromptWord {
title: string;
content: string;
}
export function GetChatGLMToken(): Promise<string> { export function GetChatGLMToken(): Promise<string> {
return request('https://glm-mangement-api.baibaomen.com/user/token', { return request('https://glm-mangement-api.baibaomen.com/user/token', {
method: 'POST', method: 'POST',
...@@ -39,6 +43,17 @@ export function GetChatGLMToken(): Promise<string> { ...@@ -39,6 +43,17 @@ export function GetChatGLMToken(): Promise<string> {
}); });
} }
export function GetPromptList(): Promise<{ items: IPromptWord[] }> {
return request('https://glm-mangement-api.baibaomen.com/promptwords/page', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + JSON.parse(localStorage.getItem('user') || '')?.token,
'Content-Type': 'application/json',
},
body: JSON.stringify({ pageIndex: 0, pageSize: 10 }),
});
}
type History = [string, string]; type History = [string, string];
interface ITalkParams { interface ITalkParams {
prompt: string; prompt: string;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment