cohere

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: 9 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// BaseURL is Cohere HTTP API base URL.
	BaseURL = "https://api.cohere.ai"
	// EmbedAPIVersion is the latest stable embedding API version.
	EmbedAPIVersion = "v1"
)

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 {
	Message string `json:"message"`
}

APIError is Cohere API error.

func (APIError) Error

func (e APIError) Error() string

Error implements errors interface.

type APIVersion

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

APIVersion stores metadata API version.

type Client

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

Client is Cohere HTTP API client.

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new HTTP API client and returns it. By default it reads the Cohere API key from COHERE_API_KEY env var and uses the default Go http.Client for making API requests. 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 {
	Embeddings [][]float64 `json:"embeddings"`
	Meta       *Meta       `json:"meta,omitempty"`
}

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 {
	Texts     []string  `json:"texts"`
	Model     Model     `json:"model,omitempty"`
	InputType InputType `json:"input_type"`
	Truncate  Truncate  `json:"truncate,omitempty"`
}

EmbeddingRequest sent to API endpoint.

type InputType

type InputType string

InputType is an embedding input type.

const (
	SearchDocInput      InputType = "search_document"
	SearchQueryInput    InputType = "search_query"
	ClassificationInput InputType = "classification"
	ClusteringInput     InputType = "clustering"
)

func (InputType) String

func (i InputType) String() string

String implements stringer.

type Meta

type Meta struct {
	APIVersion *APIVersion `json:"api_version,omitempty"`
}

Meta stores API response metadata.

type Model

type Model string

Model is an embedding model.

const (
	EnglishV3        Model = "embed-english-v3.0"
	MultiLingV3      Model = "embed-multilingual-v3.0"
	EnglishLightV3   Model = "embed-english-light-v3.0"
	MultiLingLightV3 Model = "embed-multilingual-light-v3.0"
	EnglishV2        Model = "embed-english-v2.0"
	EnglishLightV2   Model = "embed-english-light-v2.0"
	MultiLingV2      Model = "embed-multilingual-v2.0"
)

func (Model) String

func (m Model) String() string

String implements stringer.

type Option

type Option func(*Options)

Option is functional option.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient

func WithHTTPClient(httpClient *client.HTTP) Option

WithHTTPClient sets the HTTP client.

func WithVersion

func WithVersion(version string) Option

WithVersion sets the API version.

type Options

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

Options are client options

type Truncate

type Truncate string

Truncate controls input truncating. It controls how the API handles inputs longer than the maximum token length (recommended: <512)

const (
	StartTrunc Truncate = "START"
	EndTrunc   Truncate = "END"
	NoneTrunc  Truncate = "NONE"
)

func (Truncate) String

func (t Truncate) String() string

String implements stringer.

Jump to

Keyboard shortcuts

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