diff --git a/backend/chainlit/langchain/callbacks.py b/backend/chainlit/langchain/callbacks.py index 2bdd91b8eb..384cbf8bd1 100644 --- a/backend/chainlit/langchain/callbacks.py +++ b/backend/chainlit/langchain/callbacks.py @@ -91,12 +91,12 @@ def convert_role(role: str): return "user" elif role in ["system", "SystemMessage", "SystemMessagePromptTemplate"]: return "system" - elif role in ["ai", "AIMessage", "AIMessagePromptTemplate"]: + elif role in ["ai", "AIMessage", "AIMessageChunk", "AIMessagePromptTemplate"]: return "assistant" elif role in ["function", "FunctionMessage", "FunctionMessagePromptTemplate"]: return "function" else: - raise ValueError(f"Unsupported role {role}") + return "assistant" def convert_message(message: BaseMessage, template: Optional[str] = None): diff --git a/backend/chainlit/message.py b/backend/chainlit/message.py index 893efdbdb5..91a2a80beb 100644 --- a/backend/chainlit/message.py +++ b/backend/chainlit/message.py @@ -266,11 +266,12 @@ async def send(self) -> str: if not self.parent_id: context.session.root_message = self - for action in self.actions: - await action.send(for_id=id) + # Create tasks for all actions and elements + tasks = [action.send(for_id=id) for action in self.actions] + tasks.extend(element.send(for_id=id) for element in self.elements) - for element in self.elements: - await element.send(for_id=id) + # Run all tasks concurrently + await asyncio.gather(*tasks) return id diff --git a/cypress/e2e/file_element/spec.cy.ts b/cypress/e2e/file_element/spec.cy.ts index c661e5fd94..50f74440c7 100644 --- a/cypress/e2e/file_element/spec.cy.ts +++ b/cypress/e2e/file_element/spec.cy.ts @@ -9,9 +9,17 @@ describe('file', () => { cy.get('.message').should('have.length', 1); cy.get('.message').eq(0).find('.inline-file').should('have.length', 4); - cy.get('.inline-file').eq(0).should('have.attr', 'download', 'example.mp4'); - cy.get('.inline-file').eq(1).should('have.attr', 'download', 'cat.jpeg'); - cy.get('.inline-file').eq(2).should('have.attr', 'download', 'hello.py'); - cy.get('.inline-file').eq(3).should('have.attr', 'download', 'example.mp3'); + cy.get('.inline-file').should(($files) => { + const downloads = $files + .map((i, el) => Cypress.$(el).attr('download')) + .get(); + + expect(downloads).to.have.members([ + 'example.mp4', + 'cat.jpeg', + 'hello.py', + 'example.mp3' + ]); + }); }); });