ollama

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// BaseURL is Ollama HTTP API embeddings base URL.
	BaseURL = "http://localhost:11434/api"
)

Variables

This section is empty.

Functions

func NewEmbedder

func NewEmbedder(opts ...Option) embeddings.Embedder[*EmbeddingRequest]

NewEmbedder creates a client that implements embeddings.Embedder

Types

type APIError

type APIError struct {
	ErrorMessage string `json:"error"`
}

APIError is Ollama API error.

func (APIError) Error

func (e APIError) Error() string

Error implements errors interface.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an OpenAI HTTP API client.

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new Ollama HTTP API client and returns it. You can override the default options via the client methods.

func (*Client) Embed

func (c *Client) Embed(ctx context.Context, embReq *EmbeddingRequest) ([]*embeddings.Embedding, error)

Embed returns embeddings for every object in EmbeddingRequest.

type EmbedddingResponse

type EmbedddingResponse struct {
	Embedding []float64 `json:"embedding"`
}

EmbedddingResponse received from API.

func (*EmbedddingResponse) ToEmbeddings

func (e *EmbedddingResponse) ToEmbeddings() ([]*embeddings.Embedding, error)

ToEmbeddings converts the API response, into a slice of embeddings and returns it.

type EmbeddingRequest

type EmbeddingRequest struct {
	Prompt any    `json:"prompt"`
	Model  string `json:"model"`
}

EmbeddingRequest is serialized and sent to the API server.

type Option

type Option func(*Options)

Option is functional option.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient

func WithHTTPClient(httpClient *client.HTTP) Option

WithVersion sets the API version. WithHTTPClient sets the HTTP client.

type Options

type Options struct {
	BaseURL    string
	HTTPClient *client.HTTP
}

Jump to

Keyboard shortcuts

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