Documentation
¶
Index ¶
- func CosenoSimilarity(vector1, vector2 []float64) float64
- type ChatOption
- type ChatOuput
- type FormatProperty
- type Gollama
- func (c *Gollama) Chat(ctx context.Context, prompt string, options ...ChatOption) (*ChatOuput, error)
- func (c *Gollama) Embedding(ctx context.Context, prompt string) ([]float64, error)
- func (c *Gollama) GetDetails(ctx context.Context, model ...string) ([]ModelDetails, error)
- func (c *Gollama) GetModels(ctx context.Context) ([]string, error)
- func (c *Gollama) HasModel(ctx context.Context, model string) (bool, error)
- func (c *Gollama) ListModels(ctx context.Context) ([]ModelInfo, error)
- func (c *Gollama) ModelSize(ctx context.Context, model string) (int, error)
- func (c *Gollama) PullIfMissing(ctx context.Context, model ...string) error
- func (c *Gollama) PullModel(ctx context.Context, model string) error
- func (c *Gollama) SetContextLength(contextLength int64) *Gollama
- func (c *Gollama) SetHTTPTimeout(timeout time.Duration) *Gollama
- func (c *Gollama) SetModel(model string)
- func (c *Gollama) SetRandomSeed() *Gollama
- func (c *Gollama) SetSeed(seed int) *Gollama
- func (c *Gollama) SetSystemPrompt(prompt string) *Gollama
- func (c *Gollama) SetTemperature(temperature float64) *Gollama
- func (c *Gollama) SetTopK(topK int) *Gollama
- func (c *Gollama) SetTopP(topP float64) *Gollama
- func (c *Gollama) Version(ctx context.Context) (string, error)
- type ItemProperty
- type ModelDetails
- type ModelInfo
- type PromptImage
- type StructuredFormat
- type Tool
- type ToolCall
- type ToolCallFunction
- type ToolFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CosenoSimilarity ¶ added in v1.0.13
Types ¶
type ChatOption ¶ added in v1.0.9
type ChatOption interface{}
type ChatOuput ¶ added in v1.0.9
type ChatOuput struct { Role string `json:"role"` Content string `json:"content"` ToolCalls []ToolCall `json:"tool_calls"` PromptTokens int `json:"prompt_tokens"` ResponseTokens int `json:"response_tokens"` }
func (ChatOuput) DecodeContent ¶ added in v1.0.18
type FormatProperty ¶ added in v1.0.10
type FormatProperty struct { Type string `json:"type"` Description string `json:"description,omitempty"` Enum []string `json:"enum,omitempty"` Items ItemProperty `json:"items,omitempty"` }
type Gollama ¶
type Gollama struct { ServerAddr string ModelName string SeedOrNegative int TemperatureIfNegativeSeed float64 TopK int TopP float64 PullTimeout time.Duration HTTPTimeout time.Duration TrimSpace bool Verbose bool ContextLength int64 SystemPrompt string }
func New ¶
New is a constructor for Gollama that takes a model name as an argument. Any unset fields will be populated with default values.
This is useful for cases where you want to create a Gollama with a specific model name, but don't want to specify every single field.
If the provided model name is empty, the default model name will be used.
The following environment variables can be set to override the default values of the fields:
OLLAMA_HOST: the address of the Ollama server OLLAMA_MODEL: the model name OLLAMA_VERBOSE: whether to print debug information
The returned Gollama can be used to call other methods on the Ollama API.
func NewWithConfig ¶
NewWithConfig is a constructor for Gollama that takes a pre-populated Gollama as an argument. Any unset fields will be populated with default values.
This is useful for cases where you want to create a Gollama with some custom configuration, but don't want to specify every single field.
func (*Gollama) Chat ¶
func (c *Gollama) Chat(ctx context.Context, prompt string, options ...ChatOption) (*ChatOuput, error)
Chat generates a response to a prompt using the Ollama API.
The first argument is the prompt to generate a response to.
The function takes a variable number of options as arguments. The options are:
- A slice of strings representing the paths to images that should be passed as vision input.
- A slice of Tool objects representing the tools that should be available to the model.
The function returns a pointer to a ChatOuput object, which contains the response to the prompt, as well as some additional information about the response. If an error occurs, the function returns nil and an error.
func (*Gollama) Embedding ¶ added in v1.0.8
Embedding generates a vector embedding for a given string of text using the currently set model. The model must support the "embeddings" capability.
The function will return an error if the model does not support the "embeddings" capability. The function will also return an error if the request fails.
The function returns a slice of floats, representing the vector embedding of the input text.
func (*Gollama) GetDetails ¶ added in v1.0.8
GetDetails retrieves the details of specified models from the server.
The function accepts a variadic parameter of model names. If no model names are provided, it defaults to using the model name set in the Gollama object.
It returns a slice of ModelDetails for each requested model, or an error if the request fails.
func (*Gollama) GetModels ¶ added in v1.0.29
GetModels retrieves a list of available models from the server.
It returns a slice of strings containing model names, or an error if the request fails.
func (*Gollama) HasModel ¶
HasModel checks if a given model is available on the server.
The function will return an error if the request fails.
The function will return false if the model is not found on the server.
func (*Gollama) ListModels ¶
ListModels lists all available models on the server.
The function will return an error if the request fails.
func (*Gollama) ModelSize ¶
ModelSize returns the size of a model on the server.
The function will return an error if the model is not found.
The function will return 0 if the model is not found.
func (*Gollama) PullIfMissing ¶
PullIfMissing pulls a model from the server if it is not available locally.
The function will return an error if the request fails.
The function will return an error if the model is not found on the server.
If no model is specified, the model name set in the Gollama object is used.
func (*Gollama) PullModel ¶
PullModel pulls a model from the server if it is not available locally.
The function will return an error if the request fails.
The function will return an error if the model is not found on the server.
func (*Gollama) SetContextLength ¶
SetContextLength Sets the size of the context window used to generate the next token. (Default: 2048)
func (*Gollama) SetRandomSeed ¶
func (*Gollama) SetSeed ¶
SetSeed Sets the random number seed to use for generation. Setting this to a specific number will make the model generate the same text for the same prompt. (Default: 0)
func (*Gollama) SetSystemPrompt ¶ added in v1.0.7
func (*Gollama) SetTemperature ¶
SetTemperature The temperature of the model. Increasing the temperature will make the model answer more creatively. (Default: 0.8)
func (*Gollama) SetTopK ¶ added in v1.0.28
SetTopK Reduces the probability of generating nonsense. A higher value (e.g. 100) will give more diverse answers, while a lower value (e.g. 10) will be more conservative. (Default: 40)
type ItemProperty ¶ added in v1.0.10
type ItemProperty struct {
Type string `json:"type"`
}
type ModelDetails ¶ added in v1.0.8
type ModelDetails struct { License string `json:"license"` Modelfile string `json:"modelfile"` Parameters string `json:"parameters"` Template string `json:"template"` Details struct { ParentModel string `json:"parent_model"` Format string `json:"format"` Family string `json:"family"` Families []string `json:"families"` ParameterSize string `json:"parameter_size"` QuantizationLevel string `json:"quantization_level"` } `json:"details"` ModelInfo struct { GeneralArchitecture string `json:"general.architecture"` GeneralBasename string `json:"general.basename"` GeneralFileType int `json:"general.file_type"` GeneralFinetune string `json:"general.finetune"` GeneralLanguages []string `json:"general.languages"` GeneralLicense string `json:"general.license"` GeneralParameterCount int64 `json:"general.parameter_count"` GeneralQuantizationVersion int `json:"general.quantization_version"` GeneralSizeLabel string `json:"general.size_label"` GeneralTags []string `json:"general.tags"` GeneralType string `json:"general.type"` LlamaAttentionHeadCount int `json:"llama.attention.head_count"` LlamaAttentionHeadCountKv int `json:"llama.attention.head_count_kv"` LlamaAttentionLayerNormRmsEpsilon float64 `json:"llama.attention.layer_norm_rms_epsilon"` LlamaBlockCount int `json:"llama.block_count"` LlamaContextLength int `json:"llama.context_length"` LlamaEmbeddingLength int `json:"llama.embedding_length"` LlamaFeedForwardLength int `json:"llama.feed_forward_length"` LlamaRopeDimensionCount int `json:"llama.rope.dimension_count"` LlamaRopeFreqBase int `json:"llama.rope.freq_base"` LlamaVocabSize int `json:"llama.vocab_size"` TokenizerGgmlBosTokenID int `json:"tokenizer.ggml.bos_token_id"` TokenizerGgmlEosTokenID int `json:"tokenizer.ggml.eos_token_id"` TokenizerGgmlMerges any `json:"tokenizer.ggml.merges"` TokenizerGgmlModel string `json:"tokenizer.ggml.model"` TokenizerGgmlPre string `json:"tokenizer.ggml.pre"` TokenizerGgmlTokenType any `json:"tokenizer.ggml.token_type"` TokenizerGgmlTokens any `json:"tokenizer.ggml.tokens"` } `json:"model_info"` ModifiedAt string `json:"modified_at"` }
type PromptImage ¶ added in v1.0.10
type PromptImage struct {
Filename string `json:"filename"`
}
type StructuredFormat ¶ added in v1.0.10
type StructuredFormat struct { Type string `json:"type"` Properties map[string]FormatProperty `json:"properties"` Required []string `json:"required,omitempty"` }
func StructToStructuredFormat ¶ added in v1.0.12
func StructToStructuredFormat(s interface{}) StructuredFormat
type Tool ¶ added in v1.0.9
type Tool struct { Type string `json:"type"` Function ToolFunction `json:"function"` }
type ToolCall ¶ added in v1.0.9
type ToolCall struct {
Function ToolCallFunction `json:"function"`
}
type ToolCallFunction ¶ added in v1.0.9
type ToolFunction ¶ added in v1.0.9
type ToolFunction struct { Name string `json:"name"` Description string `json:"description,omitempty"` Parameters StructuredFormat `json:"parameters"` }