shroominic / codeinterpreter-api

👾 Open source implementation of the ChatGPT Code Interpreter
https://discord.gg/Vaq25XJvvW
MIT License
3.76k stars 402 forks source link

CodeBox Credentials #29

Closed MeliJuanmi closed 1 year ago

MeliJuanmi commented 1 year ago

I get the following error when trying to run the first snapped on README:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[82], line 25
     23 import asyncio
     24 # run the async function
---> 25 asyncio.run(main())

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/nest_asyncio.py:35, in _patch_asyncio.<locals>.run(main, debug)
     33 task = asyncio.ensure_future(main)
     34 try:
---> 35     return loop.run_until_complete(task)
     36 finally:
     37     if not task.done():

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/nest_asyncio.py:90, in _patch_loop.<locals>.run_until_complete(self, future)
     87 if not f.done():
     88     raise RuntimeError(
     89         'Event loop stopped before Future completed.')
---> 90 return f.result()

File ~/.pyenv/versions/3.9.17/lib/python3.9/asyncio/futures.py:201, in Future.result(self)
    199 self.__log_traceback = False
    200 if self._exception is not None:
--> 201     raise self._exception
    202 return self._result

File ~/.pyenv/versions/3.9.17/lib/python3.9/asyncio/tasks.py:256, in Task.__step(***failed resolving arguments***)
    252 try:
    253     if exc is None:
    254         # We use the `send` method directly, because coroutines
    255         # don't have `__iter__` and `__next__` methods.
--> 256         result = coro.send(None)
    257     else:
    258         result = coro.throw(exc)

Cell In[82], line 6, in main()
      3 async def main():
      4     # create a session
      5     session = CodeInterpreterSession(openai_api_key="", model="gpt-3.5-turbo-0613")
----> 6     await session.astart()
      8     # generate a response based on user input
      9     output = await session.generate_response(
     10         "Plot the bitcoin chart of 2023 YTD"
     11     )

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/codeinterpreterapi/session.py:32, in CodeInterpreterSession.astart(self)
     31 async def astart(self) -> None:
---> 32     await self.codebox.astart()

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/codeboxapi/box/codebox.py:34, in CodeBox.astart(self)
     32 async def astart(self) -> CodeBoxStatus:
     33     self.session = ClientSession()
---> 34     return await self.astatus()

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/codeboxapi/box/codebox.py:75, in CodeBox.astatus(self)
     73 async def astatus(self):
     74     return CodeBoxStatus(
---> 75         ** await self.acodebox_request(
     76             method="GET",
     77             endpoint="/",
     78         )
     79     )

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/codeboxapi/box/codebox.py:58, in CodeBox.acodebox_request(self, method, endpoint, *args, **kwargs)
     56 if self.session is None:
     57     raise RuntimeError("CodeBox session not started")
---> 58 return await abase_request(
     59     self.session,
     60     method,
     61     f"/codebox/{self.id}" + endpoint,
     62     *args, **kwargs
     63 )

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/codeboxapi/utils.py:87, in abase_request(session, method, endpoint, body, files, content_type)
     85     request_data.pop("files")
     86     response = await session.request(**request_data)
---> 87 return await handle_response_async(response)

File ~/.pyenv/versions/3.9.17/lib/python3.9/site-packages/codeboxapi/utils.py:51, in handle_response_async(response)
     49 handler = handlers.get(response.headers['Content-Type'].split(';')[0], default_handler)
     50 if response.status != 200:
---> 51     raise Exception(f"Error: {response.status} {await response.text()}")
     52 return await handler(response)

Exception: Error: 403 {"detail":"Could not validate credentials"}
juananpe commented 1 year ago

I would say that you have set a value for CODEBOX_API_KEY in your .env file. If you didn't get an API key to use CodeBox, this value should be empty. An empty value will in turn run your code in a LocalBox (see https://github.com/shroominic/codebox-api/blob/main/codeboxapi/box/codebox.py#L19)

shroominic commented 1 year ago

No I think you need to cleanup your CODEBOX_API_KEY it is probably set with the .env.example text so you make sure there is not CODEBOX_API_KEY in your ENV