Documentation
¶
Index ¶
- func InitOpikTracing(ctx context.Context, config *OpikConfig) (*sdktrace.TracerProvider, error)
- func ShutdownOpikTracing(ctx context.Context, tp *sdktrace.TracerProvider) error
- func WrapHTTPClient(client *http.Client) *http.Client
- type Client
- type CompletionOptions
- type Metrics
- type OpenAIClient
- func (c *OpenAIClient) Complete(ctx context.Context, prompt string, opts ...Option) (string, error)
- func (c *OpenAIClient) CompleteStructured(ctx context.Context, prompt string, schema interface{}, opts ...Option) (interface{}, error)
- func (c *OpenAIClient) GenerateEmbedding(ctx context.Context, text string, model string) ([]float64, error)
- func (c *OpenAIClient) GetMetrics() *Metrics
- type OpikConfig
- type Option
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
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 ¶
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) 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 WithSystemMessage ¶
WithSystemMessage sets system message
func WithTemperature ¶
WithTemperature sets the temperature