openai

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enable

func Enable(apiKey, modelName, baseURL, actionName string) sdk.ClientOption

Enable returns a ClientOption that wires the OpenAI provider. usage: client.New(..., openai.Enable("key", "gpt-4o", "", "my_action"))

func Factory

func Factory(opts map[string]any) (sdk.ClientOption, error)

Factory implements the sdk.ProviderFactory interface.

func Init

func Init(g *genkit.Genkit, modelID string, cfg Config) error

Init registers a specific model (e.g., "gpt-4o") into Genkit's global registry. It maps "openai/{modelID}" in Genkit to "{modelID}" in OpenAI API.

Types

type Config

type Config struct {
	APIKey  string
	BaseURL string // Crucial for Ollama/LocalAI/OpenRouter support
}

Config holds connection parameters.

type LLM

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

LLM is an OpenAI-compatible LLM implementation. It wraps the Genkit plugin to provide core.TextGenerator interface.

func NewLLM

func NewLLM(apiKey, baseURL, modelName string) (*LLM, error)

NewLLM creates a new OpenAI LLM client. If baseURL is empty, it defaults to OpenAI's API. If modelName is empty, it defaults to "gpt-3.5-turbo".

func (*LLM) Complete

func (l *LLM) Complete(ctx context.Context, prompt string) (string, error)

Complete generates text from a prompt.

func (*LLM) Generate

func (l *LLM) Generate(ctx context.Context, prompt string, opts ...core.GenerateOption) (*core.LLMResponse, error)

Generate generates text with options.

func (*LLM) Stream

func (l *LLM) Stream(ctx context.Context, prompt string) (<-chan core.StreamChunk, error)

Stream generates a stream of text.

type OpenAIEmbedder

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

OpenAIEmbedder implements core.Embedder using OpenAI's embedding API.

func NewEmbedder

func NewEmbedder(apiKey, baseURL, modelName string) (*OpenAIEmbedder, error)

NewEmbedder creates a new embedder using OpenAI. Default model: "text-embedding-3-small" (1536 dimensions) Supported models: "text-embedding-3-small", "text-embedding-3-large", "text-embedding-ada-002"

func (*OpenAIEmbedder) Dimension

func (e *OpenAIEmbedder) Dimension() int

Dimension returns the vector size for the configured model. Known models as of 2025-05:

text-embedding-3-small  → 1536
text-embedding-3-large  → 3072
text-embedding-ada-002  → 1536

Returns 0 for unknown models so callers can fail explicitly rather than silently mismatching dimensions.

func (*OpenAIEmbedder) Embed

func (e *OpenAIEmbedder) Embed(ctx context.Context, text string) ([]float32, error)

Embed generates a vector for a single text string.

func (*OpenAIEmbedder) EmbedBatch

func (e *OpenAIEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

EmbedBatch generates vectors for multiple strings.

Jump to

Keyboard shortcuts

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