Skip to content

Commit cb00b5f

Browse files
committed
feat: Add tool calling component
1 parent 9f2bfd6 commit cb00b5f

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

ui/src/components/markdown/MdRenderer.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import EchartsRander from './EchartsRander.vue'
3838
import FormRander from './FormRander.vue'
3939
import ReasoningRander from './ReasoningRander.vue'
4040
import IframeRender from './IframeRender.vue'
41-
41+
import ToolCallsRender from './tool-calls-render/index.vue'
4242
config({
4343
markdownItConfig(md) {
4444
md.renderer.rules.image = (tokens, idx, options) => {
@@ -87,6 +87,7 @@ const TAG_PLUGINS: TagPlugin[] = [
8787
{ tag: 'quick_question', type: 'question' },
8888
{ tag: 'html_rander', type: 'html_rander' },
8989
{ tag: 'iframe_render', type: 'iframe_render' },
90+
{ tag: 'tool_calls_render', type: 'tool_calls_render' },
9091
{
9192
tag: 'echarts_rander',
9293
type: 'echarts_rander',
@@ -192,6 +193,7 @@ const componentMap: Record<string, any> = {
192193
echarts_rander: EchartsRander,
193194
form_rander: FormRander,
194195
iframe_render: IframeRender,
196+
tool_calls_render: ToolCallsRender,
195197
}
196198
197199
function getComponentProps(item: RenderNode) {
@@ -208,11 +210,12 @@ function getComponentProps(item: RenderNode) {
208210
209211
case 'echarts_rander':
210212
return { option: item.content }
211-
212213
case 'html_rander':
213214
return { source: item.content }
214215
case 'iframe_render':
215216
return { source: item.content }
217+
case 'tool_calls_render':
218+
return { content: item.content }
216219
217220
default:
218221
return {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<component :is="kw[content.type]" :content="content"></component>
3+
</template>
4+
<script setup lang="ts">
5+
import SimpleToolCalls from './simple-tool-calls/index.vue'
6+
import { type ToolCalls } from '@/components/markdown/tool-calls-render/index'
7+
defineProps<{
8+
content: ToolCalls
9+
}>()
10+
const kw: any = {
11+
'simple-tool-calls': SimpleToolCalls,
12+
}
13+
</script>
14+
<style lang="scss" scoped></style>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<el-card>
3+
{{ content.content.input }}
4+
</el-card>
5+
<el-card>
6+
{{ content.content.output }}
7+
</el-card>
8+
</template>
9+
<script setup lang="ts">
10+
import { type ToolCalls } from '@/components/markdown/tool-calls-render/index'
11+
defineProps<{
12+
content: ToolCalls
13+
}>()
14+
</script>
15+
<style lang="scss" scoped></style>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface ToolCalls {
2+
type: string
3+
icon?: string
4+
title: string
5+
content: any
6+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<el-collapse>
3+
<el-collapse-item title="Consistency">
4+
<template #title>
5+
<div class="flex" style="flex-wrap: nowrap; align-items: center">
6+
<el-avatar class="avatar-gradient mr-8" style="height: 20px; width: 20px" shape="square">
7+
<img :src="toolCallsContent.icon || defaultIcon" /> </el-avatar
8+
>工具执行
9+
</div>
10+
</template>
11+
<Content :content="toolCallsContent"></Content>
12+
</el-collapse-item>
13+
</el-collapse>
14+
</template>
15+
<script lang="ts" setup>
16+
import Content from './content/index.vue'
17+
import { ref, computed } from 'vue'
18+
import { type ToolCalls } from './index'
19+
import defaultIcon from '@/assets/workflow/icon_robot.svg'
20+
const props = defineProps<{ content?: string }>()
21+
22+
const toolCallsContent = computed<ToolCalls>(() => {
23+
try {
24+
return JSON.parse(props.content ? props.content : '{}')
25+
} catch (error) {
26+
return { type: 'simple-tool-calls', icon: '', title: '', content: {} }
27+
}
28+
})
29+
</script>
30+
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)