provider

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(ctx context.Context) string

Dir gets the working directory from the context.

func Function

func Function[A any](h FunctionHandler[A], f ToolFunction) error

Function registers a handler of a function tool.

func Init

func Init()

Init indicates that all registrations have been completed. This is a mandatory call before processing of incoming messages can begin.

func Serve

func Serve(ctx context.Context) error

Serve starts reading tool messages from Stdin and calling registered tools that can handle these messages.

Types

type FunctionHandler

type FunctionHandler[A any] func(ctx context.Context, arguments A) (any, error)

type Tool

type Tool struct {
	// The type of the tool. Currently, only `function` is supported.
	Type string `json:"type" validate:"required,oneof=function"`
	// Description of the function.
	Function *ToolFunction `json:"function,omitempty"`
}

type ToolFunction

type ToolFunction struct {
	// The name of the function to be called. Must be a-z, A-Z, 0-9, or
	// contain underscores and dashes, with a maximum length of 64.
	Name string `json:"name" validate:"required"`
	// A description of what the function does, used by the model to
	// choose when and how to call the function.
	Description string `json:"description,omitempty"`
	// The parameters the functions accepts, described as a JSON Schema object.
	Parameters map[string]any `json:"parameters" validate:"required"`
}

type ToolRequest

type ToolRequest struct {
	// Correlation ID of the tool call.
	CallID string `json:"call_id" validate:"required"`
	// The function that the model called.
	Function ToolRequestFunction `json:"function" validate:"required"`
	// Context of the tool call request.
	Context ToolRequestContext `json:"context" validate:"required"`
}

type ToolRequestContext

type ToolRequestContext struct {
	// Full path to the current directory.
	Dir string `json:"dir" validate:"required"`
}

type ToolRequestFunction

type ToolRequestFunction struct {
	// Name of the function to call.
	Name string `json:"name" validate:"required"`
	// Arguments to call the function with, as generated by the model in JSON format.
	Arguments string `json:"arguments" validate:"required"`
}

type ToolResponse

type ToolResponse struct {
	// ID of the tool call that this message is responding to.
	CallID string `json:"call_id" validate:"required"`
	// The contents of the tool response.
	Content any `json:"content"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL