Class: LLM::Tracer::Logger
- Inherits:
-
Tracer
- Object
- Tracer
- LLM::Tracer::Logger
- Defined in:
- lib/llm/tracer/logger.rb
Overview
The LLM::Tracer::Logger class provides a tracer that provides logging facilities through Ruby's standard library.
Instance Method Summary collapse
-
#on_exit ⇒ nil
No-op.
- #on_request_start(operation:, model: nil)
- #on_request_finish(operation:, res:, model: nil)
- #on_request_error(ex:)
-
#on_tool_start(id:, name:, arguments:, model:) ⇒ LLM::Object
The span an ending is handed, with the call's id and name.
- #on_tool_finish(result:)
- #on_tool_error(ex:)
- #on_tool_interrupt(ex:, span:)
- #on_interrupt(scope:, request_id: nil)
-
#initialize(llm, options = {}) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(llm, options = {}) ⇒ Logger
Returns a new instance of Logger.
18 19 20 21 |
# File 'lib/llm/tracer/logger.rb', line 18 def initialize(llm, = {}) super setup!(**) end |
Instance Method Details
#on_exit ⇒ nil
No-op.
140 141 142 |
# File 'lib/llm/tracer/logger.rb', line 140 def on_exit nil end |
#on_request_start(operation:, model: nil)
This method returns an undefined value.
26 27 28 29 30 31 32 |
# File 'lib/llm/tracer/logger.rb', line 26 def on_request_start(operation:, model: nil, **) case operation when "chat" then start_chat(operation:, model:) when "retrieval" then start_retrieval(operation:) else nil end end |
#on_request_finish(operation:, res:, model: nil)
This method returns an undefined value.
37 38 39 40 41 42 43 |
# File 'lib/llm/tracer/logger.rb', line 37 def on_request_finish(operation:, res:, model: nil, **) case operation when "chat" then finish_chat(operation:, res:, model:) when "retrieval" then finish_retrieval(operation:, res:) else nil end end |
#on_request_error(ex:)
This method returns an undefined value.
48 49 50 51 52 53 54 55 56 |
# File 'lib/llm/tracer/logger.rb', line 48 def on_request_error(ex:, **) @logger.error( tracer: "llm.rb (logger)", event: "request.error", provider: llm.name, error_class: ex.class.to_s, error_message: ex. ) end |
#on_tool_start(id:, name:, arguments:, model:) ⇒ LLM::Object
Note:
An "ending" describes the method that matches the end of a tool call, and it can be one of: on_tool_finish, on_tool_error or on_tool_interrupt.
Returns The span an ending is handed, with the call's id and name.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/llm/tracer/logger.rb', line 65 def on_tool_start(id:, name:, arguments:, model:, **) @logger.info( tracer: "llm.rb (logger)", event: "tool.start", provider: llm.name, operation: "execute_tool", tool_id: id, tool_name: name, tool_arguments: arguments, model: ) LLM::Object.from(id:, name:) end |
#on_tool_finish(result:)
This method returns an undefined value.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/llm/tracer/logger.rb', line 82 def on_tool_finish(result:, **) @logger.info( tracer: "llm.rb (logger)", event: "tool.finish", provider: llm.name, operation: "execute_tool", tool_id: result.id, tool_name: result.name, tool_result: result.value ) end |
#on_tool_error(ex:)
This method returns an undefined value.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/llm/tracer/logger.rb', line 97 def on_tool_error(ex:, **) @logger.error( tracer: "llm.rb (logger)", event: "tool.error", provider: llm.name, operation: "execute_tool", error_class: ex.value[:type], error_message: ex.value[:message] ) end |
#on_tool_interrupt(ex:, span:)
This method returns an undefined value.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/llm/tracer/logger.rb', line 111 def on_tool_interrupt(ex:, span:, **) @logger.info( tracer: "llm.rb (logger)", event: "tool.interrupt", provider: llm.name, operation: "execute_tool", tool_id: span.id, tool_name: span.name, error_class: ex.class.to_s, error_message: ex. ) end |
#on_interrupt(scope:, request_id: nil)
This method returns an undefined value.
127 128 129 130 131 132 133 134 135 |
# File 'lib/llm/tracer/logger.rb', line 127 def on_interrupt(scope:, request_id: nil, **) @logger.info( tracer: "llm.rb (logger)", event: "#{scope}.interrupt", provider: llm.name, scope:, request_id: ) end |