PrefectHQ / marvin

✨ Build AI interfaces that spark joy
https://askmarvin.ai
Apache License 2.0
5.34k stars 348 forks source link

"UnboundLocalError: cannot access local variable 'panel'" when using FileSearch assistant tool #920

Closed actus-wirtenberger closed 6 months ago

actus-wirtenberger commented 7 months ago

First check

Bug summary

format_step() is missing a branch for tool_call.type == "file_search"

Reproduction

from marvin.beta import Assistant
from marvin.beta.assistants import FileSearch

def main() -> int:
    ai = Assistant(
        tools=[FileSearch]
    )
    ai.say(" ")
    return 0

Error

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\tmp\marvin-bug\.venv\Scripts\marvin-bug.exe\__main__.py", line 8, in <module>
  File "C:\tmp\marvin-bug\src\marvin_bug\__init__.py", line 8, in main
    ai.say(" ")
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\utilities\asyncio.py", line 193, in sync_wrapper
    return run_sync(coro)
           ^^^^^^^^^^^^^^
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\utilities\asyncio.py", line 106, in run_sync
    return context.run(asyncio.run, coroutine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\philipp.wirtenberger\scoop\persist\rye\py\cpython@3.12.2\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\philipp.wirtenberger\scoop\persist\rye\py\cpython@3.12.2\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\philipp.wirtenberger\scoop\persist\rye\py\cpython@3.12.2\Lib\asyncio\base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\assistants.py", line 131, in say_async
    result = await run.run_async()
             ^^^^^^^^^^^^^^^^^^^^^
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\runs.py", line 225, in run_async
    await stream.until_done()
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\openai\lib\streaming\_assistants.py", line 533, in until_done
    await consume_async_iterator(self)
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\openai\_utils\_streams.py", line 11, in consume_async_iterator
    async for _ in iterator:
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\openai\lib\streaming\_assistants.py", line 500, in __aiter__
    async for item in self._iterator:
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\openai\lib\streaming\_assistants.py", line 836, in __stream__
    await self._emit_sse_event(event)
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\openai\lib\streaming\_assistants.py", line 804, in _emit_sse_event
    await self.on_run_step_delta(
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\handlers.py", line 46, in on_run_step_delta
    self.print_run()
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\handlers.py", line 26, in print_run
    panels = format_run(
             ^^^^^^^^^^^
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\formatting.py", line 256, in format_run
    objects.extend([(format_step(s), s.created_at) for s in run.steps])
                     ^^^^^^^^^^^^^^
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\formatting.py", line 144, in format_step
    return _cached_format_step(step.model_dump_json())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\tmp\marvin-bug\.venv\Lib\site-packages\marvin\beta\assistants\formatting.py", line 136, in _cached_format_step
    panels.append(panel)
                  ^^^^^
UnboundLocalError: cannot access local variable 'panel' where it is not associated with a value

Versions

Version:                2.3.3
Python version:         3.12.2
OS/Arch:                windows/amd64

Additional context

No response