Skip to content

Commit

Permalink
Create event class files, classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Jan 19, 2024
1 parent 2fe8a0c commit dfd9c3c
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/new_relic/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module Agent
require 'new_relic/agent/attribute_processing'
require 'new_relic/agent/linking_metadata'
require 'new_relic/agent/local_log_decorator'
require 'new_relic/agent/llm_event'

require 'new_relic/agent/instrumentation/controller_instrumentation'

Expand Down
30 changes: 30 additions & 0 deletions lib/new_relic/agent/llm_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require_relative 'llm_event/chat_completion'

module NewRelic
module Agent
class LlmEvent

# response_model looks like repsonse.model
attr_accessor :id, :app_name, :request_id, :span_id, :transaction_id, :trace_id, :response_model, :vendor
INGEST_SOURCE = 'Ruby'

def initialize(id:, app_name:, request_id:, span_id:, transaction_id:, trace_id:, response_model:, vendor:, **args)
@id = id
@app_name = app_name
@request_id = request_id
@span_id = span_id
@transaction_id = transaction_id
@trace_id = trace_id
@response_model = response_model
@vendor = vendor
end

# Method for subclasses to override
def record; end
end
end
end
28 changes: 28 additions & 0 deletions lib/new_relic/agent/llm_event/chat_completion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true


module NewRelic
module Agent
class LlmEvent
class ChatCompletion < NewRelic::Agent::LlmEvent

# Real metrics are written: request.max_tokens, response.number_of_messages
attr_accessor :api_key_last_four_digits, :conversation_id, :request_max_tokens, :response_number_of_messages

def initialize(api_key_last_four_digits:, conversation_id:, request_max_tokens:, response_number_of_messages:)
@api_key_last_four_digits = api_key_last_four_digits
@conversation_id = conversation_id
@request_max_tokens = request_max_tokens
@response_number_of_messages = response_number_of_messages
super
end

# Method for subclasses to override
def record; end
end
end
end
end

24 changes: 24 additions & 0 deletions lib/new_relic/agent/llm_event/chat_completion/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

class NewRelic
class Agent
class LlmEvent
class ChatCompletion
class Message < NewRelic::Agent::LlmEvent::ChatCompletion

attr_accessor :content, :role, :sequence, :completion_id, :is_response

def initialize

end

def record

end
end
end
end
end
end
43 changes: 43 additions & 0 deletions lib/new_relic/agent/llm_event/chat_completion/summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

class NewRelic
class Agent
class LlmEvent
class ChatCompletion

attr_accessor
:'request.model',
:'response.organization',
:'response.usage.total_tokens',
:'response.usage.prompt_tokens',
:'response.usage.completion_tokens',
:'response.choices.finish_reason',
:'response.headers.llmVersion',
:'response.headers.ratelimitLimitRequests',
:'response.headers.ratelimitLimitTokens',
:'response.headers.ratelimitResetTokens',
:'response.headers.ratelimitResetRequests',
:'response.headers.ratelimitRemainingTokens',
:'response.headers.ratelimitRemainingRequests',
:duration,
:'request.temperature',
:error



class Summary < NewRelic::Agent::LlmEvent::ChatCompletion

def initialize

end

def record

end
end
end
end
end
end
36 changes: 36 additions & 0 deletions lib/new_relic/agent/llm_event/embedding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

class NewRelic
class Agent
class LlmEvent
class Embedding < NewRelic::Agent::LlmEvent

attr_accessor
:input,
:'request.model',
:'response.organization',
:'response.usage.total_tokens',
:'response.usage.prompt_tokens',
:'response.headers.llmVersion',
:'response.headers.ratelimitLimitRequests'
:'response.headers.ratelimitLimitTokens',
:'response.headers.ratelimitResetTokens',
:'response.headers.ratelimitResetRequests',
:'response.headers.ratelimitRemainingTokens',
:'response.headers.ratelimitRemainingRequests',
:duration,
:error

def initialize

end

def record

end
end
end
end
end
13 changes: 13 additions & 0 deletions lib/new_relic/agent/llm_event/feedback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true


class NewRelic
class Agent
class LlmEvent
class Feedback < NewRelic::Agent::LlmEvent
end
end
end
end
19 changes: 19 additions & 0 deletions test/new_relic/agent/llm_event_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require_relative '../../test_helper'


module NewRelic::Agent
class LlmEventTest < Minitest::Test
# def test_attributes
# NewRelic::Agent::LlmEvent.new

# end

def test_attributes_chat
NewRelic::Agent::LlmEvent::ChatCompletion.new
end
end
end

0 comments on commit dfd9c3c

Please sign in to comment.