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

chat add promptword api

parent 8b542a3f
import { Row, Col, Grid } from 'antd';
import type { FC } from 'react';
import styles from './content.less';
import ProductionCard from './productionCard';
const { useBreakpoint } = Grid;
interface ChatFirstContentProps {
onChange?: (text: string) => void;
}
const ChatFirstContent: FC<ChatFirstContentProps> = (props) => {
const { onChange } = props;
const screen = useBreakpoint();
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 (
<div className={styles.CardContent}>
<Row gutter={1}>
{cardList.map((item, index) => {
return (
<Col lg={8} md={12} span={8} xs={24} sm={16} key={`${item.title}-card-${index}`}>
<Row justify={isMobile && 'center'} className={styles.cardPadding}>
<ProductionCard title={item.title} content={item.content} onChange={item.onclick} />
</Row>
</Col>
);
})}
</Row>
</div>
);
};
export default ChatFirstContent;
import { Row, Col, Grid } from 'antd';
import type { FC } from 'react';
import styles from './content.less';
import ProductionCard from './productionCard';
import { IPromptWord } from '@/services/chatGLM/api';
const { useBreakpoint } = Grid;
interface ChatFirstContentProps {
list: IPromptWord[];
onChange?: (text: string) => void;
}
const ChatFirstContent: FC<ChatFirstContentProps> = (props) => {
const { onChange, list } = props;
const screen = useBreakpoint();
const isMobile = screen.xs;
return (
<div className={styles.CardContent}>
<Row gutter={1}>
{list.map((item, index) => {
return (
<Col lg={8} md={12} span={8} xs={24} sm={16} key={`${item.title}-card-${index}`}>
<Row justify={isMobile && 'center'} className={styles.cardPadding}>
<ProductionCard
title={item.title}
content={item.content}
onChange={() => {
onChange && onChange(item.content);
}}
/>
</Row>
</Col>
);
})}
</Row>
</div>
);
};
export default ChatFirstContent;
......@@ -16,7 +16,7 @@ import { history } from 'umi';
import LoginModal from '@/components/loginModal';
import NewSession from '@/components/newSession';
import { useWebSocket, useRequest } from 'ahooks';
import { GetChatGLMToken } from '@/services/chatGLM/api';
import { GetChatGLMToken, GetPromptList } from '@/services/chatGLM/api';
const { useBreakpoint } = Grid;
const { Title } = Typography;
......@@ -36,12 +36,15 @@ const Chat: React.FC = () => {
const [form] = Form.useForm();
const [selectSiderTabs, setSelectSiderTabs] = useState('');
const { data: glmToken } = useRequest(GetChatGLMToken);
const { data: promptList, loading: promptLoading } = useRequest(GetPromptList);
const [answer, setAnswer] = useState('');
const [loading, setLoading] = useState(true);
const messageHistory = useRef<IHistory[]>([]);
const { sendMessage } = useWebSocket('wss://glm-api.baibaomen.com/ws', {
onMessage: (event) => {
const text = event.data;
console.log(text);
if (text == '{{BBMCPLT}}') {
setLoading(false);
} else {
......@@ -251,7 +254,7 @@ const Chat: React.FC = () => {
) : (
<div className={classNames(isMobile && styles.mobileContent)}>
<Item name="firstInput">
<ChatFirstContent />
<ChatFirstContent list={promptList?.items || []} />
</Item>
</div>
)}
......
......@@ -32,6 +32,10 @@ export function loginChatGLM(options: ILoginParams) {
});
}
export interface IPromptWord {
title: string;
content: string;
}
export function GetChatGLMToken(): Promise<string> {
return request('https://glm-mangement-api.baibaomen.com/user/token', {
method: 'POST',
......@@ -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];
interface ITalkParams {
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