Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit ed128ee

Browse files
committed
introduce a log
1 parent 4bd320d commit ed128ee

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
/gems
33
/auto_generated
44
.env
5+
evals/log/*

evals/run

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ OptionParser
2424
end
2525

2626
opts.on("-m", "--model NAME", "Model to evaluate") { |model| options[:model] = model }
27-
28-
opts.on("-o", "--output-dir DIR", "Directory for evaluation results") do |dir|
29-
options[:output_dir] = dir
30-
end
3127
end
3228
.parse!
3329

@@ -60,7 +56,19 @@ eval_info = YAML.load_file(cases[options[:eval_name]]).symbolize_keys
6056

6157
puts "Running evaluation '#{options[:eval_name]}'"
6258

59+
log_filename = "#{options[:eval_name]}-#{Time.now.strftime("%Y%m%d-%H%M%S")}.log"
60+
logs_dir = File.join(__dir__, "log")
61+
FileUtils.mkdir_p(logs_dir) # Create directory if it doesn't exist
62+
log_file = File.join(logs_dir, log_filename)
63+
64+
logger = Logger.new(File.open(log_file, "a"))
65+
66+
logger.info("Starting evaluation '#{options[:eval_name]}'")
67+
68+
Thread.current[:llm_audit_log] = logger
69+
6370
llms.each do |llm|
71+
logger.info("Evaluating with LLM: #{llm.name}")
6472
eval =
6573
llm.eval(
6674
type: eval_info[:type],
@@ -73,9 +81,15 @@ llms.each do |llm|
7381
puts "Failed 🔴"
7482
puts "---- Expected ----\n#{eval[:expected_output]}"
7583
puts "---- Actual ----\n#{eval[:actual_output]}"
84+
logger.error("Evaluation failed with LLM: #{llm.name}")
7685
elsif eval[:result] == :pass
7786
puts "Passed 🟢"
87+
logger.info("Evaluation passed with LLM: #{llm.name}")
7888
else
7989
STDERR.puts "Error: Unknown result #{eval.inspect}"
90+
logger.error("Unknown result: #{eval.inspect}")
8091
end
8192
end
93+
94+
puts
95+
puts "Log file: #{log_file}"

lib/completions/endpoints/base.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ def perform_completion!(
156156
)
157157

158158
if !@streaming_mode
159-
return(
159+
response_data =
160160
non_streaming_response(
161161
response: response,
162162
xml_tool_processor: xml_tool_processor,
163163
xml_stripper: xml_stripper,
164164
partials_raw: partials_raw,
165165
response_raw: response_raw,
166166
)
167-
)
167+
return response_data
168168
end
169169

170170
begin
@@ -214,6 +214,16 @@ def perform_completion!(
214214
decode_chunk_finish.each { |partial| blk.call(partial, cancel) }
215215
return response_data
216216
ensure
217+
if log && (logger = Thread.current[:llm_audit_log])
218+
call_data = <<~LOG
219+
#{self.class.name}: request_tokens #{log.request_tokens} response_tokens #{log.response_tokens}
220+
request:
221+
#{format_possible_json_payload(log.raw_request_payload)}
222+
response:
223+
#{response_data}
224+
LOG
225+
logger.info(call_data)
226+
end
217227
if log
218228
log.raw_response_payload = response_raw
219229
final_log_update(log)
@@ -298,6 +308,14 @@ def disable_streaming?
298308

299309
private
300310

311+
def format_possible_json_payload(payload)
312+
begin
313+
JSON.pretty_generate(JSON.parse(payload))
314+
rescue JSON::ParserError
315+
payload
316+
end
317+
end
318+
301319
def start_log(
302320
provider_id:,
303321
request_body:,

0 commit comments

Comments
 (0)