openai

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToMatrix

func ConvertToMatrix(response *CreateEmbeddingResponse) [][]float32

Types

type CreateEmbeddingRequest

type CreateEmbeddingRequest struct {
	Model      string `json:"model"`
	User       string `json:"user"`
	Input      *Input `json:"input"`
	Dimensions *int   `json:"dimensions,omitempty"`
}

func (*CreateEmbeddingRequest) JSON

func (c *CreateEmbeddingRequest) JSON() (string, error)

func (*CreateEmbeddingRequest) String

func (c *CreateEmbeddingRequest) String() string

type CreateEmbeddingResponse

type CreateEmbeddingResponse struct {
	Object string          `json:"object"`
	Data   []EmbeddingData `json:"data"`
	Model  string          `json:"model"`
	Usage  Usage           `json:"usage"`
}

func (*CreateEmbeddingResponse) String

func (c *CreateEmbeddingResponse) String() string

type EmbeddingData

type EmbeddingData struct {
	Object    string    `json:"object"`
	Index     int       `json:"index"`
	Embedding []float32 `json:"embedding"`
}

type EmbeddingModel

type EmbeddingModel string
const (
	ModelContextVar                     = "model"
	DimensionsContextVar                = "dimensions"
	TextEmbeddingAda002  EmbeddingModel = "text-embedding-ada-002"
	TextEmbedding3Small  EmbeddingModel = "text-embedding-3-small"
	TextEmbedding3Large  EmbeddingModel = "text-embedding-3-large"
)

type Input

type Input struct {
	Text                 string   `json:"-"`
	Texts                []string `json:"-"`
	Integers             []int    `json:"-"`
	ListOfListOfIntegers [][]int  `json:"-"`
}

func (*Input) MarshalJSON

func (i *Input) MarshalJSON() ([]byte, error)

type OpenAIClient

type OpenAIClient struct {
	BaseURL    string
	APIKey     string
	OrgID      string
	Client     *http.Client
	Model      string
	Dimensions *int
	User       string
}

func NewOpenAIClient

func NewOpenAIClient(apiKey string, opts ...Option) (*OpenAIClient, error)

func (*OpenAIClient) CreateEmbedding

type OpenAIEmbeddingFunction

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

func NewOpenAIEmbeddingFunction

func NewOpenAIEmbeddingFunction(apiKey string, opts ...Option) (*OpenAIEmbeddingFunction, error)

func (*OpenAIEmbeddingFunction) EmbedDocuments

func (e *OpenAIEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]embeddings.Embedding, error)

func (*OpenAIEmbeddingFunction) EmbedQuery

func (e *OpenAIEmbeddingFunction) EmbedQuery(ctx context.Context, document string) (embeddings.Embedding, error)

type Option

type Option func(c *OpenAIClient) error

Option is a function type that can be used to modify the client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithDimensions

func WithDimensions(dimensions int) Option

func WithModel

func WithModel(model EmbeddingModel) Option

WithModel is an option for setting the model to use. Must be one of: text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large

func WithOpenAIOrganizationID

func WithOpenAIOrganizationID(orgID string) Option

WithOpenAIOrganizationID is an option for setting the OpenAI org id.

func WithOpenAIUser added in v0.2.3

func WithOpenAIUser(user string) Option

WithOpenAIUser is an option for setting the OpenAI user. The user is passed with every request to OpenAI. It serves for auditing purposes. If not set the user defaults to ChromaGo client.

type Usage

type Usage struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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