chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

while login, get Unable to sign in.

Open wac81 opened this issue 1 year ago • 4 comments

while login, get Unable to sign in. 1712048483111 1712048521501

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()

wac81 avatar Apr 02 '24 09:04 wac81

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

ahmad081177 avatar Apr 17 '24 21:04 ahmad081177

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

oliverpera avatar Apr 20 '24 20:04 oliverpera

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)

wac81 avatar Apr 25 '24 09:04 wac81

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

wac81 avatar Apr 25 '24 09:04 wac81

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

qyj19920704 avatar May 24 '24 07:05 qyj19920704

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

qyj19920704 avatar May 24 '24 07:05 qyj19920704

@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.

ahmad081177 avatar May 26 '24 05:05 ahmad081177

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

wac81 avatar May 29 '24 14:05 wac81