ollama

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

ChatMessage represents a message in the chat context.

type Companion

type Companion struct {
	Config       models.Configuration
	SystemRole   models.Message
	Conversation []models.Message
	HttpClient   *http.Client
}

Companion represents the AI companion with its configuration, conversation history, and HTTP client.

func (*Companion) AddMessage

func (companion *Companion) AddMessage(message models.Message)

addMessage adds the given message to the conversation history.

func (*Companion) GetConfig

func (companion *Companion) GetConfig() models.Configuration

GetConfig returns the current configuration of the companion.

func (*Companion) GetConversation

func (companion *Companion) GetConversation() []models.Message

GetConversation returns the current conversation history of the companion.

func (*Companion) GetEnrichmentPrompt

func (companion *Companion) GetEnrichmentPrompt() string

GetEnrichmentPrompt returns the current enrichment prompt of the companion.

func (*Companion) GetHttpClient

func (companion *Companion) GetHttpClient() *http.Client

GetClient returns the current HTTP client of the companion.

func (*Companion) GetModels

func (companion *Companion) GetModels() ([]models.Model, error)

GetModels returns a list of available models from the API.

func (*Companion) GetSummarizationPrompt

func (companion *Companion) GetSummarizationPrompt() string

GetSummarizationPrompt returns the current summarization prompt of the companion.

func (*Companion) GetSystemRole

func (companion *Companion) GetSystemRole() models.Message

GetCurrentSystemRole returns the current system role of the companion.

func (*Companion) HandleStreamResponse

func (companion *Companion) HandleStreamResponse(resp *http.Response, streamType models.StreamType, callback func(m models.Message) error) (models.Message, error)

HandleStreamResponse handles the streaming response from the Ollama API.

func (*Companion) PrepareConversation

func (companion *Companion) PrepareConversation(message models.Message, includeStrategy models.IncludeStrategy) []models.Message

prepareConversation prepares the conversation by appending system role and current conversation messages.

func (*Companion) RunFunction

func (companion *Companion) RunFunction(tool models.Tool, payload models.FunctionPayload) (models.FunctionResponse, error)

RunFunction executes a function with the provided payload.

func (*Companion) SendChatRequest

func (companion *Companion) SendChatRequest(message models.MessageRequest, streaming bool, callback func(m models.Message) error) (models.Message, error)

ProcessUserInput processes the user input by sending it to the API and handling the response.

func (*Companion) SendEmbeddingRequest

func (companion *Companion) SendEmbeddingRequest(embedding models.EmbeddingRequest) (models.EmbeddingResponse, error)

SendEmbeddingRequest sends an embedding request to the server using the provided embedding request object.

func (*Companion) SendGenerateRequest

func (companion *Companion) SendGenerateRequest(message models.MessageRequest, streaming bool, callback func(m models.Message) error) (models.Message, error)

ProcessUserInput processes the user input by sending it to the API and handling the response.

func (*Companion) SendModerationRequest

func (companion *Companion) SendModerationRequest(moderationRequest models.ModerationRequest) (models.ModerationResponse, error)

SendModerationRequest sends a request to the OpenAI API to moderate a given text input.

func (*Companion) SendToolRequest added in v0.3.4

func (companion *Companion) SendToolRequest(message models.MessageRequest) (models.Message, error)

func (*Companion) SetConfig

func (companion *Companion) SetConfig(config models.Configuration)

SetConfig sets a new configuration for the companion.

func (*Companion) SetConversation

func (companion *Companion) SetConversation(conversation []models.Message)

SetConversation sets a new conversation history for the companion.

func (*Companion) SetEnrichmentPrompt

func (companion *Companion) SetEnrichmentPrompt(enrichmentprompt string)

SetEnrichmentPrompt sets a new enrichment prompt for the companion.

func (*Companion) SetHttpClient

func (companion *Companion) SetHttpClient(client *http.Client)

SetClient sets a new HTTP client for the companion.

func (*Companion) SetSummarizationPrompt

func (companion *Companion) SetSummarizationPrompt(summarizationprompt string)

SetSummarizationPrompt sets a new summarization prompt for the companion.

func (*Companion) SetSystemRole

func (companion *Companion) SetSystemRole(prompt string)

SetCurrentSystemRole sets a new system role for the companion.

type CompletionRequest

