37 lines
870 B
Go
37 lines
870 B
Go
package toolhost
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type RemoteTool struct {
|
|
name string
|
|
description string
|
|
client *Client
|
|
callTimeout time.Duration
|
|
}
|
|
|
|
func NewRemoteTool(name, description string, callTimeout time.Duration, client *Client) *RemoteTool {
|
|
if callTimeout <= 0 {
|
|
callTimeout = 15 * time.Second
|
|
}
|
|
return &RemoteTool{name: name, description: description, client: client, callTimeout: callTimeout}
|
|
}
|
|
|
|
func (t *RemoteTool) Name() string { return t.name }
|
|
|
|
func (t *RemoteTool) Description() string { return t.description }
|
|
|
|
func (t *RemoteTool) Call(ctx context.Context, input string) (string, error) {
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
if _, ok := ctx.Deadline(); !ok {
|
|
var cancel context.CancelFunc
|
|
ctx, cancel = context.WithTimeout(ctx, t.callTimeout)
|
|
defer cancel()
|
|
}
|
|
return t.client.ToolCall(ctx, t.name, input)
|
|
}
|