llm

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 4 Imported by: 7

Documentation

Index

Constants

View Source
const (
	RoleUser  = Role("user")
	RoleModel = Role("model")
	RoleFunc  = Role("function")
)
View Source
const (
	FinishReasonUnknown    = FinishReason("unknown")
	FinishReasonError      = FinishReason("error")
	FinishReasonSafety     = FinishReason("safety")
	FinishReasonRecitation = FinishReason("recitation")
	FinishReasonStop       = FinishReason("stop")
	FinishReasonMaxTokens  = FinishReason("max_tokens")
	FinishReasonToolUse    = FinishReason("tool_use")
)

Variables

View Source
var (
	ErrUnknown         = errors.New("unknown error")
	ErrNoResponse      = errors.New("no response")
	ErrInvalidRequest  = errors.New("invalid request")
	ErrInvalidResponse = errors.New("invalid response")
	ErrAuthentication  = errors.New("authentication error")
	ErrPermission      = errors.New("permission error")
	ErrNotFound        = errors.New("not found")
	ErrRateLimit       = errors.New("rate limit error")
	ErrOverloaded      = errors.New("overloaded")
	ErrInternalServer  = errors.New("internal server error")
)

Functions

This section is empty.

Types

type BlockThreshold

type BlockThreshold uint16
const (
	BlockDefault BlockThreshold = iota
	BlockNone
	BlockLowAndAbove
	BlockMediumAndAbove
	BlockOnlyHigh
	BlockOff
)

type ChatContext

type ChatContext struct {
	Contents []*Content             `json:"contents"`
	Tools    []*FunctionDeclaration `json:"tools"`

	SystemInstruction string `json:"system_instruction"`
}

type Config

type Config struct {
	Temperature     *float32        `json:"temperature,omitempty"`
	TopP            *float32        `json:"top_p,omitempty"`
	TopK            *int            `json:"top_k,omitempty"`
	MaxOutputTokens *int            `json:"max_output_tokens,omitempty"`
	StopSequences   []string        `json:"stop_sequences,omitempty"`
	ThinkingConfig  *ThinkingConfig `json:"thinking_config,omitempty"`

	SystemInstruction     string         `json:"system_instruction,omitempty"`
	SafetyFilterThreshold BlockThreshold `json:"filter_threshold,omitempty"`
}

type Content

type Content struct {
	Role  Role      `json:"role"`
	Parts []Segment `json:"parts"`
}

func TextContent

func TextContent(role Role, text string) *Content

type FileData

type FileData struct {
	MIMEType string `json:"mimeType"`
	FileURI  string `json:"fileUri"`
}

func (*FileData) Segment

func (*FileData) Segment()

func (*FileData) Type

func (*FileData) Type() SegmentType

type FinishReason

type FinishReason string

type FunctionCall

type FunctionCall struct {
	Name string                 `json:"name"`
	ID   string                 `json:"id"`
	Args map[string]interface{} `json:"args"`
}

func (*FunctionCall) Segment

func (*FunctionCall) Segment()

func (*FunctionCall) Type

func (*FunctionCall) Type() SegmentType

type FunctionDeclaration

type FunctionDeclaration struct {
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Schema      *Schema `json:"schema"`
}

type FunctionResponse

type FunctionResponse struct {
	Name    string      `json:"name,omitempty"`
	ID      string      `json:"id,omitempty"`
	Content interface{} `json:"content"`
	IsError bool        `json:"-"`
}

func (*FunctionResponse) Segment

func (*FunctionResponse) Segment()

func (*FunctionResponse) Type

func (*FunctionResponse) Type() SegmentType

type InlineData

type InlineData struct {
	MIMEType string `json:"mimeType"`
	Data     []byte `json:"data"`
}

func (*InlineData) Segment

func (*InlineData) Segment()

func (*InlineData) Type

func (*InlineData) Type() SegmentType

type Model

type Model interface {
	GenerateStream(ctx context.Context, chat *ChatContext, input *Content) *StreamContent
	Close() error
	Name() string
}

type OpenAPIType

type OpenAPIType string
const (
	OpenAPITypeString  OpenAPIType = "string"
	OpenAPITypeNumber  OpenAPIType = "number"
	OpenAPITypeInteger OpenAPIType = "integer"
	OpenAPITypeBoolean OpenAPIType = "boolean"
	OpenAPITypeArray   OpenAPIType = "array"
	OpenAPITypeObject  OpenAPIType = "object"
)

type Role

type Role string

type Schema

type Schema struct {
	Type  OpenAPIType `json:"type"`
	Title string      `json:"title,omitempty"`

	Description string             `json:"description,omitempty"`
	Properties  map[string]*Schema `json:"properties,omitempty"`
	Items       *Schema            `json:"items,omitempty"`
	Required    []string           `json:"required,omitempty"`

	Nullable bool          `json:"nullable,omitempty"`
	Format   string        `json:"format,omitempty"`
	Enum     []interface{} `json:"enum,omitempty"`
	Default  interface{}   `json:"default,omitempty"`
}

type Segment

type Segment interface {
	Segment()
	Type() SegmentType
}

type SegmentType

type SegmentType uint16
const (
	SegmentTypeUnknown          SegmentType = iota // unknown
	SegmentTypeText                                // text
	SegmentTypeInlineData                          // inline_data
	SegmentTypeFileData                            // file_data
	SegmentTypeFunctionCall                        // function_call
	SegmentTypeFunctionResponse                    // function_response
	SegmentTypeThinkingBlock                       // thinking_block
)

func (SegmentType) String

func (i SegmentType) String() string

type StreamContent

type StreamContent struct {
	Err          error        `json:"error"`        // Only Available after Stream channel is closed
	Content      *Content     `json:"content"`      // Only Available after Stream channel is closed
	UsageData    *UsageData   `json:"usageData"`    // Only Available after Stream channel is closed (Note: UsageData is not available for all LLM providers)
	FinishReason FinishReason `json:"finishReason"` // Only Available after Stream channel is closed

	Stream <-chan Segment `json:"-"` // Response Stream
}

func (*StreamContent) Text

func (g *StreamContent) Text() string

Text returns the text content of the segment. Note: This function must be called after the Stream channel is closed.

func (*StreamContent) Wait

func (g *StreamContent) Wait() error

type Text

type Text string

func (Text) Segment

func (Text) Segment()

func (Text) Type

func (t Text) Type() SegmentType

type ThinkingBlock added in v0.2.1

type ThinkingBlock struct {
	Redacted  bool   `json:"redacted,omitempty"`
	Signature string `json:"signature,omitempty"`
	Data      string `json:"content,omitempty"`
}

func (*ThinkingBlock) Segment added in v0.2.1

func (*ThinkingBlock) Segment()

func (*ThinkingBlock) Type added in v0.2.1

func (*ThinkingBlock) Type() SegmentType

type ThinkingConfig

type ThinkingConfig struct {
	IncludeThoughts *bool `json:"include_thoughts,omitempty"`
	ThinkingBudget  *int  `json:"thinking_budget,omitempty"`
}

type UsageData

type UsageData 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