-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: Add tool calling component #4830
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
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,14 @@ | ||
| <template> | ||
| <component :is="kw[content.type]" :content="content"></component> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import SimpleToolCalls from './simple-tool-calls/index.vue' | ||
| import { type ToolCalls } from '@/components/markdown/tool-calls-render/index' | ||
| defineProps<{ | ||
| content: ToolCalls | ||
| }>() | ||
| const kw: any = { | ||
| 'simple-tool-calls': SimpleToolCalls, | ||
| } | ||
| </script> | ||
| <style lang="scss" scoped></style> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <template> | ||
| <el-card> | ||
| {{ content.content.input }} | ||
| </el-card> | ||
| <el-card> | ||
| {{ content.content.output }} | ||
| </el-card> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import { type ToolCalls } from '@/components/markdown/tool-calls-render/index' | ||
| defineProps<{ | ||
| content: ToolCalls | ||
| }>() | ||
| </script> | ||
| <style lang="scss" scoped></style> | ||
|
Contributor
Author
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. The provided Vue.js component looks mostly clean and follows best practices. However, there are a few minor things that can be improved:
Here's the updated code with these improvements incorporated: <template>
<div class="card-container">
<el-card v-for="(item, index) in content" :key="index">
<template #header>{{ item.title }}</template>
{{ item.content }}
</el-card>
</div>
</template>
<script setup lang="ts">
import { type ToolCall, type ToolCalls } from '@/components/markdown/tool-calls-render/index';
import { ref } from 'vue';
const toolCalls = ref<ToolCall[]>([
{
title: "Input:",
content: "{input}",
},
{
title: "Output:",
content: "{output}",
// Add more items as needed
]);
// You can define other props or data here...
</script>
<style scoped lang="scss">
.card-container {
display: flex;
gap: 16px;
.el-card {
width: calc(45% - 16px);
}
}
</style>Key Changes:
These changes should make the template more dynamic and user friendly while maintaining proper TypeScript typing. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export interface ToolCalls { | ||
| type: string | ||
| icon?: string | ||
| title: string | ||
| content: any | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <template> | ||
| <el-collapse> | ||
| <el-collapse-item title="Consistency"> | ||
| <template #title> | ||
| <div class="flex" style="flex-wrap: nowrap; align-items: center"> | ||
| <el-avatar class="avatar-gradient mr-8" style="height: 20px; width: 20px" shape="square"> | ||
| <img :src="toolCallsContent.icon || defaultIcon" /> </el-avatar | ||
| >工具执行 | ||
| </div> | ||
| </template> | ||
| <Content :content="toolCallsContent"></Content> | ||
| </el-collapse-item> | ||
| </el-collapse> | ||
| </template> | ||
| <script lang="ts" setup> | ||
| import Content from './content/index.vue' | ||
| import { ref, computed } from 'vue' | ||
| import { type ToolCalls } from './index' | ||
| import defaultIcon from '@/assets/workflow/icon_robot.svg' | ||
| const props = defineProps<{ content?: string }>() | ||
|
|
||
| const toolCallsContent = computed<ToolCalls>(() => { | ||
| try { | ||
| return JSON.parse(props.content ? props.content : '{}') | ||
| } catch (error) { | ||
| return { type: 'simple-tool-calls', icon: '', title: '', content: {} } | ||
| } | ||
| }) | ||
| </script> | ||
| <style lang="scss" scoped></style> | ||
|
Contributor
Author
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. The @@ -7,4 +7,5 @@
import { type ToolCalls } from './index'
import defaultIcon from '@/assets/workflow/icon_robot.svg'
-import props from<{ content?: string }>()
+const props = defineProps<{
+ content?: string
+}>()This should fix an issue with TypeScript's syntax highlighting when editing this code snippet. In terms of readability and clarity:
If you have more specific optimizations or improvements in mind, feel free to share them! |
||
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.
The provided Vue component template appears to be valid and functional. However, here are a few minor improvements or optimizations you might consider:
Type Annotations: Ensure that the
propsdefinition is properly typed with TypeScript. Currently,content.typeis expected to be of a string type (as specified inToolCalls), but TypeScript does not enforce this. Adding an explicit return type can improve clarity.Optional Prop Types: If it's possible that
content.typecould be undefined or null, you should define optional types.Conditional Rendering: Consider adding some conditional rendering if necessary to handle different types gracefully, especially if there are more components you expect to render.
Use of
v-bind: The colon:is often used for data binding, and while<component>allows you to bind to dynamic values like strings (:'some-component'), usingv-bindexplicitly is generally recommended for clarity.Here's the revised code with these considerations:
In this adjusted version:
getComponentis used to ensure we only attempt to use known keys.contentprop is implied by defaulting its value to{}.