|
14 | 14 |
|
15 | 15 |
|
16 | 16 | # pylint: disable=import-outside-toplevel,no-name-in-module |
17 | | - |
18 | 17 | import importlib |
19 | 18 | import logging |
20 | 19 | import sys |
@@ -200,26 +199,31 @@ def test_upload(self): |
200 | 199 |
|
201 | 200 |
|
202 | 201 | class TestFsspecUploadHookIntegration(TestBase): |
| 202 | + def setUp(self): |
| 203 | + super().setUp() |
| 204 | + self.hook = FsspecUploadHook(base_path=BASE_PATH) |
| 205 | + |
| 206 | + def tearDown(self): |
| 207 | + super().tearDown() |
| 208 | + self.hook.shutdown() |
| 209 | + |
203 | 210 | def assert_fsspec_equal(self, path: str, value: str) -> None: |
204 | 211 | with fsspec.open(path, "r") as file: |
205 | 212 | self.assertEqual(file.read(), value) |
206 | 213 |
|
207 | 214 | def test_upload_completions(self): |
208 | | - hook = FsspecUploadHook( |
209 | | - base_path=BASE_PATH, |
210 | | - ) |
211 | 215 | tracer = self.tracer_provider.get_tracer(__name__) |
212 | 216 | log_record = LogRecord() |
213 | 217 |
|
214 | 218 | with tracer.start_as_current_span("chat mymodel") as span: |
215 | | - hook.upload( |
| 219 | + self.hook.upload( |
216 | 220 | inputs=FAKE_INPUTS, |
217 | 221 | outputs=FAKE_OUTPUTS, |
218 | 222 | system_instruction=FAKE_SYSTEM_INSTRUCTION, |
219 | 223 | span=span, |
220 | 224 | log_record=log_record, |
221 | 225 | ) |
222 | | - hook.shutdown() |
| 226 | + self.hook.shutdown() |
223 | 227 |
|
224 | 228 | finished_spans = self.get_finished_spans() |
225 | 229 | self.assertEqual(len(finished_spans), 1) |
@@ -250,25 +254,39 @@ def test_upload_completions(self): |
250 | 254 | '[{"content":"You are a helpful assistant.","type":"text"}]', |
251 | 255 | ) |
252 | 256 |
|
253 | | - @staticmethod |
254 | | - def upload_with_log(log_record: LogRecord): |
255 | | - hook = FsspecUploadHook( |
256 | | - base_path=BASE_PATH, |
257 | | - ) |
258 | | - |
259 | | - hook.upload( |
| 257 | + def test_stamps_empty_log(self): |
| 258 | + log_record = LogRecord() |
| 259 | + self.hook.upload( |
260 | 260 | inputs=FAKE_INPUTS, |
261 | 261 | outputs=FAKE_OUTPUTS, |
262 | 262 | system_instruction=FAKE_SYSTEM_INSTRUCTION, |
263 | 263 | log_record=log_record, |
264 | 264 | ) |
265 | | - hook.shutdown() |
266 | | - |
267 | | - def test_stamps_empty_log(self): |
268 | | - log_record = LogRecord() |
269 | | - self.upload_with_log(log_record) |
270 | 265 |
|
271 | 266 | # stamp on both body and attributes |
272 | 267 | self.assertIn("gen_ai.input.messages_ref", log_record.attributes) |
273 | 268 | self.assertIn("gen_ai.output.messages_ref", log_record.attributes) |
274 | 269 | self.assertIn("gen_ai.system_instructions_ref", log_record.attributes) |
| 270 | + |
| 271 | + def test_upload_bytes(self) -> None: |
| 272 | + log_record = LogRecord() |
| 273 | + self.hook.upload( |
| 274 | + inputs=[ |
| 275 | + types.InputMessage( |
| 276 | + role="user", |
| 277 | + parts=[ |
| 278 | + types.Text(content="What is the capital of France?"), |
| 279 | + {"type": "generic_bytes", "bytes": b"hello"}, |
| 280 | + ], |
| 281 | + ) |
| 282 | + ], |
| 283 | + outputs=FAKE_OUTPUTS, |
| 284 | + system_instruction=FAKE_SYSTEM_INSTRUCTION, |
| 285 | + log_record=log_record, |
| 286 | + ) |
| 287 | + self.hook.shutdown() |
| 288 | + |
| 289 | + self.assert_fsspec_equal( |
| 290 | + log_record.attributes["gen_ai.input.messages_ref"], |
| 291 | + '[{"role":"user","parts":[{"content":"What is the capital of France?","type":"text"},{"type":"generic_bytes","bytes":"aGVsbG8="}]}]', |
| 292 | + ) |
0 commit comments