BaseDataLayer 类作为 Chainlit 框架内数据持久化操作的抽象基础。此类概述了在聊天机器人应用中管理用户、反馈、元素、步骤和线程的方法。

方法

async get_user(self, identifier: str)
协程

根据标识符获取用户。返回类型可选为 PersistedUser

async create_user(self, user: User)
协程

根据提供的 User 实例创建新用户。返回类型可选为 PersistedUser

async upsert_feedback(self, feedback: Feedback)
协程

插入或更新反馈。接受 Feedback 实例并返回字符串作为持久化反馈的标识符。

async delete_feedback(self, feedback_id: str)
协程

根据 feedback_id 删除反馈。成功则返回 True

async create_element(self, element_dict: ElementDict)
协程

向数据层添加新元素。接受 ElementDict 作为参数。

async get_element(self, thread_id: str, element_id: str)
协程

根据 thread_idelement_id 检索元素。返回类型可选为 ElementDict

async delete_element(self, element_id: str)
协程

根据标识符 element_id 删除元素。

async create_step(self, step_dict: StepDict)
协程

在数据层创建新步骤。接受 StepDict 作为参数。

async update_step(self, step_dict: StepDict)
协程

更新现有步骤。接受 StepDict 作为参数。

async delete_step(self, step_id: str)
协程

根据标识符 step_id 删除步骤。

async get_thread_author(self, thread_id: str)
协程

根据 thread_id 获取给定线程的作者。返回表示作者标识符的字符串。

async delete_thread(self, thread_id: str)
协程

根据标识符 thread_id 删除线程。

async list_threads(self, pagination: Pagination, filters: ThreadFilter)
协程

根据 paginationfilters 参数列出线程。返回 PaginatedResponse[ThreadDict]

async get_thread(self, thread_id: str)
协程

根据标识符 thread_id 检索线程。返回类型可选为 ThreadDict

async update_thread(self, thread_id: str, name: Optional[str] = None, user_id: Optional[str] = None, metadata: Optional[Dict] = None, tags: Optional[List[str]] = None)
协程

更新线程的详细信息,如名称、user_id、元数据和标签。参数大多是可选的。

async delete_user_session(self, id: str)
协程

根据标识符 id 删除用户会话。返回布尔值表示成功与否。

装饰器

queue_until_user_message()
装饰器

将某些方法排队,使其仅在接收到第一个用户消息后执行,这对于 WebsocketSessions 特别有用。

示例

由于 BaseDataLayer 的抽象性质,不进行子类化和实现抽象方法就无法直接实例化和使用它。

您可以参考自定义数据层实现指南