Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
6.86k stars 903 forks source link

Chainlit 1.2.0 breaks SQLAlchemyDataLayer #1375

Closed itonskie closed 2 days ago

itonskie commented 2 days ago

Describe the bug In Chainlit version 1.2.0, the new BaseDataLayer class has abstract methods implemented, which causes compatibility issues with SQLAlchemyDataLayer. Specifically, I encounter the following error when trying to instantiate SQLAlchemyDataLayer:

Traceback (most recent call last): File "/workspaces/Bluedrive_Chatbot_v3/bluedrive_chatbot.py", line 20, in SQLAlchemyDataLayer(conninfo=conninfo) TypeError: Can't instantiate abstract class SQLAlchemyDataLayer with abstract method get_element

To Reproduce Steps to reproduce the behavior:

  1. Use Chainlit version 1.2.0.
  2. Try to instantiate SQLAlchemyDataLayer
  3. Run the script
  4. See error

Expected behavior I expect it to instantiate SQLAlchemyDataLayer without this error

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Looked at the previous version. 1.1.404. it works up until that point

dosubot[bot] commented 2 days ago

Hey there, @itonskie! I'm here to help you with any bugs, questions, or contributions. Let's tackle this issue together while we wait for a human maintainer.

To resolve the TypeError when trying to instantiate SQLAlchemyDataLayer in Chainlit version 1.2.0 due to the abstract method get_element, ensure that the get_element method is implemented in the SQLAlchemyDataLayer class. Here is the implementation for get_element:

async def get_element(
    self, thread_id: str, element_id: str
) -> Optional["ElementDict"]:
    if self.show_logger:
        logger.info(
            f"SQLAlchemy: get_element, thread_id={thread_id}, element_id={element_id}"
        )
    query = """SELECT * FROM elements WHERE "threadId" = :thread_id AND "id" = :element_id"""
    parameters = {"thread_id": thread_id, "element_id": element_id}
    element: Union[List[Dict[str, Any]], int, None] = await self.execute_sql(
        query=query, parameters=parameters
    )
    if isinstance(element, list) and element:
        element_dict: Dict[str, Any] = element[0]
        return ElementDict(
            id=element_dict["id"],
            threadId=element_dict.get("threadId"),
            type=element_dict["type"],
            chainlitKey=element_dict.get("chainlitKey"),
            url=element_dict.get("url"),
            objectKey=element_dict.get("objectKey"),
            name=element_dict["name"],
            display=element_dict["display"],
            size=element_dict.get("size"),
            language=element_dict.get("language"),
            page=element_dict.get("page"),
            autoPlay=element_dict.get("autoPlay"),
            playerConfig=element_dict.get("playerConfig"),
            forId=element_dict.get("forId"),
            mime=element_dict.get("mime"),
        )
    else:
        return None

Ensure that the method signature matches exactly what is expected by the base class BaseDataLayer and that the class is correctly inheriting from BaseDataLayer [1][2].

Additionally, make sure that all other abstract methods from BaseDataLayer are implemented in SQLAlchemyDataLayer. These include methods like get_user, create_user, delete_feedback, upsert_feedback, create_element, delete_element, create_step, update_step, delete_step, get_thread_author, delete_thread, list_threads, get_thread, update_thread, and delete_user_session [2][3].

If the error persists, further investigation into the base class BaseDataLayer and how SQLAlchemyDataLayer is instantiated might be necessary.

To continue talking to Dosu, mention @dosu.

dokterbob commented 2 days ago

This has been solved with #1346. We'll do a fixup release soon!