OpenNyAI / Jugalbandi-Manager

Jugalbandi (JB) Manager is a full AI-powered conversational chatbot platform. It's platform agnostic and can serve multiple channels such as WhatsApp or custom web interfaces. It can handle conversations in both text and voice across any language. It comes with Bhashini Speech models out of the box and can failover to Azure.
https://opennyai.github.io/Jugalbandi-Manager/
Apache License 2.0
19 stars 21 forks source link

[Bug]: Error in Chats Tab; AttributeError: type object 'JBSession' has no attribute 'user' #148

Closed kanak8278 closed 1 month ago

kanak8278 commented 1 month ago

Describe the bug

AttributeError: type object 'JBSession' has no attribute 'user'

Endpoint: http://localhost:4173/chat image The chats section is empty.

Error in api service. The error is due to the change in the column/table.

Steps to reproduce

Up the JBManager and go to http://localhost:4173/chat

Expected Behavior

Should return all the chats in the ChatBot.

Screenshots and logs

api-1 | INFO: 172.18.0.1:47506 - "GET /v1/bots HTTP/1.1" 200 OK api-1 | INFO: 172.18.0.1:47520 - "GET /v1/chats/6f5371a3-424a-43d4-811c-5c3e40516e29 HTTP/1.1" 500 Internal Server Error api-1 | ERROR: Exception in ASGI application api-1 | Traceback (most recent call last): api-1 | File "/app/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi api-1 | result = await app( # type: ignore[func-returns-value] api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ api-1 | File "/app/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__ api-1 | return await self.app(scope, receive, send) api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ api-1 | File "/app/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__ api-1 | await super().__call__(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/applications.py", line 116, in __call__ api-1 | await self.middleware_stack(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__ api-1 | raise exc api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__ api-1 | await self.app(scope, receive, _send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 91, in __call__ api-1 | await self.simple_response(scope, receive, send, request_headers=headers) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 146, in simple_response api-1 | await self.app(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__ api-1 | await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app api-1 | raise exc api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app api-1 | await app(scope, receive, sender) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 746, in __call__ api-1 | await route.handle(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle api-1 | await self.app(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 75, in app api-1 | await wrap_app_handling_exceptions(app, request)(scope, receive, send) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app api-1 | raise exc api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app api-1 | await app(scope, receive, sender) api-1 | File "/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 70, in app api-1 | response = await func(request) api-1 | ^^^^^^^^^^^^^^^^^^^ api-1 | File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 299, in app api-1 | raise e api-1 | File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 294, in app api-1 | raw_response = await run_endpoint_function( api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ api-1 | File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function api-1 | return await dependant.call(**values) api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ api-1 | File "/app/app/routers/v1/__init__.py", line 104, in get_chats api-1 | chats = await get_chat_history(bot_id, skip, limit) api-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ api-1 | File "/app/app/crud.py", line 79, in get_chat_history api-1 | .options(joinedload(JBSession.user)) api-1 | ^^^^^^^^^^^^^^ api-1 | AttributeError: type object 'JBSession' has no attribute 'user'

Additional Information

No response

kanak8278 commented 1 month ago

Plan

Ways to Solve:

code-with-om commented 1 month ago

@kanak8278 I'm going to work on this issue.

kanak8278 commented 1 month ago

@code-with-om Any update?

code-with-om commented 1 month ago

This is done. Fixed the issue on PR-157

shreypandey commented 1 month ago

The crud operations are fixed. But the messages are still not rendering in the UI.

Fix required:

  1. Insert message in json format in the JBMessage Table. We have to update the create_message calls appropriately.
  2. Update the frontend code to render each component properly. We have to update the loadMessage function in chat.tsx.
shreypandey commented 1 month ago

@code-with-om Please consider the following message objects as arguments while doing changes in loadMessage:

  1. Text Message: Show as text
    {
    "id": "example_message",
    "message_type": "text",
    "turn_id": "example_turn",
    "message": {
        "body": "Hi"
    },
    "is_user_sent": true
    }
  2. Audio Message: Show as audio media
    {
    "id": "example_message",
    "message_type": "audio",
    "turn_id": "example_turn",
    "message": {
        "media_url": "example_media_url_here"
    },
    "is_user_sent": false
    }
  3. Option List: Show as a list of options which user will see after clicking on a button.
    {
    "id": "example_message",
    "message_type": "option_list",
    "turn_id": "example_turn",
    "message": {
        "header": "",
        "body": "Would you like to buy a car, service your car, test drive, buy accessories or parts, or get a warranty and protection plan?",
        "footer": "",
        "button_text": "Service Select",
        "list_title": "Service Select",
        "options": [
            {
                "option_id": "1",
                "option_text": "Buy a Car"
            },
            {
                "option_id": "2",
                "option_text": "Service Car"
            },
            {
                "option_id": "3",
                "option_text": "Test Drive"
            },
            {
                "option_id": "4",
                "option_text": "Buy Accessories or Parts"
            },
            {
                "option_id": "5",
                "option_text": "Warranty and Protection Plan"
            }
        ]
    },
    "is_user_sent": false
    }
  4. Button Message: Each Option is shown as separate button
    {
    "id": "example_message",
    "message_type": "button",
    "turn_id": "example_turn",
    "message": {
        "header": "",
        "body": "What time of day would you prefer? Morning, afternoon, or evening?",
        "footer": "",
        "options": [
            {
                "option_id": "1",
                "option_text": "Morning"
            },
            {
                "option_id": "2",
                "option_text": "Afternoon"
            },
            {
                "option_id": "3",
                "option_text": "Evening"
            }
        ]
    },
    "is_user_sent": false
    }
  5. Interactive Reply: Show option text as text.
    {
    "id": "example_msg",
    "message_type": "interactive_reply",
    "turn_id": "example_turn",
    "message": {
        "options": [
            {
                "option_id": "1",
                "option_text": "Morning"
            }
        ]
    },
    "is_user_sent": true
    }
code-with-om commented 1 month ago

Fixed in PR -162