gen

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float added in v0.6.0

func Float(f float64) *float64

func Int added in v0.6.0

func Int(i int) *int

Types

type FullRequest

type FullRequest struct {
	Request
	Prompts []prompt.Prompt `json:"prompts"`
}

type Gen

type Gen interface {
	Provider() string
	Generator(options ...Option) *Generator
}

type Generator

type Generator struct {
	Prompter Prompter
	Request  Request
}

func (*Generator) AddTools

func (g *Generator) AddTools(tool ...tools.Tool) *Generator

func (*Generator) FrequencyPenalty added in v0.6.0

func (b *Generator) FrequencyPenalty(freq float64) *Generator

func (*Generator) MaxTokens

func (b *Generator) MaxTokens(maxTokens int) *Generator

func (*Generator) Model

func (b *Generator) Model(model Model) *Generator

func (*Generator) Output added in v0.6.0

func (b *Generator) Output(s *schema.JSON) *Generator

func (*Generator) PresencePenalty added in v0.6.0

func (b *Generator) PresencePenalty(prec float64) *Generator

func (*Generator) Prompt

func (b *Generator) Prompt(prompts ...prompt.Prompt) (*Response, error)

func (*Generator) SetConfig

func (b *Generator) SetConfig(config Request) *Generator

func (*Generator) SetToolConfig

func (b *Generator) SetToolConfig(tool tools.Tool) *Generator

func (*Generator) SetTools

func (b *Generator) SetTools(tool ...tools.Tool) *Generator

func (*Generator) StopAt

func (b *Generator) StopAt(stop ...string) *Generator

func (*Generator) System

func (b *Generator) System(prompt string) *Generator

func (*Generator) Temperature

func (b *Generator) Temperature(temperature float64) *Generator

func (*Generator) Tools

func (g *Generator) Tools() []tools.Tool

func (*Generator) TopK added in v0.6.0

func (b *Generator) TopK(topK int) *Generator

func (*Generator) TopP

func (b *Generator) TopP(topP float64) *Generator

func (*Generator) WithContext added in v0.6.0

func (b *Generator) WithContext(ctx context.Context) *Generator

type Model

type Model struct {
	Provider string `json:"provider"`
	Name     string `json:"name"`

	Config map[string]any `json:"config,omitempty"`

	Description string `json:"description,omitempty"`

	InputContentTypes []string `json:"input_content_types,omitempty"`

	InputMaxToken  int `json:"input_max_token,omitempty"`
	OutputMaxToken int `json:"output_max_token,omitempty"`

	SupportTools            bool `json:"support_tools,omitempty"`
	SupportStructuredOutput bool `json:"support_structured_output,omitempty"`
}

func (Model) FQN

func (m Model) FQN() string

func (Model) String

func (m Model) String() string

type Option

type Option func(generator *Generator) *Generator

func WithContext added in v0.6.0

func WithContext(ctx context.Context) Option

func WithFrequencyPenalty added in v0.6.0

func WithFrequencyPenalty(freq float64) Option

func WithMaxTokens

func WithMaxTokens(maxTokens int) Option

func WithModel

func WithModel(model Model) Option

func WithOutput

func WithOutput(s *schema.JSON) Option

func WithPresencePenalty added in v0.6.0

func WithPresencePenalty(presence float64) Option

func WithRequest

func WithRequest(requset Request) Option

func WithStopAt

func WithStopAt(stop ...string) Option

func WithSystem

func WithSystem(prompt string) Option

func WithTemperature

func WithTemperature(temperature float64) Option

func WithToolConfig

func WithToolConfig(tool tools.Tool) Option

func WithTools

func WithTools(tools ...tools.Tool) Option

func WithTopK added in v0.6.0

func WithTopK(topK int) Option

func WithTopP

func WithTopP(topP float64) Option

type Prompter

type Prompter interface {
	SetRequest(request Request)
	Prompt(prompts ...prompt.Prompt) (*Response, error)
}

type Request

type Request struct {
	Context context.Context `json:"-"`

	Model        Model  `json:"model"`
	SystemPrompt string `json:"system_prompt,omitempty"`

	OutputSchema *schema.JSON `json:"output_schema,omitempty"`

	Tools      []tools.Tool `json:"tools,omitempty"`
	ToolConfig *tools.Tool  `json:"tool,omitempty"`

	TopP             *float64 `json:"top_p,omitempty"`
	TopK             *int     `json:"top_k,omitempty"`
	Temperature      *float64 `json:"temperature,omitempty"`
	MaxTokens        *int     `json:"max_tokens,omitempty"`
	FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
	PresencePenalty  *float64 `json:"presence_penalty,omitempty"`
	StopSequences    []string `json:"stop_sequences,omitempty"`
}

type Response

type Response struct {
	Texts []string     `json:"texts,omitempty"`
	Tools []tools.Call `json:"tools,omitempty"`

	Metadata models.Metadata `json:"metadata,omitempty"`
}

func (*Response) AsText

func (r *Response) AsText() (string, error)

func (*Response) AsTools

func (r *Response) AsTools() ([]tools.Call, error)

func (*Response) Eval

func (r *Response) Eval() (err error)

func (*Response) IsText

func (r *Response) IsText() bool

func (*Response) IsTools

func (r *Response) IsTools() bool

func (*Response) Unmarshal

func (r *Response) Unmarshal(ref any) error

Jump to

Keyboard shortcuts

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