Class: NewRelic::Agent::Llm::ChatCompletionSummary

Inherits:
LlmEvent
  • Object
show all
Includes:
ResponseHeaders
Defined in:
lib/new_relic/agent/llm/chat_completion_summary.rb

Constant Summary collapse

ATTRIBUTES =
%i[request_max_tokens response_number_of_messages
request_model response_choices_finish_reason request_temperature
duration error]
ATTRIBUTE_NAME_EXCEPTIONS =
{
  response_number_of_messages: 'response.number_of_messages',
  request_model: 'request.model',
  response_choices_finish_reason: 'response.choices.finish_reason',
  request_temperature: 'request.temperature'
}
ERROR_COMPLETION_ID =
'completion_id'
EVENT_NAME =
'LlmChatCompletionSummary'

Constants included from ResponseHeaders

ResponseHeaders::OPENAI_ORGANIZATION, ResponseHeaders::OPENAI_VERSION, ResponseHeaders::X_RATELIMIT_LIMIT_REQUESTS, ResponseHeaders::X_RATELIMIT_LIMIT_TOKENS, ResponseHeaders::X_RATELIMIT_LIMIT_TOKENS_USAGE_BASED, ResponseHeaders::X_RATELIMIT_REMAINING_REQUESTS, ResponseHeaders::X_RATELIMIT_REMAINING_TOKENS, ResponseHeaders::X_RATELIMIT_REMAINING_TOKENS_USAGE_BASED, ResponseHeaders::X_RATELIMIT_RESET_REQUESTS, ResponseHeaders::X_RATELIMIT_RESET_TOKENS, ResponseHeaders::X_RATELIMIT_RESET_TOKENS_USAGE_BASED, ResponseHeaders::X_REQUEST_ID

Constants inherited from LlmEvent

LlmEvent::AGENT_DEFINED_ATTRIBUTES, LlmEvent::CODE_STRING, LlmEvent::ERROR_ATTRIBUTE_CODE, LlmEvent::ERROR_ATTRIBUTE_PARAM, LlmEvent::ERROR_ATTRIBUTE_STATUS_CODE, LlmEvent::ERROR_STRING, LlmEvent::INGEST_SOURCE, LlmEvent::PARAM_STRING

Instance Method Summary collapse

Methods included from ResponseHeaders

#populate_openai_response_headers

Methods inherited from LlmEvent

#event_attributes, #initialize, #record, set_llm_agent_attribute_on_transaction

Constructor Details

This class inherits a constructor from NewRelic::Agent::Llm::LlmEvent

Instance Method Details

#attribute_name_exceptionsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/new_relic/agent/llm/chat_completion_summary.rb', line 31

def attribute_name_exceptions
  # TODO: OLD RUBIES < 2.6
  # Hash#merge accepts multiple arguments in 2.6
  # Remove condition once support for Ruby <2.6 is dropped
  if RUBY_VERSION >= '2.6.0'
    LlmEvent::ATTRIBUTE_NAME_EXCEPTIONS.merge(ResponseHeaders::ATTRIBUTE_NAME_EXCEPTIONS, ATTRIBUTE_NAME_EXCEPTIONS)
  else
    LlmEvent::ATTRIBUTE_NAME_EXCEPTIONS.merge(ResponseHeaders::ATTRIBUTE_NAME_EXCEPTIONS).merge(ATTRIBUTE_NAME_EXCEPTIONS)
  end
end

#attributesObject



27
28
29
# File 'lib/new_relic/agent/llm/chat_completion_summary.rb', line 27

def attributes
  LlmEvent::ATTRIBUTES + ResponseHeaders::ATTRIBUTES + ATTRIBUTES
end

#error_attributes(exception) ⇒ Object



46
47
48
49
50
# File 'lib/new_relic/agent/llm/chat_completion_summary.rb', line 46

def error_attributes(exception)
  attrs = {ERROR_COMPLETION_ID => id}

  error_attributes_from_response(exception, attrs)
end

#event_nameObject



42
43
44
# File 'lib/new_relic/agent/llm/chat_completion_summary.rb', line 42

def event_name
  EVENT_NAME
end