-
Notifications
You must be signed in to change notification settings - Fork 954
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
1.2.0 breaks Custom Data Layer #1390
Comments
Hey @marketneutral! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together! In version 1.2.0, the To resolve this, you need to ensure that all required abstract methods are implemented in your custom data layer. Here's a basic example of how you might implement the from typing import Optional, Dict, Any, List, Union
import chainlit.data as cl_data
from chainlit.data.sql_alchemy import SQLAlchemyDataLayer
from chainlit.data.storage_clients import S3StorageClient
class CustomSQLAlchemyDataLayer(SQLAlchemyDataLayer):
async def get_element(self, thread_id: str, element_id: str) -> Optional["ElementDict"]:
# Implement the method logic here
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
# Usage
storage_client = S3StorageClient(bucket="your_bucket_name")
cl_data._data_layer = CustomSQLAlchemyDataLayer(conninfo="your_conninfo", storage_provider=storage_client) Make sure to replace |
Fixed in #1346 a couple weeks ago but they haven't made a new release to include it |
Please make a new release, this blocks the update for us. |
@LeonKalt @hayescode Fix is part of 1.3.0rc0. Would love feedback on that. We'll probably release 1.3.0 start of next week. |
Describe the bug
Release 1.2.0 breaks the example(s) in https://docs.chainlit.io/data-persistence/custom
To Reproduce
This is the code that works prior to 1.2.0
After 1.2.0, on startup, I get the TypeError
Could you adivse on a new example for 1.2.0?
The text was updated successfully, but these errors were encountered: