while login, get Unable to sign in.
while login, get Unable to sign in.
and my code same as example
import chainlit as cl @cl.password_auth_callback def auth_callback(username: str, password: str): # Fetch the user matching username from your database # and compare the hashed password with the value stored in the database if (username, password) == ("admin", "admin"): user = cl.User( identifier="admin", metadata={"role": "admin", "provider": "credentials"} ) cl.user_session.set("user", user) return user
else:
return None
@cl.on_chat_start async def on_chat_start():
app_user = cl.user_session.get("user")
await cl.Message(f"Hello {app_user.identifier}").send()
Me too, facing similar issue, password_auth_callback fails thus on_chat_start is not called
My Code:
@cl.password_auth_callback
def auth_callback(username: str, password: str)-> Optional[cl.User]:
# Fetch the user matching username from your database
# and compare the hashed password with the value stored in the database
if (username, password) == ("admin", "admin"):
user = cl.User(identifier=username)
print(f"Authenticated user {username}")
return user
else:
return None
@cl.on_chat_start
def on_chat_start():
print("The chat session has started!")
chat = create_chat_system()
print("Chat system created")
cl.user_session.set("chat_system", chat)
ERROR: ERROR: Exception in ASGI application Traceback (most recent call last): File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 426, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in call return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\applications.py", line 1054, in call await super().call(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\applications.py", line 116, in call await self.middleware_stack(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\errors.py", line 186, in call raise exc File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\errors.py", line 164, in call await self.app(scope, receive, _send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\cors.py", line 91, in call await self.simple_response(scope, receive, send, request_headers=headers) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\cors.py", line 146, in simple_response await self.app(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\exceptions.py", line 62, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app raise exc File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app await app(scope, receive, sender) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 746, in call await route.handle(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 288, in handle await self.app(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 75, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app raise exc File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app await app(scope, receive, sender) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 70, in app response = await func(request) ^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\routing.py", line 299, in app raise e File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\routing.py", line 294, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\routing.py", line 191, in run_endpoint_function return await dependant.call(**values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\chainlit\server.py", line 290, in login access_token = create_jwt(user) ^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\chainlit\auth.py", line 58, in create_jwt encoded_jwt = jwt.encode(to_encode, get_jwt_secret(), algorithm="HS256") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\api_jwt.py", line 73, in encode return api_jws.encode( ^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\api_jws.py", line 160, in encode key = alg_obj.prepare_key(key) ^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\algorithms.py", line 265, in prepare_key key_bytes = force_bytes(key) ^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\utils.py", line 22, in force_bytes raise TypeError("Expected a string value") TypeError: Expected a string value
Which chainlit version do you use? This can happen due to older versions. I had the same issue. Upgrade to the latest version with:
pip install --upgrade chainlit
i got new error after upgrade
pydantic.error_wrappers.ValidationError: 1 validation error for FeaturesSettings multi_modal instance of MultiModalFeature, tuple or dict expected (type=type_error.dataclass; class_name=MultiModalFeature)
i got new error after upgrade
pydantic.error_wrappers.ValidationError: 1 validation error for FeaturesSettings multi_modal instance of MultiModalFeature, tuple or dict expected (type=type_error.dataclass; class_name=MultiModalFeature)
i solve this error ,but get same error after upgrade File "/home/wac/anaconda3/envs/ragweb2/lib/python3.11/site-packages/chainlit/context.py", line 79, in get_context raise ChainlitContextException() chainlit.context.ChainlitContextException: Chainlit context not found
i got new error after upgrade pydantic.error_wrappers.ValidationError: 1 validation error for FeaturesSettings multi_modal instance of MultiModalFeature, tuple or dict expected (type=type_error.dataclass; class_name=MultiModalFeature)
i solve this error ,but get same error after upgrade File "/home/wac/anaconda3/envs/ragweb2/lib/python3.11/site-packages/chainlit/context.py", line 79, in get_context raise ChainlitContextException() chainlit.context.ChainlitContextException: Chainlit context not found
Hello, may I ask how you solve it, I have the same problem as you
Me too, facing similar issue, password_auth_callback fails thus on_chat_start is not called
My Code:
@cl.password_auth_callback def auth_callback(username: str, password: str)-> Optional[cl.User]: # Fetch the user matching username from your database # and compare the hashed password with the value stored in the database if (username, password) == ("admin", "admin"): user = cl.User(identifier=username) print(f"Authenticated user {username}") return user else: return None@cl.on_chat_start def on_chat_start(): print("The chat session has started!") chat = create_chat_system() print("Chat system created") cl.user_session.set("chat_system", chat)ERROR: ERROR: Exception in ASGI application Traceback (most recent call last): File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 426, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in call return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\applications.py", line 1054, in call await super().call(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\applications.py", line 116, in call await self.middleware_stack(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\errors.py", line 186, in call raise exc File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\errors.py", line 164, in call await self.app(scope, receive, _send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\cors.py", line 91, in call await self.simple_response(scope, receive, send, request_headers=headers) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\cors.py", line 146, in simple_response await self.app(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\middleware\exceptions.py", line 62, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app raise exc File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app await app(scope, receive, sender) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 746, in call await route.handle(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 288, in handle await self.app(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 75, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 55, in wrapped_app raise exc File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette_exception_handler.py", line 44, in wrapped_app await app(scope, receive, sender) File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\starlette\routing.py", line 70, in app response = await func(request) ^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\routing.py", line 299, in app raise e File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\routing.py", line 294, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\fastapi\routing.py", line 191, in run_endpoint_function return await dependant.call(**values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\chainlit\server.py", line 290, in login access_token = create_jwt(user) ^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\chainlit\auth.py", line 58, in create_jwt encoded_jwt = jwt.encode(to_encode, get_jwt_secret(), algorithm="HS256") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\api_jwt.py", line 73, in encode return api_jws.encode( ^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\api_jws.py", line 160, in encode key = alg_obj.prepare_key(key) ^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\algorithms.py", line 265, in prepare_key key_bytes = force_bytes(key) ^^^^^^^^^^^^^^^^ File "d:\workdir\penvs\ask-the-doc\Lib\site-packages\jwt\utils.py", line 22, in force_bytes raise TypeError("Expected a string value") TypeError: Expected a string value
Hello, may I ask how you solve it, I have the same problem as you
@cl.password_auth_callback def auth_callback(username: str, password: str)-> Optional[cl.User]: # Fetch the user matching username from your database # and compare the hashed password with the value stored in the database if (username, password) == ("admin", "admin"): user = cl.User(identifier=username) print(f"Authenticated user {username}") return user else: return None
Now am using chainlit V 1.1.202 - it works fine. thanks.
i got new error after upgrade pydantic.error_wrappers.ValidationError: 1 validation error for FeaturesSettings multi_modal instance of MultiModalFeature, tuple or dict expected (type=type_error.dataclass; class_name=MultiModalFeature)
i solve this error ,but get same error after upgrade File "/home/wac/anaconda3/envs/ragweb2/lib/python3.11/site-packages/chainlit/context.py", line 79, in get_context raise ChainlitContextException() chainlit.context.ChainlitContextException: Chainlit context not found
Hello, may I ask how you solve it, I have the same problem as you
clear your project and update