package module
v1.1.0 Latest Latest

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 12 Imported by: 0




This section is empty.


This section is empty.


func AppendCustomAttributesToEvent

func AppendCustomAttributesToEvent(cw *ClientWrapper, data map[string]interface{}) map[string]interface{}

func GetInput

func GetInput(any interface{}) any

If multiple messages are sent, only the first message is used for the "content" field

func NRCreateChatCompletionMessage

func NRCreateChatCompletionMessage(txn *newrelic.Transaction, app *newrelic.Application, resp openai.ChatCompletionResponse, uuid uuid.UUID, cw *ClientWrapper, sequence int, req openai.ChatCompletionRequest)

NRCreateChatCompletionMessage captures the completion response messages and records a custom event in New Relic for each message

func NRCreateChatCompletionMessageInput

func NRCreateChatCompletionMessageInput(txn *newrelic.Transaction, app *newrelic.Application, req openai.ChatCompletionRequest, inputuuid uuid.UUID, cw *ClientWrapper) int

Captures initial request messages and records a custom event in New Relic for each message

func NRCreateChatCompletionMessageStream

func NRCreateChatCompletionMessageStream(app *newrelic.Application, uuid uuid.UUID, sw *ChatCompletionStreamWrapper, cw *ClientWrapper, sequence int)

func NRCreateEmbedding

func NRCreateEmbedding(cw *ClientWrapper, req openai.EmbeddingRequest, app *newrelic.Application) (openai.EmbeddingResponse, error)

NRCreateEmbedding is a wrapper for the OpenAI CreateEmbedding method. If AI Monitoring is disabled, the wrapped function will still call the OpenAI CreateEmbedding method and return the response with no New Relic instrumentation

func TokenCountingHelper

func TokenCountingHelper(app *newrelic.Application, message openai.ChatCompletionMessage, model string) (numTokens int, tokensCounted bool)

Calculates tokens using the LLmTokenCountCallback In order to calculate total tokens of a message, we need to factor in the Content, Role, and Name (if it exists)


type ChatCompletionResponseWrapper

type ChatCompletionResponseWrapper struct {
	ChatCompletionResponse openai.ChatCompletionResponse
	TraceID                string

Wrapper for ChatCompletionResponse that is returned from NRCreateChatCompletion. It also includes the TraceID of the transaction for linking a chat response with it's feedback

func NRCreateChatCompletion

func NRCreateChatCompletion(cw *ClientWrapper, req openai.ChatCompletionRequest, app *newrelic.Application) (ChatCompletionResponseWrapper, error)

NRCreateChatCompletion is a wrapper for the OpenAI CreateChatCompletion method. If AI Monitoring is disabled, the wrapped function will still call the OpenAI CreateChatCompletion method and return the response with no New Relic instrumentation

func NRCreateChatCompletionSummary

func NRCreateChatCompletionSummary(txn *newrelic.Transaction, app *newrelic.Application, cw *ClientWrapper, req openai.ChatCompletionRequest) ChatCompletionResponseWrapper

NRCreateChatCompletionSummary captures the request and response data for a chat completion request and records a custom event in New Relic. It also captures the completion messages With a call to NRCreateChatCompletionMessage

type ChatCompletionStreamWrapper

type ChatCompletionStreamWrapper struct {
	StreamingData map[string]interface{}

	TraceID string
	// contains filtered or unexported fields

Wrapper for ChatCompletionStream that is returned from NRCreateChatCompletionStream Contains attributes that get populated during the streaming process

func NRCreateChatCompletionStream

func NRCreateChatCompletionStream(cw *ClientWrapper, ctx context.Context, req openai.ChatCompletionRequest, app *newrelic.Application) (*ChatCompletionStreamWrapper, error)

func (*ChatCompletionStreamWrapper) Close

func (w *ChatCompletionStreamWrapper) Close()

func (*ChatCompletionStreamWrapper) Recv

func (w *ChatCompletionStreamWrapper) Recv() (openai.ChatCompletionStreamResponse, error)

Wrapper for Recv() method that calls the underlying stream's Recv() method

type ClientWrapper

type ClientWrapper struct {
	Client OpenAIClient
	// Set of Custom Attributes that get tied to all LLM Events
	CustomAttributes map[string]interface{}

Wrapper for OpenAI Client with Custom Attributes that can be set for all LLM Events

func NRNewClient

func NRNewClient(authToken string) *ClientWrapper

Call to Create Client Wrapper

func NRNewClientWithConfig

func NRNewClientWithConfig(config *ConfigWrapper) *ClientWrapper

NewClientWithConfig creates new OpenAI API client for specified config.

func (*ClientWrapper) AddCustomAttributes

func (cw *ClientWrapper) AddCustomAttributes(attributes map[string]interface{})

Adds Custom Attributes to the ClientWrapper

type ConfigWrapper

type ConfigWrapper struct {
	Config *openai.ClientConfig

Wrapper for OpenAI Configuration

func NRDefaultAzureConfig

func NRDefaultAzureConfig(apiKey, baseURL string) *ConfigWrapper

Azure Config

func NRDefaultConfig

func NRDefaultConfig(authToken string) *ConfigWrapper

Default Config

type OpenAIClient

type OpenAIClient interface {
	CreateChatCompletion(ctx context.Context, request openai.ChatCompletionRequest) (response openai.ChatCompletionResponse, err error)
	CreateChatCompletionStream(ctx context.Context, request openai.ChatCompletionRequest) (stream *openai.ChatCompletionStream, err error)
	CreateEmbeddings(ctx context.Context, conv openai.EmbeddingRequestConverter) (res openai.EmbeddingResponse, err error)


Path Synopsis

Jump to

Keyboard shortcuts

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