Skip to content

Commit

Permalink
feat(ai): add output apply
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed May 2, 2023
1 parent 060d07a commit 00c45d3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
54 changes: 37 additions & 17 deletions client/web/plugins/com.msgbyte.ai-assistant/src/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
LoadingSpinner,
useChatInputActionContext,
Tag,
Button,
Divider,
} from '@capital/component';
import axios from 'axios';
import styled from 'styled-components';
Expand Down Expand Up @@ -40,7 +42,7 @@ const ActionButton = styled.div`
export const AssistantPopover: React.FC<{
onCompleted: () => void;
}> = React.memo((props) => {
const { message } = useChatInputActionContext();
const { message, setMessage } = useChatInputActionContext();
const [{ loading, value }, handleCallAI] = useAsyncRequest(
async (question: string) => {
// TODO: wait for replace
Expand All @@ -63,25 +65,43 @@ export const AssistantPopover: React.FC<{

return (
<Root>
<Tip>{Translate.helpMeTo}</Tip>

<div>
{typeof value === 'object' &&
(value.result ? (
<div>
<div>{value.answer}</div>
<Tag color="green">
{Translate.usage}: {value.usage}ms
</Tag>
</div>
) : (
<div>
<div>{Translate.serviceBusy}</div>
<Tag color="red">{Translate.callError}</Tag>
</div>
))}
{typeof value === 'object' && (
<>
{value.result ? (
<div>
<div>{value.answer}</div>
<div>
<Tag color="green">
{Translate.usage}: {value.usage}ms
</Tag>

<Button
size="small"
type="primary"
onClick={() => {
setMessage(value.answer);
props.onCompleted();
}}
>
{Translate.apply}
</Button>
</div>
</div>
) : (
<div>
<div>{Translate.serviceBusy}</div>
<Tag color="red">{Translate.callError}</Tag>
</div>
)}

<Divider />
</>
)}
</div>

<Tip>{Translate.helpMeTo}</Tip>

{typeof message === 'string' && message.length > 0 && (
<>
<ActionButton
Expand Down
4 changes: 4 additions & 0 deletions client/web/plugins/com.msgbyte.ai-assistant/src/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ export const Translate = {
'zh-CN': '调用失败',
'en-US': 'Call Error',
}),
apply: localTrans({
'zh-CN': '应用',
'en-US': 'Apply',
}),
};

0 comments on commit 00c45d3

Please sign in to comment.