feat(ai): add message summary

pull/90/head
moonrailgun 2 years ago
parent 00c45d3050
commit 12c8813b68

@ -1,6 +1,11 @@
import React from 'react';
import { Translate } from './translate';
import { useAsyncRequest } from '@capital/common';
import {
useAsyncRequest,
useConverseMessageContext,
getCachedUserInfo,
getMessageTextDecorators,
} from '@capital/common';
import {
LoadingSpinner,
useChatInputActionContext,
@ -14,6 +19,7 @@ import {
improveTextPrompt,
longerTextPrompt,
shorterTextPrompt,
summaryMessagesPrompt,
translateTextPrompt,
} from './prompt';
@ -42,6 +48,7 @@ const ActionButton = styled.div`
export const AssistantPopover: React.FC<{
onCompleted: () => void;
}> = React.memo((props) => {
const { messages } = useConverseMessageContext();
const { message, setMessage } = useChatInputActionContext();
const [{ loading, value }, handleCallAI] = useAsyncRequest(
async (question: string) => {
@ -70,7 +77,7 @@ export const AssistantPopover: React.FC<{
<>
{value.result ? (
<div>
<div>{value.answer}</div>
<pre>{value.answer}</pre>
<div>
<Tag color="green">
{Translate.usage}: {value.usage}ms
@ -127,9 +134,28 @@ export const AssistantPopover: React.FC<{
</>
)}
{/* <ActionButton onClick={() => handleCallAI('')}>
<ActionButton
onClick={async () => {
const plainMessages = (
await Promise.all(
messages.map(
async (item) =>
`${
(
await getCachedUserInfo(item.author)
).nickname
}: ${getMessageTextDecorators().serialize(
item.content ?? ''
)}`
)
)
).join('\n');
handleCallAI(summaryMessagesPrompt + plainMessages);
}}
>
{Translate.summaryMessages}
</ActionButton> */}
</ActionButton>
</Root>
);
});

@ -1,3 +1,5 @@
import { Translate } from './translate';
export const improveTextPrompt =
"You are a text embellisher, you can only embellish the text, don't interpret it. Now i need you embellish it and keep my origin language:";
export const shorterTextPrompt =
@ -6,3 +8,5 @@ export const longerTextPrompt =
"You are a text embellisher, you can only longer the text, don't interpret it. Now i need you longer it and keep my origin language:";
export const translateTextPrompt =
'You are a program responsible for translating text. Your task is to output the specified target language based on the input text. Please do not output any text other than the translation. Target language is english, and if you receive text is english, please translate to chinese(no need pinyin), then its my text:';
export const summaryMessagesPrompt = Translate.prompt.summaryMessages;

@ -45,4 +45,12 @@ export const Translate = {
'zh-CN': '应用',
'en-US': 'Apply',
}),
prompt: {
summaryMessages: localTrans({
'zh-CN':
'你将得到一串聊天记录,希望你能够对这些记录进行摘要。要求简明扼要,以包含列表的大纲形式输出。',
'en-US':
'You will receive a chat record and we hope you can summarize it. Please provide a concise outline format that includes a list.',
}),
},
};

@ -65,6 +65,7 @@ export {
sendMessage,
showMessageTime,
joinArray,
useConverseMessageContext,
} from 'tailchat-shared';
export { navigate } from '@/components/AppRouterApi';

Loading…
Cancel
Save