Documentation
¶
Overview ¶
Package v1 provides the Judgment SDK v1 format for tracing, scoring, and evaluation.
Basic usage:
client, err := v1.NewJudgeval(
"my-project",
v1.WithAPIKey("your-api-key"),
v1.WithOrganizationID("your-org-id"),
)
if err != nil {
log.Fatal(err)
}
tracer, err := client.Tracer.Create(ctx, v1.TracerCreateParams{
Initialize: v1.Bool(true),
})
if err != nil {
log.Fatal(err)
}
defer tracer.Shutdown(ctx)
scorer := client.Scorers.BuiltIn.Faithfulness(v1.FaithfulnessScorerParams{
Threshold: v1.Float(0.8),
})
example := v1.NewExample(v1.ExampleParams{
Name: v1.String("test-example"),
Properties: map[string]interface{}{
"input": "What is AI?",
"output": "Artificial Intelligence...",
},
})
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func Float(v float64) *float64
- func Int(v int) *int
- func NewJudgmentSpanExporter(ctx context.Context, endpoint string, apiClient *api.Client, projectID string) sdktrace.SpanExporter
- func NewJudgmentSpanProcessor(delegate sdktrace.SpanProcessor, lifecycle []sdktrace.SpanProcessor) sdktrace.SpanProcessor
- func NewNoOpSpanExporter() sdktrace.SpanExporter
- func NewNoOpSpanProcessor() sdktrace.SpanProcessor
- func String(v string) *string
- type APIScorerType
- type AnswerCorrectnessScorer
- type AnswerCorrectnessScorerParams
- type AnswerRelevancyScorer
- type AnswerRelevancyScorerParams
- type BaseScorer
- type BaseTracer
- func (b *BaseTracer) AsyncEvaluate(ctx context.Context, scorer BaseScorer, example *Example)
- func (b *BaseTracer) AsyncTraceEvaluate(ctx context.Context, scorer BaseScorer)
- func (b *BaseTracer) EndSpan(span trace.Span)
- func (b *BaseTracer) GetTracer() trace.Tracer
- func (b *BaseTracer) SetAttribute(span trace.Span, key string, value interface{})
- func (b *BaseTracer) SetAttributes(span trace.Span, attrs map[string]interface{})
- func (b *BaseTracer) SetCustomerID(ctx context.Context, customerID string) context.Context
- func (b *BaseTracer) SetGeneralSpan(span trace.Span)
- func (b *BaseTracer) SetInput(span trace.Span, input interface{})
- func (b *BaseTracer) SetLLMSpan(span trace.Span)
- func (b *BaseTracer) SetOutput(span trace.Span, output interface{})
- func (b *BaseTracer) SetSessionID(ctx context.Context, sessionID string) context.Context
- func (b *BaseTracer) SetSpanKind(span trace.Span, kind string)
- func (b *BaseTracer) SetToolSpan(span trace.Span)
- func (b *BaseTracer) Span(ctx context.Context, spanName string) (context.Context, trace.Span)
- func (b *BaseTracer) StartSpan(ctx context.Context, spanName string) (context.Context, trace.Span)
- type BuiltInScorersFactory
- func (f *BuiltInScorersFactory) AnswerCorrectness(params AnswerCorrectnessScorerParams) *AnswerCorrectnessScorer
- func (f *BuiltInScorersFactory) AnswerRelevancy(params AnswerRelevancyScorerParams) *AnswerRelevancyScorer
- func (f *BuiltInScorersFactory) Faithfulness(params FaithfulnessScorerParams) *FaithfulnessScorer
- type CustomScorer
- type CustomScorerFactory
- type CustomScorerParams
- type CustomerIDProcessor
- type Evaluation
- type EvaluationCreateParams
- type EvaluationFactory
- type Example
- func (e *Example) GetCreatedAt() string
- func (e *Example) GetExampleID() string
- func (e *Example) GetName() *string
- func (e *Example) GetProperties() map[string]interface{}
- func (e *Example) GetProperty(key string) interface{}
- func (e *Example) SetName(name string)
- func (e *Example) SetProperty(key string, value interface{}) *Example
- type ExampleParams
- type FaithfulnessScorer
- type FaithfulnessScorerParams
- type FilterTracerFunc
- type Judgeval
- type JudgevalTracerLike
- type JudgmentSpanExporter
- type JudgmentSpanProcessor
- func (p *JudgmentSpanProcessor) ForceFlush(ctx context.Context) error
- func (p *JudgmentSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan)
- func (p *JudgmentSpanProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)
- func (p *JudgmentSpanProcessor) Shutdown(ctx context.Context) error
- type JudgmentTracerProvider
- type JudgmentTracerProviderConfig
- type NoOpSpanExporter
- type NoOpSpanProcessor
- type NoOpTracer
- type Option
- type PromptScorer
- func (s *PromptScorer) AppendToPrompt(addition string)
- func (s *PromptScorer) GetDescription() string
- func (s *PromptScorer) GetModel() string
- func (s *PromptScorer) GetName() string
- func (s *PromptScorer) GetOptions() map[string]float64
- func (s *PromptScorer) GetPrompt() string
- func (s *PromptScorer) GetScorerConfig() *models.ScorerConfig
- func (s *PromptScorer) GetThreshold() float64
- func (s *PromptScorer) SetDescription(description string)
- func (s *PromptScorer) SetModel(model string)
- func (s *PromptScorer) SetOptions(options map[string]float64)
- func (s *PromptScorer) SetPrompt(prompt string)
- func (s *PromptScorer) SetThreshold(threshold float64)
- type PromptScorerFactory
- type ScorerConfig
- type ScorersFactory
- type SerializerFunc
- type SessionIDProcessor
- type Tracer
- type TracerCreateParams
- type TracerFactory
Constants ¶
View Source
const ( AttributeKeysJudgmentSpanKind = "judgment.span_kind" AttributeKeysJudgmentInput = "judgment.input" AttributeKeysJudgmentOutput = "judgment.output" AttributeKeysJudgmentOfflineMode = "judgment.offline_mode" AttributeKeysJudgmentUpdateID = "judgment.update_id" AttributeKeysJudgmentCustomerID = "judgment.customer_id" AttributeKeysJudgmentSessionID = "judgment.session_id" AttributeKeysJudgmentAgentID = "judgment.agent_id" AttributeKeysJudgmentParentAgentID = "judgment.parent_agent_id" AttributeKeysJudgmentAgentClassName = "judgment.agent_class_name" AttributeKeysJudgmentAgentInstanceName = "judgment.agent_instance_name" AttributeKeysJudgmentIsAgentEntryPoint = "judgment.is_agent_entry_point" AttributeKeysJudgmentCumulativeLLMCost = "judgment.cumulative_llm_cost" AttributeKeysJudgmentStateBefore = "judgment.state_before" AttributeKeysJudgmentStateAfter = "judgment.state_after" AttributeKeysPendingTraceEval = "judgment.pending_trace_eval" AttributeKeysGenAIPrompt = "gen_ai.prompt" AttributeKeysGenAICompletion = "gen_ai.completion" AttributeKeysGenAIRequestModel = "gen_ai.request.model" AttributeKeysGenAIResponseModel = "gen_ai.response.model" AttributeKeysGenAIResponseID = "gen_ai.response.id" AttributeKeysGenAISystem = "gen_ai.system" AttributeKeysGenAIUsageInputTokens = "gen_ai.usage.input_tokens" AttributeKeysGenAIUsageOutputTokens = "gen_ai.usage.output_tokens" AttributeKeysGenAIUsageTotalTokens = "gen_ai.usage.total_tokens" AttributeKeysGenAIUsageCacheCreationInputTokens = "gen_ai.usage.cache_creation_input_tokens" AttributeKeysGenAIUsageCacheReadInputTokens = "gen_ai.usage.cache_read_input_tokens" AttributeKeysGenAIRequestTemperature = "gen_ai.request.temperature" AttributeKeysGenAIRequestMaxTokens = "gen_ai.request.max_tokens" AttributeKeysGenAIRequestTopP = "gen_ai.request.top_p" AttributeKeysGenAIRequestTopK = "gen_ai.request.top_k" AttributeKeysGenAIRequestFrequencyPenalty = "gen_ai.request.frequency_penalty" AttributeKeysGenAIRequestPresencePenalty = "gen_ai.request.presence_penalty" AttributeKeysGenAIRequestStopSequences = "gen_ai.request.stop_sequences" AttributeKeysGenAIRequestStream = "gen_ai.request.stream" AttributeKeysGenAIResponseFinishReasons = "gen_ai.response.finish_reasons" )
View Source
const ( ResourceKeysServiceName = "service.name" ResourceKeysTelemetrySDKLanguage = "telemetry.sdk.language" ResourceKeysTelemetrySDKName = "telemetry.sdk.name" ResourceKeysTelemetrySDKVersion = "telemetry.sdk.version" ResourceKeysJudgmentProjectID = "judgment.project_id" )
View Source
const TracerName = "judgeval"
Variables ¶
View Source
var Version = strings.TrimSpace(versionFile)
Functions ¶
func NewJudgmentSpanExporter ¶ added in v0.2.4
func NewJudgmentSpanProcessor ¶ added in v0.2.4
func NewJudgmentSpanProcessor( delegate sdktrace.SpanProcessor, lifecycle []sdktrace.SpanProcessor, ) sdktrace.SpanProcessor
func NewNoOpSpanExporter ¶ added in v0.2.4
func NewNoOpSpanExporter() sdktrace.SpanExporter
func NewNoOpSpanProcessor ¶ added in v0.2.4
func NewNoOpSpanProcessor() sdktrace.SpanProcessor
Types ¶
type APIScorerType ¶
type APIScorerType string
const ( APIScorerTypePromptScorer APIScorerType = "Prompt Scorer" APIScorerTypeTracePromptScorer APIScorerType = "Trace Prompt Scorer" APIScorerTypeFaithfulness APIScorerType = "Faithfulness" APIScorerTypeAnswerRelevancy APIScorerType = "Answer Relevancy" APIScorerTypeAnswerCorrectness APIScorerType = "Answer Correctness" APIScorerTypeCustom APIScorerType = "Custom" )
func (APIScorerType) String ¶
func (t APIScorerType) String() string
type AnswerCorrectnessScorer ¶
type AnswerCorrectnessScorer struct {
// contains filtered or unexported fields
}
func (*AnswerCorrectnessScorer) GetScorerConfig ¶
func (s *AnswerCorrectnessScorer) GetScorerConfig() *models.ScorerConfig
type AnswerRelevancyScorer ¶
type AnswerRelevancyScorer struct {
// contains filtered or unexported fields
}
func (*AnswerRelevancyScorer) GetScorerConfig ¶
func (s *AnswerRelevancyScorer) GetScorerConfig() *models.ScorerConfig
type BaseScorer ¶
type BaseScorer interface {
GetName() string
GetScorerConfig() *models.ScorerConfig
}
type BaseTracer ¶
type BaseTracer struct {
// contains filtered or unexported fields
}
func (*BaseTracer) AsyncEvaluate ¶
func (b *BaseTracer) AsyncEvaluate(ctx context.Context, scorer BaseScorer, example *Example)
func (*BaseTracer) AsyncTraceEvaluate ¶
func (b *BaseTracer) AsyncTraceEvaluate(ctx context.Context, scorer BaseScorer)
func (*BaseTracer) EndSpan ¶
func (b *BaseTracer) EndSpan(span trace.Span)
func (*BaseTracer) GetTracer ¶
func (b *BaseTracer) GetTracer() trace.Tracer
func (*BaseTracer) SetAttribute ¶
func (b *BaseTracer) SetAttribute(span trace.Span, key string, value interface{})
func (*BaseTracer) SetAttributes ¶
func (b *BaseTracer) SetAttributes(span trace.Span, attrs map[string]interface{})
func (*BaseTracer) SetCustomerID ¶ added in v0.3.0
func (*BaseTracer) SetGeneralSpan ¶
func (b *BaseTracer) SetGeneralSpan(span trace.Span)
func (*BaseTracer) SetInput ¶
func (b *BaseTracer) SetInput(span trace.Span, input interface{})
func (*BaseTracer) SetLLMSpan ¶
func (b *BaseTracer) SetLLMSpan(span trace.Span)
func (*BaseTracer) SetOutput ¶
func (b *BaseTracer) SetOutput(span trace.Span, output interface{})
func (*BaseTracer) SetSessionID ¶ added in v0.3.0
func (*BaseTracer) SetSpanKind ¶
func (b *BaseTracer) SetSpanKind(span trace.Span, kind string)
func (*BaseTracer) SetToolSpan ¶
func (b *BaseTracer) SetToolSpan(span trace.Span)
type BuiltInScorersFactory ¶
type BuiltInScorersFactory struct{}
func (*BuiltInScorersFactory) AnswerCorrectness ¶
func (f *BuiltInScorersFactory) AnswerCorrectness(params AnswerCorrectnessScorerParams) *AnswerCorrectnessScorer
func (*BuiltInScorersFactory) AnswerRelevancy ¶
func (f *BuiltInScorersFactory) AnswerRelevancy(params AnswerRelevancyScorerParams) *AnswerRelevancyScorer
func (*BuiltInScorersFactory) Faithfulness ¶
func (f *BuiltInScorersFactory) Faithfulness(params FaithfulnessScorerParams) *FaithfulnessScorer
type CustomScorer ¶
type CustomScorer struct {
// contains filtered or unexported fields
}
func (*CustomScorer) GetBaseScorer ¶ added in v0.3.0
func (s *CustomScorer) GetBaseScorer() models.BaseScorer
func (*CustomScorer) GetClassName ¶
func (s *CustomScorer) GetClassName() string
func (*CustomScorer) GetName ¶
func (s *CustomScorer) GetName() string
func (*CustomScorer) GetScorerConfig ¶
func (s *CustomScorer) GetScorerConfig() *models.ScorerConfig
func (*CustomScorer) IsServerHosted ¶
func (s *CustomScorer) IsServerHosted() bool
type CustomScorerFactory ¶
type CustomScorerFactory struct{}
func (*CustomScorerFactory) Get ¶
func (f *CustomScorerFactory) Get(name string, className string) (*CustomScorer, error)
type CustomScorerParams ¶
type CustomerIDProcessor ¶ added in v0.3.0
type CustomerIDProcessor struct{}
func (*CustomerIDProcessor) ForceFlush ¶ added in v0.3.0
func (p *CustomerIDProcessor) ForceFlush(ctx context.Context) error
func (*CustomerIDProcessor) OnEnd ¶ added in v0.3.0
func (p *CustomerIDProcessor) OnEnd(s sdktrace.ReadOnlySpan)
func (*CustomerIDProcessor) OnStart ¶ added in v0.3.0
func (p *CustomerIDProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)
type Evaluation ¶
type Evaluation struct {
// contains filtered or unexported fields
}
type EvaluationCreateParams ¶
type EvaluationCreateParams struct {
}
type EvaluationFactory ¶
type EvaluationFactory struct {
// contains filtered or unexported fields
}
func (*EvaluationFactory) Create ¶
func (f *EvaluationFactory) Create(params EvaluationCreateParams) *Evaluation
type Example ¶
type Example struct {
// contains filtered or unexported fields
}
func NewExample ¶
func NewExample(params ExampleParams) *Example
func (*Example) GetCreatedAt ¶
func (*Example) GetExampleID ¶
func (*Example) GetProperties ¶
func (*Example) GetProperty ¶
func (*Example) SetProperty ¶
type ExampleParams ¶
type FaithfulnessScorer ¶
type FaithfulnessScorer struct {
// contains filtered or unexported fields
}
func (*FaithfulnessScorer) GetScorerConfig ¶
func (s *FaithfulnessScorer) GetScorerConfig() *models.ScorerConfig
type FilterTracerFunc ¶ added in v0.2.4
type FilterTracerFunc func(name string, opts ...trace.TracerOption) bool
type Judgeval ¶
type Judgeval struct {
Tracer *TracerFactory
Scorers *ScorersFactory
Evaluation *EvaluationFactory
// contains filtered or unexported fields
}
type JudgevalTracerLike ¶ added in v0.2.7
type JudgevalTracerLike interface {
Initialize(ctx context.Context) error
ForceFlush(ctx context.Context) error
Shutdown(ctx context.Context) error
GetTracer() trace.Tracer
Span(ctx context.Context, spanName string) (context.Context, trace.Span)
SetSpanKind(span trace.Span, kind string)
SetLLMSpan(span trace.Span)
SetToolSpan(span trace.Span)
SetGeneralSpan(span trace.Span)
SetAttribute(span trace.Span, key string, value interface{})
SetAttributes(span trace.Span, attrs map[string]interface{})
SetInput(span trace.Span, input interface{})
SetOutput(span trace.Span, output interface{})
SetCustomerID(ctx context.Context, customerID string) context.Context
SetSessionID(ctx context.Context, sessionID string) context.Context
AsyncEvaluate(ctx context.Context, scorer BaseScorer, example *Example)
AsyncTraceEvaluate(ctx context.Context, scorer BaseScorer)
StartSpan(ctx context.Context, spanName string) (context.Context, trace.Span)
EndSpan(span trace.Span)
}
type JudgmentSpanExporter ¶ added in v0.2.4
type JudgmentSpanExporter struct {
// contains filtered or unexported fields
}
func (*JudgmentSpanExporter) ExportSpans ¶ added in v0.2.4
func (e *JudgmentSpanExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error
type JudgmentSpanProcessor ¶ added in v0.2.4
type JudgmentSpanProcessor struct {
// contains filtered or unexported fields
}
func (*JudgmentSpanProcessor) ForceFlush ¶ added in v0.2.4
func (p *JudgmentSpanProcessor) ForceFlush(ctx context.Context) error
func (*JudgmentSpanProcessor) OnEnd ¶ added in v0.2.4
func (p *JudgmentSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan)
func (*JudgmentSpanProcessor) OnStart ¶ added in v0.2.4
func (p *JudgmentSpanProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)
type JudgmentTracerProvider ¶ added in v0.2.4
type JudgmentTracerProvider struct {
embedded.TracerProvider
// contains filtered or unexported fields
}
func NewJudgmentTracerProvider ¶ added in v0.2.4
func NewJudgmentTracerProvider(config *JudgmentTracerProviderConfig, opts ...sdktrace.TracerProviderOption) *JudgmentTracerProvider
func (*JudgmentTracerProvider) ForceFlush ¶ added in v0.2.4
func (j *JudgmentTracerProvider) ForceFlush(ctx context.Context) error
func (*JudgmentTracerProvider) Shutdown ¶ added in v0.2.4
func (j *JudgmentTracerProvider) Shutdown(ctx context.Context) error
func (*JudgmentTracerProvider) Tracer ¶ added in v0.2.4
func (j *JudgmentTracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer
type JudgmentTracerProviderConfig ¶ added in v0.2.4
type JudgmentTracerProviderConfig struct {
// FilterTracer filters what tracers are allowed to be created. This is useful when you want to disable any instrumentation
// or control instrumentation that is automatically created by auto-instrumentations or other libraries.
// If set to return false, the caller will receive a NoOpTracer.
// The function receives the tracer name and options to check if it should be allowed.
// Returns true if the tracer should be allowed, false otherwise.
FilterTracer FilterTracerFunc
}
type NoOpSpanExporter ¶ added in v0.2.4
type NoOpSpanExporter struct{}
func (*NoOpSpanExporter) ExportSpans ¶ added in v0.2.4
func (e *NoOpSpanExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlySpan) error
type NoOpSpanProcessor ¶ added in v0.2.4
type NoOpSpanProcessor struct{}
func (*NoOpSpanProcessor) ForceFlush ¶ added in v0.2.4
func (p *NoOpSpanProcessor) ForceFlush(ctx context.Context) error
func (*NoOpSpanProcessor) OnEnd ¶ added in v0.2.4
func (p *NoOpSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan)
func (*NoOpSpanProcessor) OnStart ¶ added in v0.2.4
func (p *NoOpSpanProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)
type NoOpTracer ¶ added in v0.2.7
type NoOpTracer struct {
*BaseTracer
}
NoOpTracer is a no-op implementation of JudgevalTracerLike.
func NewNoOpTracer ¶ added in v0.2.7
func NewNoOpTracer() *NoOpTracer
func (*NoOpTracer) ForceFlush ¶ added in v0.2.7
func (n *NoOpTracer) ForceFlush(ctx context.Context) error
func (*NoOpTracer) Initialize ¶ added in v0.2.7
func (n *NoOpTracer) Initialize(ctx context.Context) error
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithAPIKey ¶
func WithAPIURL ¶
func WithOrganizationID ¶
type PromptScorer ¶
type PromptScorer struct {
// contains filtered or unexported fields
}
func (*PromptScorer) AppendToPrompt ¶
func (s *PromptScorer) AppendToPrompt(addition string)
func (*PromptScorer) GetDescription ¶
func (s *PromptScorer) GetDescription() string
func (*PromptScorer) GetModel ¶
func (s *PromptScorer) GetModel() string
func (*PromptScorer) GetName ¶
func (s *PromptScorer) GetName() string
func (*PromptScorer) GetOptions ¶
func (s *PromptScorer) GetOptions() map[string]float64
func (*PromptScorer) GetPrompt ¶
func (s *PromptScorer) GetPrompt() string
func (*PromptScorer) GetScorerConfig ¶
func (s *PromptScorer) GetScorerConfig() *models.ScorerConfig
func (*PromptScorer) GetThreshold ¶
func (s *PromptScorer) GetThreshold() float64
func (*PromptScorer) SetDescription ¶
func (s *PromptScorer) SetDescription(description string)
func (*PromptScorer) SetModel ¶
func (s *PromptScorer) SetModel(model string)
func (*PromptScorer) SetOptions ¶
func (s *PromptScorer) SetOptions(options map[string]float64)
func (*PromptScorer) SetPrompt ¶
func (s *PromptScorer) SetPrompt(prompt string)
func (*PromptScorer) SetThreshold ¶
func (s *PromptScorer) SetThreshold(threshold float64)
type PromptScorerFactory ¶
type PromptScorerFactory struct {
// contains filtered or unexported fields
}
func (*PromptScorerFactory) Get ¶
func (f *PromptScorerFactory) Get(ctx context.Context, name string) (*PromptScorer, error)
type ScorerConfig ¶
type ScorerConfig = models.ScorerConfig
type ScorersFactory ¶
type ScorersFactory struct {
BuiltIn *BuiltInScorersFactory
PromptScorer *PromptScorerFactory
TracePromptScorer *PromptScorerFactory
CustomScorer *CustomScorerFactory
// contains filtered or unexported fields
}
type SerializerFunc ¶
type SessionIDProcessor ¶ added in v0.3.0
type SessionIDProcessor struct{}
func (*SessionIDProcessor) ForceFlush ¶ added in v0.3.0
func (p *SessionIDProcessor) ForceFlush(ctx context.Context) error
func (*SessionIDProcessor) OnEnd ¶ added in v0.3.0
func (p *SessionIDProcessor) OnEnd(s sdktrace.ReadOnlySpan)
func (*SessionIDProcessor) OnStart ¶ added in v0.3.0
func (p *SessionIDProcessor) OnStart(parentContext context.Context, span sdktrace.ReadWriteSpan)
type Tracer ¶
type Tracer struct {
*BaseTracer
// contains filtered or unexported fields
}
type TracerCreateParams ¶
type TracerCreateParams struct {
EnableEvaluation *bool
Serializer SerializerFunc
ResourceAttributes map[string]any
FilterTracer FilterTracerFunc
Initialize *bool
}
type TracerFactory ¶
type TracerFactory struct {
// contains filtered or unexported fields
}
func (*TracerFactory) Create ¶
func (f *TracerFactory) Create(ctx context.Context, params TracerCreateParams) (*Tracer, error)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package integrations provides middleware for instrumenting LLM client libraries with Judgment tracing.
|
Package integrations provides middleware for instrumenting LLM client libraries with Judgment tracing. |
|
internal
|
|
Click to show internal directories.
Click to hide internal directories.