feat(ai): add output apply

pull/90/head
moonrailgun 2 years ago
parent 060d07ae8e
commit 00c45d3050

@ -5,6 +5,8 @@ import {
LoadingSpinner, LoadingSpinner,
useChatInputActionContext, useChatInputActionContext,
Tag, Tag,
Button,
Divider,
} from '@capital/component'; } from '@capital/component';
import axios from 'axios'; import axios from 'axios';
import styled from 'styled-components'; import styled from 'styled-components';
@ -40,7 +42,7 @@ const ActionButton = styled.div`
export const AssistantPopover: React.FC<{ export const AssistantPopover: React.FC<{
onCompleted: () => void; onCompleted: () => void;
}> = React.memo((props) => { }> = React.memo((props) => {
const { message } = useChatInputActionContext(); const { message, setMessage } = useChatInputActionContext();
const [{ loading, value }, handleCallAI] = useAsyncRequest( const [{ loading, value }, handleCallAI] = useAsyncRequest(
async (question: string) => { async (question: string) => {
// TODO: wait for replace // TODO: wait for replace
@ -63,25 +65,43 @@ export const AssistantPopover: React.FC<{
return ( return (
<Root> <Root>
<Tip>{Translate.helpMeTo}</Tip>
<div> <div>
{typeof value === 'object' && {typeof value === 'object' && (
(value.result ? ( <>
{value.result ? (
<div> <div>
<div>{value.answer}</div> <div>{value.answer}</div>
<div>
<Tag color="green"> <Tag color="green">
{Translate.usage}: {value.usage}ms {Translate.usage}: {value.usage}ms
</Tag> </Tag>
<Button
size="small"
type="primary"
onClick={() => {
setMessage(value.answer);
props.onCompleted();
}}
>
{Translate.apply}
</Button>
</div>
</div> </div>
) : ( ) : (
<div> <div>
<div>{Translate.serviceBusy}</div> <div>{Translate.serviceBusy}</div>
<Tag color="red">{Translate.callError}</Tag> <Tag color="red">{Translate.callError}</Tag>
</div> </div>
))} )}
<Divider />
</>
)}
</div> </div>
<Tip>{Translate.helpMeTo}</Tip>
{typeof message === 'string' && message.length > 0 && ( {typeof message === 'string' && message.length > 0 && (
<> <>
<ActionButton <ActionButton

@ -41,4 +41,8 @@ export const Translate = {
'zh-CN': '调用失败', 'zh-CN': '调用失败',
'en-US': 'Call Error', 'en-US': 'Call Error',
}), }),
apply: localTrans({
'zh-CN': '应用',
'en-US': 'Apply',
}),
}; };

Loading…
Cancel
Save