llm

package
v0.2.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Model   string  `json:"model"`
	Message Message `json:"message"` // For Chat Completion
	Done    bool    `json:"done"`

	CreatedAt          time.Time `json:"created_at"`
	TotalDuration      int64     `json:"total_duration"`
	LoadDuration       int       `json:"load_duration"`
	PromptEvalCount    int       `json:"prompt_eval_count"`
	PromptEvalDuration int       `json:"prompt_eval_duration"`
	EvalCount          int       `json:"eval_count"`
	EvalDuration       int64     `json:"eval_duration"`
}

func (*Answer) ToJsonString added in v0.1.0

func (answer *Answer) ToJsonString() string

type Choice added in v0.1.7

type Choice struct {
	Index        int           `json:"index,omitempty"`
	Message      OpenAIMessage `json:"message,omitempty"`
	Logprobs     *string       `json:"logprobs,omitempty"` // Assuming logprobs can be null
	FinishReason string        `json:"finish_reason,omitempty"`
	Delta        Delta         `json:"delta,omitempty"`
}

type Delta added in v0.1.7

type Delta struct {
	Content string `json:"content,omitempty"`
}

type Details added in v0.1.9

type Details struct {
	Format            string   `json:"format"`
	Family            string   `json:"family"`
	Families          []string `json:"families"`
	ParameterSize     string   `json:"parameter_size"`
	QuantizationLevel string   `json:"quantization_level"`
}

type Embedding added in v0.1.8

type Embedding struct {
	Object    string    `json:"object"`
	Index     int       `json:"index"`
	Embedding []float64 `json:"embedding"`
}

type Function added in v0.0.6

type Function struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Parameters  Parameters `json:"parameters"`
}

type FunctionTool added in v0.1.6

type FunctionTool struct {
	Name      string                 `json:"name"`
	Arguments map[string]interface{} `json:"arguments"` // used for the ToolCalls list
}

func (*FunctionTool) ToJSONString added in v0.1.6

func (ft *FunctionTool) ToJSONString() (string, error)

type GenAnswer added in v0.1.7

type GenAnswer struct {
	Model    string `json:"model"`
	Done     bool   `json:"done"`
	Response string `json:"response"` // For "Simple" Completion
	Context  []int  `json:"context"`  // For "Simple" Completion

	CreatedAt          time.Time `json:"created_at"`
	TotalDuration      int64     `json:"total_duration"`
	LoadDuration       int       `json:"load_duration"`
	PromptEvalCount    int       `json:"prompt_eval_count"`
	PromptEvalDuration int       `json:"prompt_eval_duration"`
	EvalCount          int       `json:"eval_count"`
	EvalDuration       int64     `json:"eval_duration"`
}

func (*GenAnswer) ToJsonString added in v0.1.7

func (answer *GenAnswer) ToJsonString() string

type GenQuery added in v0.1.7

type GenQuery struct {
	Model   string  `json:"model"`
	Options Options `json:"options"`
	Stream  bool    `json:"stream"`
	Prompt  string  `json:"prompt"`  // For "Simple" Completion
	Context []int   `json:"context"` // For "Simple" Completion
	//Tools    []Tool    `json:"tools"`
	Suffix string `json:"suffix,omitempty"`

	Format    string `json:"format,omitempty"` // https://github.com/ollama/ollama/blob/main/docs/api.md#request-json-mode
	KeepAlive bool   `json:"keep_alive,omitempty"`
	Raw       bool   `json:"raw,omitempty"`
	System    string `json:"system,omitempty"`
	Template  string `json:"template,omitempty"`

	TokenHeaderName  string
	TokenHeaderValue string
}

https://github.com/ollama/ollama/blob/main/docs/api.md#parameters

func (*GenQuery) ToJsonString added in v0.1.7

func (query *GenQuery) ToJsonString() string

type LLM

type LLM struct {
	Name string `json:"name"`
	Url  string `json:"url"`
}

type Message

type Message struct {
	Role      string `json:"role"`
	Content   string `json:"content"`
	ToolCalls []struct {
		Function FunctionTool //`json:"function"`
		Result   interface{}
		Error    error
	} `json:"tool_calls"`
}

