Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mentat python client throws mentat.errors.MentatError: Session failed #579

Open
chilaraiSxt opened this issue Jun 5, 2024 · 0 comments
Open

Comments

@chilaraiSxt
Copy link

chilaraiSxt commented Jun 5, 2024

Hi, I am trying out Mentat Python client but I believe it isnt able to create a session. I assume it's a FastAPI error

The code below confirms that my AZURE_OPENAI_KEY and AZURE_OPENAI_ENDPOINT. The same error happens with OPENAI_API_KEY. And yes, with AZURE I didnt use the OPENAI_API_KEY.

Till Mentat version 1.0.13, the code works well with OPENAI_API_KEY and generates the required code but, I think there is an issue with the versions after that.

  • Python: 3.11.7
  • Mentat version: 1.0.18

Here is the code

import os
from mentat import Mentat

async def UseMentat():

    keyEnv = os.getenv("AZURE_OPENAI_KEY")
    pathEnv = os.getenv("AZURE_OPENAI_ENDPOINT")
    print(keyEnv, pathEnv)

    # CODE GEN TEST
    dataPath = "a.js"

    finalPrompt = f"Write a code in node.js to add two numbers. Then save the output to {dataPath}"

    # Interact with Mentat
    client = Mentat(paths=["README.md"])
    await client.startup()
    await client.call_mentat_auto_accept(finalPrompt)
    await client.shutdown()

    return {"code": 200}

Here are the error logs

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/python_client/client.py", line 73, in call_mentat
    return await self._call_mentat_task
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/python_client/client.py", line 60, in _call_mentat
    await self.wait_for_edit_completion()
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/python_client/client.py", line 85, in wait_for_edit_completion
    await self.session.stream.recv(channel="edits_complete")
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/session_stream.py", line 146, in recv
    async for event in subscriber:
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/broadcast.py", line 27, in __aiter__
    yield await self.get()
          ^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/broadcast.py", line 32, in get
    item = await self._queue.get()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/queues.py", line 158, in get
    await getter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/routing.py", line 299, in handle
    await self.app(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/routing.py", line 79, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 299, in app
    raise e
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 294, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 193, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Tests/mentat-projects/main.py", line 18, in userMentat
    return asyncio.run(UseMentat())
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Tests/mentat-projects/usementat.py", line 21, in UseMentat
    await client.call_mentat_auto_accept(finalPrompt)
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/python_client/client.py", line 81, in call_mentat_auto_accept
    await self.call_mentat("y")
  File "/Tests/mentat-projects/.venv/lib/python3.11/site-packages/mentat/python_client/client.py", line 76, in call_mentat
    raise MentatError("Session failed")
mentat.errors.MentatError: Session failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant