Documentation
¶
Index ¶
- func CalculateGlobalCost(model string, inputTokens, outputTokens int) float64
- func EmitInferenceEvent(span trace.Span, attrs []attribute.KeyValue)
- func EstimateTokenCount(text string) int
- func EstimateTokensFromMessages(messages []string) int
- func GetCaptureMessageContent() bool
- func InitGlobalPricingCache(endpoint string, disableFetch bool, customPricing map[string]PricingInfo)
- func RecordError(span trace.Span, err error)
- func RecordException(span trace.Span, err error, message string)
- func SetCaptureMessageContent(capture bool)
- func SetServerAddressAndPort(baseURL string, defaultAddress string, defaultPort int) (string, int)
- type InstrumentedRoundTripper
- type PricingCache
- type PricingInfo
- type TokenStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateGlobalCost ¶
CalculateGlobalCost is a convenience function using the global cache
func EmitInferenceEvent ¶
EmitInferenceEvent records the GenAI client inference operation details event. Matches the Python/TS emitInferenceEvent behaviour.
func EstimateTokenCount ¶
EstimateTokenCount provides a rough estimation of token count This is a simple approximation - for accurate counts, use tiktoken or similar
func EstimateTokensFromMessages ¶
EstimateTokensFromMessages estimates tokens from a list of messages
func GetCaptureMessageContent ¶
func GetCaptureMessageContent() bool
GetCaptureMessageContent returns whether message content should be captured.
func InitGlobalPricingCache ¶
func InitGlobalPricingCache(endpoint string, disableFetch bool, customPricing map[string]PricingInfo)
InitGlobalPricingCache initializes the global pricing cache
func RecordError ¶
RecordError records an error on a span
func RecordException ¶
RecordException records an exception with an explicit message on a span
func SetCaptureMessageContent ¶
func SetCaptureMessageContent(capture bool)
SetCaptureMessageContent configures whether prompt/completion text is recorded in span attributes. Called by shield360.Init based on DisableCaptureMessageContent.
Types ¶
type InstrumentedRoundTripper ¶
type InstrumentedRoundTripper struct {
// contains filtered or unexported fields
}
InstrumentedRoundTripper wraps an http.RoundTripper with OpenTelemetry tracing
func NewInstrumentedRoundTripper ¶
func NewInstrumentedRoundTripper(base http.RoundTripper, spanName string, opts ...trace.SpanStartOption) *InstrumentedRoundTripper
NewInstrumentedRoundTripper creates a new instrumented round tripper
type PricingCache ¶
type PricingCache struct {
// contains filtered or unexported fields
}
PricingCache manages pricing information with automatic fetching
func GetGlobalPricingCache ¶
func GetGlobalPricingCache() *PricingCache
GetGlobalPricingCache returns the global pricing cache
func NewPricingCache ¶
func NewPricingCache(endpoint string, disableFetch bool, customPricing map[string]PricingInfo) *PricingCache
NewPricingCache creates a new pricing cache
func (*PricingCache) CalculateCost ¶
func (pc *PricingCache) CalculateCost(model string, inputTokens, outputTokens int) float64
CalculateCost calculates the cost for input and output tokens
func (*PricingCache) GetPricing ¶
func (pc *PricingCache) GetPricing(model string) (PricingInfo, bool)
GetPricing returns pricing information for a model
func (*PricingCache) RefreshPricing ¶
func (pc *PricingCache) RefreshPricing(ctx context.Context) error
RefreshPricing forces a refresh of pricing information
func (*PricingCache) SetPricing ¶
func (pc *PricingCache) SetPricing(model string, pricing PricingInfo)
SetPricing sets pricing information for a model
type PricingInfo ¶
type PricingInfo struct {
InputCostPerToken float64 `json:"input_cost_per_token"`
OutputCostPerToken float64 `json:"output_cost_per_token"`
}
PricingInfo holds pricing information for a model
type TokenStats ¶
TokenStats holds token usage statistics
func NewTokenStats ¶
func NewTokenStats(input, output int) TokenStats
NewTokenStats creates a new TokenStats instance
func (*TokenStats) Add ¶
func (ts *TokenStats) Add(other TokenStats)
Add adds another TokenStats to this one