|
17 | 17 | assert_equal 0, Baml::Collector.__function_span_count if Baml::Collector.respond_to?(:__function_span_count) |
18 | 18 | end |
19 | 19 |
|
20 | | - after do |
| 20 | + after do |
21 | 21 | # Force garbage collection and check collector is empty |
22 | 22 | GC.start |
23 | 23 | # GC.start(full_mark: true, immediate_sweep: true); |
|
35 | 35 | b.TestOpenAIGPT4oMini(input: "hi there", baml_options: {collector: collector}) |
36 | 36 |
|
37 | 37 | puts "func called" |
38 | | - |
| 38 | + |
39 | 39 |
|
40 | 40 | puts "#{Baml::Collector.__function_span_count}" |
41 | 41 | puts "#{Baml::Collector.__print_storage}" |
|
71 | 71 |
|
72 | 72 | # Verify request/response |
73 | 73 | request = call.http_request |
74 | | - refute_nil request |
75 | | - assert_kind_of Hash, request.body |
76 | | - assert_includes request.body, "messages" |
77 | | - assert_includes request.body["messages"][0], "content" |
78 | | - refute_nil request.body["messages"][0]["content"] |
79 | | - assert_equal "gpt-4o-mini", request.body["model"] |
| 74 | + body = request.body.json() |
| 75 | + refute_nil body |
| 76 | + assert_kind_of Hash, body |
| 77 | + assert_includes body, "messages" |
| 78 | + assert_includes body["messages"][0], "content" |
| 79 | + refute_nil body["messages"][0]["content"] |
| 80 | + assert_equal "gpt-4o-mini", body["model"] |
80 | 81 |
|
81 | 82 | # Verify http response |
82 | 83 | response = call.http_response |
83 | 84 | refute_nil response |
| 85 | + body = response.body.json() |
84 | 86 | assert_equal 200, response.status |
85 | | - refute_nil response.body |
86 | | - assert_kind_of Hash, response.body |
87 | | - assert_includes response.body, "choices" |
88 | | - assert response.body["choices"].length > 0 |
89 | | - assert_includes response.body["choices"][0], "message" |
90 | | - assert_includes response.body["choices"][0]["message"], "content" |
91 | | - refute_nil response.body["choices"][0]["message"]["content"] |
| 87 | + refute_nil body |
| 88 | + assert_kind_of Hash, body |
| 89 | + assert_includes body, "choices" |
| 90 | + assert body["choices"].length > 0 |
| 91 | + assert_includes body["choices"][0], "message" |
| 92 | + assert_includes body["choices"][0]["message"], "content" |
| 93 | + refute_nil body["choices"][0]["message"]["content"] |
92 | 94 |
|
93 | 95 | puts "call.body.headers: #{call.http_response.headers}" |
94 | 96 | # Verify response headers contain openai-version |
|
109 | 111 | assert call_usage.input_tokens > 0 |
110 | 112 | refute_nil call_usage.output_tokens |
111 | 113 | assert call_usage.output_tokens > 0 |
112 | | - |
| 114 | + |
113 | 115 | # Matches log usage |
114 | 116 | assert_equal call_usage.input_tokens, log.usage.input_tokens |
115 | 117 | assert_equal call_usage.output_tokens, log.usage.output_tokens |
|
149 | 151 | assert_equal 0, function_logs.length |
150 | 152 |
|
151 | 153 | stream = b.stream.TestOpenAIGPT4oMini(input: "hi there", baml_options: {collector: collector}) |
152 | | - |
| 154 | + |
153 | 155 | chunks = [] |
154 | 156 | stream.each do |chunk| |
155 | 157 | puts "### chunk: #{chunk}" |
|
158 | 160 |
|
159 | 161 | res = stream.get_final_response |
160 | 162 | puts "### res: #{res}" |
161 | | - |
| 163 | + |
162 | 164 | function_logs = collector.logs |
163 | 165 | assert_equal 1, function_logs.length |
164 | 166 |
|
|
329 | 331 | threads << Thread.new { b.TestOpenAIGPT4oMini(input: "call #1", baml_options: {collector: collector}) } |
330 | 332 | threads << Thread.new { b.TestOpenAIGPT4oMini(input: "call #2", baml_options: {collector: collector}) } |
331 | 333 | threads.each(&:join) |
332 | | - |
| 334 | + |
333 | 335 | puts "------------------------- ended parallel calls" |
334 | 336 |
|
335 | 337 | # Verify the collector has two function logs |
|
0 commit comments