Skip to content

docs(bubble): add think demo #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/component/bubble.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ bubble/list-custom

:::

### 深度思考

:::demo 带深度思考。

bubble/with-think

:::

### 使用 GPT-Vis 渲染图表 (no support)

@antv/GPT-Vis 仅支持React。
Expand Down
6 changes: 6 additions & 0 deletions docs/examples-setup/bubble/with-think.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup lang="tsx">
defineOptions({ name: 'AXBubbleWithThinkSetup' });
</script>
<template>
<div>Needs to be supplemented.</div>
</template>
82 changes: 82 additions & 0 deletions docs/examples/bubble/with-think.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<script setup lang="tsx">
import { BulbOutlined, DownOutlined, LoadingOutlined, UpOutlined, UserOutlined } from '@ant-design/icons-vue';
import { Button, Space, Typography } from 'ant-design-vue';
import { Bubble, type BubbleProps } from 'ant-design-x-vue';
import markdownit from 'markdown-it';
import { ref } from 'vue';

defineOptions({ name: 'AXBubbleWithThink' });

const md = markdownit({ html: true, breaks: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security concern: Enabling HTML in markdown-it could lead to XSS vulnerabilities.

The markdown-it configuration has HTML rendering enabled with html: true. This could potentially lead to XSS vulnerabilities if the content contains malicious HTML. Consider disabling HTML or implementing a sanitization strategy if user input will be rendered.

-const md = markdownit({ html: true, breaks: true });
+const md = markdownit({ html: false, breaks: true });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const md = markdownit({ html: true, breaks: true });
const md = markdownit({ html: false, breaks: true });


const think = ref(false);
const collapse = ref(false);
const thinkContent = ref('');
const answerContent = ref('');

const renderMarkdown: BubbleProps['messageRender'] = (content) => (
<Typography>
<div v-html={md.render(content)} />
</Typography>
);

defineRender(() => {
return (
<Space direction="vertical" size="large">
<Button
disabled={think.value}
onClick={() => {
think.value = true
thinkContent.value += '> 好的,用户之前询问过我一些问题,我需要综合考虑,首先...';
answerContent.value = '';
}}
>
开始思考
</Button>
<Bubble
v-if={thinkContent.value}
avatar={{ icon: <UserOutlined /> }}
styles={{ footer: { marginTop: 0 } }}
content={
<Space>
<BulbOutlined />
<span>{think.value ? "思考中..." : "已深度思考"}</span>
<Button
type="text"
size="small"
style={{ background: 'transparent' }}
icon={collapse.value ? <UpOutlined /> : <DownOutlined />}
onClick={() => {
collapse.value = !collapse.value;
}}
/>
</Space>
}
footer={
<Space direction="vertical">
<Bubble
v-show={!collapse.value}
variant="borderless"
typing
content={thinkContent.value}
messageRender={renderMarkdown}
onTypingComplete={() => {
think.value = false;
answerContent.value += '思考完毕,这是我的答案。';
}}
/>
{think.value && <LoadingOutlined />}
<Bubble
variant="borderless"
style={{ marginTop: '-24px' }}
typing
content={answerContent}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the content prop usage.

The content prop is being passed a ref object directly, which may cause unexpected behavior. You should pass the .value property of the ref.

-              content={answerContent}
+              content={answerContent.value}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
content={answerContent}
content={answerContent.value}

messageRender={renderMarkdown}
/>
</Space>
}
/>
</Space>
);
})
</script>