-
Notifications
You must be signed in to change notification settings - Fork 955
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
LookupError in ChainlitContext: ContextVar 'local_steps' Not Found When Converting FastAPI to WSGI with a2wsgi #1494
Comments
Sorry you're experiencing issues. Could you please attach the full code and all steps required for us to replicate the problem? Written by @dosu, edited by dokterbob |
@dokterbob Thank you for your reply. The app. py code is as follows:
the my_cl_app.py code as follows:
I use gunicorn run the fastapi( a2wsgi conver to wsgi) ,looking forward to your reply! |
@dosu Any idea what's going on? |
The error you're encountering, "LookupError: ", typically occurs when the To resolve this issue, you need to ensure that the def init_ws_context(session_or_sid):
if not isinstance(session_or_sid, WebsocketSession):
session = WebsocketSession.require(session_or_sid)
else:
session = session_or_sid
context = ChainlitContext(session)
context_var.set(context)
local_steps.set([]) # Initialize local_steps with an empty list
return context
def init_http_context(thread_id=None, user=None, auth_token=None, user_env=None, client_type="webapp"):
from chainlit.data import get_data_layer
session_id = str(uuid.uuid4())
thread_id = thread_id or str(uuid.uuid4())
session = HTTPSession(
id=session_id,
thread_id=thread_id,
token=auth_token,
user=user,
client_type=client_type,
user_env=user_env,
)
context = ChainlitContext(session)
context_var.set(context)
local_steps.set([]) # Initialize local_steps with an empty list
if data_layer := get_data_layer():
if user_id := getattr(user, "id", None):
asyncio.create_task(
data_layer.update_thread(thread_id=thread_id, user_id=user_id)
)
return context By ensuring |
@dosu Could you please suggest a clearer title for the issue? |
@dosu Can you provide specific instructions on how to use it based on the code I provided above? |
To address the
By following these steps, you should be able to resolve the |
@dosu Is there any way to initialize |
I use fastapi mount chainlit,and I use a2wsgi conver to wsgi,beacase I use gunicorn。the chanlit version is 1.3.0rc1 .when I open the chainlit url,the page can open,but the page shows that " it can not connect the server ". the errror log as the follows, who can help me?
2024-10-31 17:38:59 - <ContextVar name='local_steps' at 0x7fde381385e0>
Traceback (most recent call last):
File "/opt/app/.venv/lib/python3.10/site-packages/chainlit/utils.py", line 44, in wrapper
return await user_function(**params_values)
File "/opt/app/.venv/lib/python3.10/site-packages/chainlit/step.py", line 99, in async_wrapper
async with Step(
File "/opt/app/.venv/lib/python3.10/site-packages/chainlit/step.py", line 431, in aenter
previous_steps = local_steps.get() or []
LookupError: <ContextVar name='local_steps' at 0x7fde381385e0>
2024-10-31 17:39:44 - Translated markdown file for zh-CN not found. Defaulting to chainlit.md.
2024-10-31 17:39:45 - <ContextVar name='local_steps' at 0x7fde381385e0>
The text was updated successfully, but these errors were encountered: