Skip to content

Tool

工具调用卡片组件,拦截 <tool> 标签,显示函数名、参数和调用结果。

演示


get_weather
{
  "city": "北京",
  "unit": "celsius"
}
result
晴天,25°C,湿度 45%
<template>
  <div>
    <Input v-model="text" :rows="3" :simulate-text="exampleText" />

    <hr>

    <div>
      <StreamContains :model-value="text" mode="accurate">
        <Tool />
      </StreamContains>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { StreamContains, Tool } from 'stream-ui'
import Input from '../../.comm/Input.vue'

const exampleText = '<tool name="get_weather" args=\'{"city":"北京","unit":"celsius"}\'>晴天,25°C,湿度 45%</tool>'
const text = ref(exampleText)
</script>

使用

vue
<StreamContains :model-value="text" mode="accurate">
  <Tool />
</StreamContains>

示例

html
<tool name="get_weather" args='{"city":"北京"}'>晴天,25°C</tool>

Props

属性类型来源说明
contentstring标签内文本调用结果
isClosedboolean注入是否已完成
attrs.namestring标签属性工具/函数名称
attrs.argsstring标签属性JSON 参数,自动格式化显示
  • 未闭合时显示 running... 状态
  • attrs.args 为 JSON 字符串时自动格式化输出

CLI

bash
npx @huiol/stream-ui add tool

Released under the MIT License.