dispatch

package
v0.0.0-...-c3fa2bf Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FunctionInputToTool

func FunctionInputToTool(fi FunctionInput) openai.Tool

Types

type Dispatcher

type Dispatcher[T any] interface {
	// Prompt generates an object of type T from the given prompt.
	Prompt(ctx context.Context, prompt string) (T, error)
	// PromptTemplate generates an object of type T from a given template.
	// The prompt is then a template string that is rendered with the given values.
	PromptTemplate(ctx context.Context, template *template.Template, values interface{}) (T, error)
}

type DummyDispatcher

type DummyDispatcher[T any] struct{}

func NewDummyDispatcher

func NewDummyDispatcher[T any]() *DummyDispatcher[T]

func (*DummyDispatcher[T]) Prompt

func (d *DummyDispatcher[T]) Prompt(ctx context.Context, prompt string) (T, error)

func (*DummyDispatcher[T]) PromptTemplate

func (d *DummyDispatcher[T]) PromptTemplate(ctx context.Context, template *template.Template, values interface{}) (T, error)

type FunctionInput

type FunctionInput struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Parameters  any    `json:"parameters"`
}

func StructToJsonSchema

func StructToJsonSchema(functionName string, functionDescription string, inputStruct interface{}) FunctionInput

func StructToJsonSchemaGeneric

func StructToJsonSchemaGeneric[T any](functionName string, functionDescription string) FunctionInput

type OAITool

type OAITool struct {
	// Type is always "function" for now.
	Type     string        `json:"type"`
	Function FunctionInput `json:"function"`
}

type OpenAIDispatcher

type OpenAIDispatcher[T any] struct {
	*OpenAIDispatcherConfig
	// contains filtered or unexported fields
}

OpenAIDispatcher dispatches to any OpenAI compatible model. For any type T and prompt, it will generate and parse the response into T.

func NewOpenAIDispatcher

func NewOpenAIDispatcher[T any](name, description, systemPrompt string, completer gollum.ChatCompleter, cfg *OpenAIDispatcherConfig) *OpenAIDispatcher[T]

func (*OpenAIDispatcher[T]) Prompt

func (d *OpenAIDispatcher[T]) Prompt(ctx context.Context, prompt string) (T, error)

func (*OpenAIDispatcher[T]) PromptTemplate

func (d *OpenAIDispatcher[T]) PromptTemplate(ctx context.Context, template *template.Template, values interface{}) (T, error)

PromptTemplate generates an object of type T from a given template. This is mostly a convenience wrapper around Prompt.

type OpenAIDispatcherConfig

type OpenAIDispatcherConfig struct {
	Model       *string
	Temperature *float32
	MaxTokens   *int
}

Jump to

Keyboard shortcuts

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