instructor

package
v0.0.0-...-b63ca60 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 14 Imported by: 19

Documentation

Index

Constants

View Source
const (
	DefaultMaxRetries = 3
	DefaultValidator  = false
)
View Source
const WRAPPER_END = `"items": [`

Variables

This section is empty.

Functions

This section is empty.

Types

type Function

type Function struct {
	Type     string             `json:"type"`
	Function FunctionDefinition `json:"function"`
}

type FunctionDefinition

type FunctionDefinition struct {
	Name        string             `json:"name"`
	Description string             `json:"description,omitempty"`
	Parameters  *jsonschema.Schema `json:"parameters"`
}

func ToFunctionSchema

func ToFunctionSchema(tType reflect.Type, tSchema *jsonschema.Schema) []FunctionDefinition

type Instructor

type Instructor interface {
	Provider() Provider
	Mode() Mode
	MaxRetries() int
	Validate() bool
	// contains filtered or unexported methods
}

type InstructorAnthropic

type InstructorAnthropic struct {
	*anthropic.Client
	// contains filtered or unexported fields
}

func FromAnthropic

func FromAnthropic(client *anthropic.Client, opts ...Options) *InstructorAnthropic

func (*InstructorAnthropic) CreateMessages

func (i *InstructorAnthropic) CreateMessages(ctx context.Context, request anthropic.MessagesRequest, responseType any) (response anthropic.MessagesResponse, err error)

func (*InstructorAnthropic) MaxRetries

func (i *InstructorAnthropic) MaxRetries() int

func (*InstructorAnthropic) Mode

func (i *InstructorAnthropic) Mode() string

func (*InstructorAnthropic) Provider

func (i *InstructorAnthropic) Provider() string

func (*InstructorAnthropic) Validate

func (i *InstructorAnthropic) Validate() bool

type InstructorCohere

type InstructorCohere struct {
	*cohere.Client
	// contains filtered or unexported fields
}

func FromCohere

func FromCohere(client *cohere.Client, opts ...Options) *InstructorCohere

func (*InstructorCohere) Chat

func (*InstructorCohere) ChatStream

func (i *InstructorCohere) ChatStream(
	ctx context.Context,
	request *cohere.ChatStreamRequest,
	responseType any,
	opts ...option.RequestOption,
) (<-chan any, error)

func (*InstructorCohere) MaxRetries

func (i *InstructorCohere) MaxRetries() int

func (*InstructorCohere) Mode

func (i *InstructorCohere) Mode() string

func (*InstructorCohere) Provider

func (i *InstructorCohere) Provider() string

func (*InstructorCohere) Validate

func (i *InstructorCohere) Validate() bool

type InstructorOpenAI

type InstructorOpenAI struct {
	*openai.Client
	// contains filtered or unexported fields
}

func FromOpenAI

func FromOpenAI(client *openai.Client, opts ...Options) *InstructorOpenAI

func (*InstructorOpenAI) CreateChatCompletion

func (i *InstructorOpenAI) CreateChatCompletion(
	ctx context.Context,
	request openai.ChatCompletionRequest,
	responseType any,
) (response openai.ChatCompletionResponse, err error)

func (*InstructorOpenAI) CreateChatCompletionStream

func (i *InstructorOpenAI) CreateChatCompletionStream(
	ctx context.Context,
	request openai.ChatCompletionRequest,
	responseType any,
) (stream <-chan any, err error)

func (*InstructorOpenAI) MaxRetries

func (i *InstructorOpenAI) MaxRetries() int

func (*InstructorOpenAI) Mode

func (i *InstructorOpenAI) Mode() Mode

func (*InstructorOpenAI) Provider

func (i *InstructorOpenAI) Provider() Provider

func (*InstructorOpenAI) Validate

func (i *InstructorOpenAI) Validate() bool

type Mode

type Mode = string
const (
	ModeToolCall       Mode = "tool_call_mode"
	ModeToolCallStrict Mode = "tool_call_strict_mode"
	ModeJSON           Mode = "json_mode"
	ModeJSONStrict     Mode = "json_strict_mode"
	ModeJSONSchema     Mode = "json_schema_mode"
	ModeMarkdownJSON   Mode = "markdown_json_mode"
	ModeDefault        Mode = ModeJSONSchema
)

type Options

type Options struct {
	Mode       *Mode
	MaxRetries *int
	// contains filtered or unexported fields
}

func WithMaxRetries

func WithMaxRetries(maxRetries int) Options

func WithMode

func WithMode(mode Mode) Options

func WithValidation

func WithValidation() Options

type Provider

type Provider = string
const (
	ProviderOpenAI    Provider = "OpenAI"
	ProviderAnthropic Provider = "Anthropic"
	ProviderCohere    Provider = "Cohere"
)

type ResponseFormatSchemaWrapper

type ResponseFormatSchemaWrapper struct {
	Type                 string                  `json:"type"`
	Required             []string                `json:"required"`
	AdditionalProperties bool                    `json:"additionalProperties"`
	Properties           *jsonschema.Definitions `json:"properties"`
	Definitions          *jsonschema.Definitions `json:"$defs"`
}

type Schema

type Schema struct {
	*jsonschema.Schema
	String string

	Functions []FunctionDefinition
}

func NewSchema

func NewSchema(t reflect.Type) (*Schema, error)

func (*Schema) NameFromRef

func (s *Schema) NameFromRef() string

type StreamWrapper

type StreamWrapper[T any] struct {
	Items []T `json:"items"`
}

type UsageSum

type UsageSum struct {
	InputTokens  int
	OutputTokens int
	TotalTokens  int
}

Jump to

Keyboard shortcuts

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