Skip to content
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

feat(tool): add execute options #35

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/generate-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

export interface StepResult {
text?: string
// TODO: step type

Check warning on line 46 in packages/generate-text/src/index.ts

View workflow job for this annotation

GitHub Actions / check

Complete the task associated to this "TODO" comment
// type: 'continue' | 'initial' | 'tool-result'
toolCalls: ToolCall[]
toolResults: ToolResult[]
Expand Down Expand Up @@ -117,7 +117,7 @@
} 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
Loading