type CompletionRequest struct {
	Model     string                `json:"model"`
	Messages  []models.Message      `json:"messages,omitempty"`
	Prompt    string                `json:"prompt,omitempty"`
	Suffix    string                `json:"suffix,omitempty"`
	Images    *[]models.Base64Image `json:"images,omitempty"`
	Format    string                `json:"format,omitempty"`
	Options   string                `json:"options,omitempty"`
	System    string                `json:"system,omitempty"`
	Template  string                `json:"template,omitempty"`
	Stream    bool                  `json:"stream"`
	Raw       bool                  `json:"raw,omitempty"`
	KeepAlive int64                 `json:"keep_alive,omitempty"`
	Context   string                `json:"context,omitempty"`
	Tools     []models.Function     `json:"tools,omitempty"`
}

GenerateRequest represents the request structure for the /api/generate endpoint.

type CompletionResponse

type CompletionResponse struct {
	Model              string         `json:"model"`
	CreatedAt          time.Time      `json:"created_at"`
	Done               bool           `json:"done"`
	DoneReason         string         `json:"done_reason,omitempty"`
	Message            models.Message `json:"message,omitempty"`
	Response           string         `json:"response,omitempty"`
	TotalDuration      int64          `json:"total_duration"`
	LoadDuration       int64          `json:"load_duration"`
	PromptEvalCount    int            `json:"prompt_eval_count"`
	PromptEvalDuration int64          `json:"prompt_eval_duration"`
	EvalCount          int            `json:"eval_count"`
	EvalDuration       int64          `json:"eval_duration"`
	// Context is an encoding of the conversation used in this response; this
	// can be sent in the next request to keep a conversational memory.
	Context []int `json:"context,omitempty"`
}

ChatResponse represents the response structure for the /api/chat endpoint.

type CopyModelRequest

type CopyModelRequest struct {
	Source      string `json:"source"`
	Destination string `json:"destination"`
}

CopyModelRequest represents the request structure for the /api/models/copy endpoint.

type CopyModelResponse

type CopyModelResponse struct {
	Message string `json:"message"`
}

CopyModelResponse represents the response structure for the /api/models/copy endpoint.

type CreateModelRequest

type CreateModelRequest struct {
	Model     string `json:"model"`
	Modelfile string `json:"modelfile"`
}

CreateModelRequest represents the request structure for the /api/models/create endpoint.

type CreateModelResponse

type CreateModelResponse struct {
	Message string `json:"message"`
}

CreateModelResponse represents the response structure for the /api/models/create endpoint.

type DeleteModelResponse

type DeleteModelResponse struct {
	Message string `json:"message"`
}

DeleteModelResponse represents the response structure for the /api/models/{model} DELETE endpoint.

type EmbeddingResponse

type EmbeddingResponse struct {
	Model           string      `json:"model"`
	Embeddings      [][]float32 `json:"embeddings"`
	TotalDuration   int64       `json:"total_duration,omitempty"`
	LoadDuration    int64       `json:"load_duration,omitempty"`
	PromptEvalCount int         `json:"prompt_eval_count,omitempty"`
}

EmbeddingsResponse represents the response structure for the /api/embeddings endpoint.

type EmbeddingsRequest

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

EmbeddingsRequest represents the request structure for the /api/embeddings endpoint.

type ListModelsResponse

type ListModelsResponse struct {
	Models []string `json:"models"`
}

ListModelsResponse represents the response structure for the /api/models endpoint.

type ModelInfoResponse

type ModelInfoResponse struct {
	Name    string `json:"name"`
	Details string `json:"details"`
}

ModelInfoResponse represents the response structure for the /api/models/{model} endpoint.

type ModelResponse

type ModelResponse struct {
	Models []models.Model `json:"models"`
}

ModelResponse represents the response structure for the models endpoint.

type PullModelRequest

type PullModelRequest struct {
	Model string `json:"model"`
}

PullModelRequest represents the request structure for the /api/models/pull endpoint.

type PullModelResponse

type PullModelResponse struct {
	Message string `json:"message"`
}

PullModelResponse represents the response structure for the /api/models/pull endpoint.

type PushModelRequest

type PushModelRequest struct {
	Model string `json:"model"`
}

PushModelRequest represents the request structure for the /api/models/push endpoint.

type PushModelResponse

type PushModelResponse struct {
	Message string `json:"message"`
}

PushModelResponse represents the response structure for the /api/models/push endpoint.

type RunningModelsResponse

type RunningModelsResponse struct {
	RunningModels []string `json:"running_models"`
}

RunningModelsResponse represents the response structure for the /api/models/running endpoint.

type VersionResponse

type VersionResponse struct {
	Version string `json:"version"`
}

VersionResponse represents the response structure for the /api/version endpoint.

Jump to

Keyboard shortcuts

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