func (*Message) FirstToolCallToJSONString added in v0.1.6

func (m *Message) FirstToolCallToJSONString() (string, error)

func (*Message) ToolCallsToJSONString added in v0.0.7

func (m *Message) ToolCallsToJSONString() (string, error)

type MessageRecord added in v0.0.3

type MessageRecord struct {
	Id      string `json:"id"`
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ModelInfo added in v0.1.9

type ModelInfo struct {
	Name       string    `json:"name"`
	ModifiedAt time.Time `json:"modified_at"`
	Size       int64     `json:"size"`
	Digest     string    `json:"digest"`
	Details    Details   `json:"details"`
}

type ModelInformation added in v0.0.7

type ModelInformation struct {
	Modelfile  string `json:"modelfile"`
	Parameters string `json:"parameters"`
	Template   string `json:"template"`
	Details    struct {
		Format            string   `json:"format"`
		Family            string   `json:"family"`
		Families          []string `json:"families"`
		ParameterSize     string   `json:"parameter_size"`
		QuantizationLevel string   `json:"quantization_level"`
	} `json:"details"`
}

func ShowModelInformation added in v0.0.7

func ShowModelInformation(url, model string) (ModelInformation, int, error)

func ShowModelInformationWithToken added in v0.1.9

func ShowModelInformationWithToken(url, model, tokenHeaderName, tokenHeaderValue string) (ModelInformation, int, error)

type ModelList added in v0.1.9

type ModelList struct {
	Models []ModelInfo `json:"models"`
}

func GetModelsList added in v0.1.9

func GetModelsList(url string) (ModelList, int, error)

func GetModelsListWithToken added in v0.1.9

func GetModelsListWithToken(url, tokenHeaderName, tokenHeaderValue string) (ModelList, int, error)

type OpenAIAnswer added in v0.1.7

type OpenAIAnswer struct {
	ID                string   `json:"id"`
	Object            string   `json:"object"`
	Created           int64    `json:"created"`
	Model             string   `json:"model"`
	SystemFingerprint string   `json:"system_fingerprint"`
	Choices           []Choice `json:"choices"`
	Usage             Usage    `json:"usage"`
}

func (*OpenAIAnswer) ToJsonString added in v0.1.7

func (answer *OpenAIAnswer) ToJsonString() string

type OpenAIEmbeddingResponse added in v0.1.8

type OpenAIEmbeddingResponse struct {
	Object string      `json:"object"`
	Data   []Embedding `json:"data"`
	Model  string      `json:"model"`
	Usage  Usage       `json:"usage"`
}

type OpenAIMessage added in v0.1.7

type OpenAIMessage struct {
	Role    string `json:"role,omitempty"`
	Content string `json:"content,omitempty"`
}

type OpenAIQuery added in v0.1.7

type OpenAIQuery struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`

	//Options  OpenAIOptions `json:"options"`
	//--------------------------------------------
	Stop        []string `json:"stop,omitempty"`
	Seed        int      `json:"seed,omitempty"`
	Temperature float64  `json:"temperature,omitempty"`
	TopP        float64  `json:"top_p,omitempty"`

	PresencePenalty  float64 `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`

	LogitBias       map[string]interface{} `json:"logit_bias,omitempty"`      // OpenAI specific
	Logprobs        bool                   `json:"logprobs,omitempty"`        // OpenAI specific
	TopLogprobs     int                    `json:"top_logprobs,omitempty"`    // OpenAI specific
	MaxTokens       int                    `json:"max_tokens,omitempty"`      // OpenAI specific
	N               int                    `json:"n,omitempty"`               // OpenAI specific
	Response_format map[string]interface{} `json:"response_format,omitempty"` // OpenAI specific
	ServiceTier     string                 `json:"service_tier,omitempty"`    // OpenAI specific

	StreamOptions map[string]interface{} `json:"stream_options,omitempty"` // OpenAI specific

	Stream            bool   `json:"stream"`
	Tools             []Tool `json:"tools,omitempty"`               // not used right now
	ToolChoices       string `json:"tool_choices,omitempty"`        // not used right now
	ParallelToolCalls bool   `json:"parallel_tool_calls,omitempty"` // not used right now
	User              string `json:"user,omitempty"`                // not used right now

	//TokenHeaderName  string
	//TokenHeaderValue string
	Verbose      bool   `json:"-"`
	OpenAIAPIKey string `json:"-"`
}

func (*OpenAIQuery) ToJsonString added in v0.1.7

func (query *OpenAIQuery) ToJsonString() string

type OpenAIQuery4Embedding added in v0.1.8

type OpenAIQuery4Embedding struct {
	Input string `json:"input"`
	Model string `json:"model"`

	OpenAIAPIKey string `json:"-"`
}

https://platform.openai.com/docs/guides/embeddings/what-are-embeddings

type Options

type Options struct {
	NumCtx int `json:"num_ctx,omitempty"`

	RepeatLastN   int      `json:"repeat_last_n"`
	Temperature   float64  `json:"temperature"`
	Seed          int      `json:"seed"`
	RepeatPenalty float64  `json:"repeat_penalty"`
	Stop          []string `json:"stop,omitempty"`

	NumKeep          int     `json:"num_keep"`
	NumPredict       int     `json:"num_predict"`
	TopK             int     `json:"top_k"`
	TopP             float64 `json:"top_p"`
	TFSZ             float64 `json:"tfs_z"`
	TypicalP         float64 `json:"typical_p"`
	PresencePenalty  float64 `json:"presence_penalty"`
	FrequencyPenalty float64 `json:"frequency_penalty"`
	Mirostat         int     `json:"mirostat"`
	MirostatTau      float64 `json:"mirostat_tau"`
	MirostatEta      float64 `json:"mirostat_eta"`
	PenalizeNewline  bool    `json:"penalize_newline"`

	Verbose bool
}

func DefaultOptions added in v0.2.0

func DefaultOptions() Options

func SetOptions added in v0.2.0

func SetOptions(options map[string]interface{}) Options

type Parameters added in v0.0.6

type Parameters struct {
	Type       string              `json:"type"`
	Properties map[string]Property `json:"properties"`
	Required   []string            `json:"required"`
}

type Property added in v0.0.6

type Property struct {
	Type        string `json:"type"`
	Description string `json:"description"`
}

type PullResult added in v0.0.7

type PullResult struct {
	Status string `json:"status"`
}

func PullModel added in v0.0.7

func PullModel(url, model string) (PullResult, int, error)

func PullModelWithToken added in v0.1.9

func PullModelWithToken(url, model, tokenHeaderName, tokenHeaderValue string) (PullResult, int, error)

type Query

type Query struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"` // For Chat Completion
	Options  Options   `json:"options"`
	Stream   bool      `json:"stream"`
	Tools    []Tool    `json:"tools"`

	//Format    string `json:"format"` // https://github.com/ollama/ollama/blob/main/docs/api.md#request-json-mode
	// change the type string to any to accept any type of format in case of structured outputs
	// https://ollama.com/blog/structured-outputs
	Format    any    `json:"format,omitempty"`
	KeepAlive bool   `json:"keep_alive,omitempty"`
	Raw       bool   `json:"raw,omitempty"`
	System    string `json:"system,omitempty"`
	Template  string `json:"template,omitempty"`

	TokenHeaderName  string
	TokenHeaderValue string
}

func (*Query) ToJsonString added in v0.1.0

func (query *Query) ToJsonString() string

type Query4Embedding added in v0.0.1

type Query4Embedding struct {
	Prompt string `json:"prompt"`
	Model  string `json:"model"`

	TokenHeaderName  string
	TokenHeaderValue string
}

type Tool added in v0.0.6

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

type Usage added in v0.1.7

type Usage struct {
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
}

type VectorRecord added in v0.0.1

type VectorRecord struct {
	Id               string    `json:"id"`
	Prompt           string    `json:"prompt"`
	Embedding        []float64 `json:"embedding"`
	CosineSimilarity float64
	Score            float64 // ElasticSearch

	Reference      string                 `json:"reference"`
	SimpleMetaData string                 `json:"metaData"`
	Metadata       map[string]interface{} `json:"metadata"` // additional metadata
	Text           string                 `json:"text"`
}

Jump to

Keyboard shortcuts

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