Skip to content

Commit

Permalink
feat(tool): add execute options (#35)
Browse files Browse the repository at this point in the history
* fix(tool/generate-text): add reference

* feat(tool): add execute options
  • Loading branch information
kwaa authored Jan 22, 2025
1 parent 796154b commit 210f2c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/generate-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const rawGenerateText: RawGenerateText = async (options: GenerateTextOptions) =>
} of message.tool_calls) {
const tool = (options.tools as Tool[]).find(tool => tool.function.name === toolName)!
const parsedArgs = JSON.parse(toolArgs) as Record<string, unknown>
const result = await tool.execute(parsedArgs)
const result = await tool.execute(parsedArgs, { abortSignal: options.abortSignal, messages, toolCallId })

toolCalls.push({
args: toolArgs,
Expand Down
10 changes: 9 additions & 1 deletion packages/shared-chat/src/types/tool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Message } from './message'

export interface Tool {
execute: (input: unknown) => Promise<string> | string
execute: (input: unknown, options: ToolExecuteOptions) => Promise<string> | string
function: {
description?: string
name: string
Expand All @@ -8,3 +10,9 @@ export interface Tool {
}
type: 'function'
}

interface ToolExecuteOptions {
abortSignal?: AbortSignal
messages: Message[]
toolCallId: string
}
2 changes: 2 additions & 0 deletions packages/tool/src/generate-text.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="@xsai/generate-text" />

import type { Schema } from '@typeschema/main'

import type { ToolResult } from '.'
Expand Down

0 comments on commit 210f2c4

Please sign in to comment.