Skip to content

Commit

Permalink
send elements and actions concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed Oct 23, 2023
1 parent f8e649a commit 2f201e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions backend/chainlit/langchain/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions backend/chainlit/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions cypress/e2e/file_element/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]);
});
});
});

0 comments on commit 2f201e2

Please sign in to comment.