-
Notifications
You must be signed in to change notification settings - Fork 96
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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 }); | ||||||
|
||||||
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} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the content prop usage. The - content={answerContent}
+ content={answerContent.value} 📝 Committable suggestion
Suggested change
|
||||||
messageRender={renderMarkdown} | ||||||
/> | ||||||
</Space> | ||||||
} | ||||||
/> | ||||||
</Space> | ||||||
); | ||||||
}) | ||||||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.📝 Committable suggestion