ollama

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultModel = "smollm"

DefaultModel is the default model for the Ollama API.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for the Ollama API.

View Source
const DefaultURL = "http://localhost:7869/api/chat"

DefaultURL is the default endpoint for the Ollama API.

Variables

View Source
var Transformer = func(e Event) (*prompts.ChatCompletionResponse, error) {
	return &prompts.ChatCompletionResponse{
		Model: e.Model,
		Choices: []prompts.ChatCompletionChoice{
			{
				Message: prompts.Index{
					Role:    prompts.Role(e.Message.Role),
					Content: e.Message.Content,
				},
			},
		},
	}, nil
}

Transformer is a function that transforms an Event into a ChatCompletionResponse.

Functions

func NewDecoder

func NewDecoder(res *http.Response) prompts.Decoder[Event]

NewDecoder creates a new Decoder based on the content type of the response.

Types

type Event

type Event struct {
	Model     string `json:"model"`
	CreatedAt string `json:"created_at"`
	Message   struct {
		Role    string `json:"role"`
		Content string `json:"content"`
		Images  []struct {
			URL  string `json:"url"`
			Size int    `json:"size"`
		} `json:"images"`
	} `json:"message"`
	Done bool `json:"done"`
}

Event is the structure of the event stream response from the Ollama API.

type Ollama

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

Ollama is a chat model.

func New

func New(opts ...Opt) *Ollama

New returns a new Ollama.

func (*Ollama) SendCompletionRequest

func (o *Ollama) SendCompletionRequest(ctx context.Context, req *prompts.ChatCompletionRequest) (*prompts.ChatCompletionResponse, error)

SendCompletionRequest sends a completion request to the Perplexity API.

func (*Ollama) SendStreamCompletionRequest

func (o *Ollama) SendStreamCompletionRequest(ctx context.Context, req *prompts.ChatCompletionRequest, cb ...func(res *prompts.ChatCompletionResponse) error) error

SendStreamCompletionRequest sends a streamed completion request to the Ollama. nolint:gocyclo

type Opt

type Opt func(*Opts)

Opt ...

func WithApiKey

func WithApiKey(apiKey string) Opt

WithApiKey configures the API key.

func WithBaseURL

func WithBaseURL(url string) Opt

WithBaseURL configures the base URL.

func WithClient

func WithClient(client *http.Client) Opt

WithClient configures the HTTP client.

func WithTimeout

func WithTimeout(timeout time.Duration) Opt

WithTimeout configures the timeout.

func WithURL

func WithURL(url string) Opt

WithURL configures the base URL.

type Opts

type Opts struct {
	// BaseURL is the base URL.
	BaseURL string `json:"base_url"`
	// ApiKey is the API key.
	ApiKey string `json:"api_key"`
	// Timeout is the timeout.
	Timeout time.Duration `json:"timeout"`
	// Client is the HTTP client.
	Client *http.Client `json:"-"`
}

Opts ...

func Defaults

func Defaults() *Opts

Defaults is the default options.

Jump to

Keyboard shortcuts

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