llm

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitOpikTracing

func InitOpikTracing(ctx context.Context, config *OpikConfig) (*sdktrace.TracerProvider, error)

InitOpikTracing initializes OpenTelemetry tracing with Opik backend

func ShutdownOpikTracing

func ShutdownOpikTracing(ctx context.Context, tp *sdktrace.TracerProvider) error

ShutdownOpikTracing gracefully shuts down the tracer provider

func WrapHTTPClient

func WrapHTTPClient(client *http.Client) *http.Client

WrapHTTPClient wraps an HTTP client with OpenTelemetry instrumentation

Types

type Client

type Client interface {
	// Complete generates a text completion
	Complete(ctx context.Context, prompt string, opts ...Option) (string, error)

	// CompleteStructured generates structured output based on schema
	CompleteStructured(ctx context.Context, prompt string, schema interface{}, opts ...Option) (interface{}, error)

	// GetMetrics returns accumulated metrics
	GetMetrics() *Metrics
}

Client is the interface for LLM clients

type CompletionOptions

type CompletionOptions struct {
	Model       string
	Temperature float64
	MaxTokens   int
	SystemMsg   string
}

CompletionOptions holds options for completions

func DefaultCompletionOptions

func DefaultCompletionOptions() *CompletionOptions

DefaultCompletionOptions returns default options

type Metrics

type Metrics struct {
	Invocations      int
	TotalTokens      int
	PromptTokens     int
	CompletionTokens int
	TotalCost        float64
}

Metrics tracks LLM usage metrics

type OpenAIClient

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

OpenAIClient implements the Client interface using OpenAI

func NewOpenAIClient

func NewOpenAIClient(apiKey string) (*OpenAIClient, error)

NewOpenAIClient creates a new OpenAI client

func NewOpenAIClientWithHTTP

func NewOpenAIClientWithHTTP(apiKey string, httpClient *http.Client) (*OpenAIClient, error)

NewOpenAIClientWithHTTP creates a new OpenAI client with custom HTTP client

func (*OpenAIClient) Complete

func (c *OpenAIClient) Complete(ctx context.Context, prompt string, opts ...Option) (string, error)

Complete generates a text completion

func (*OpenAIClient) CompleteStructured

func (c *OpenAIClient) CompleteStructured(ctx context.Context, prompt string, schema interface{}, opts ...Option) (interface{}, error)

CompleteStructured generates structured output based on schema

func (*OpenAIClient) GenerateEmbedding added in v0.3.11

func (c *OpenAIClient) GenerateEmbedding(ctx context.Context, text string, model string) ([]float64, error)

GenerateEmbedding generates an embedding vector for the given text

func (*OpenAIClient) GetMetrics

func (c *OpenAIClient) GetMetrics() *Metrics

GetMetrics returns accumulated metrics

type OpikConfig

type OpikConfig struct {
	Enabled     bool
	APIKey      string
	Endpoint    string
	Workspace   string
	ProjectName string
}

OpikConfig holds Opik configuration

func LoadOpikConfig

func LoadOpikConfig() *OpikConfig

LoadOpikConfig loads Opik configuration from environment Reads from OPIK_API_KEY, OPIK_WORKSPACE, OPIK_PROJECT_NAME, and OTEL_EXPORTER_OTLP_ENDPOINT

type Option

type Option func(*CompletionOptions)

Option is a function that configures completion options

func WithMaxTokens

func WithMaxTokens(tokens int) Option

WithMaxTokens sets max tokens

func WithModel

func WithModel(model string) Option

WithModel sets the model to use

func WithSystemMessage

func WithSystemMessage(msg string) Option

WithSystemMessage sets system message

func WithTemperature

func WithTemperature(temp float64) Option

WithTemperature sets the temperature

Jump to

Keyboard shortcuts

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