feat: Add product widget response#210
Conversation
2e3f74d to
64d97bd
Compare
| self.MessageType.INTERMEDIATE_STEP: "ai", | ||
| self.MessageType.AI: "ai", | ||
| self.MessageType.FUNCTION: "ai", | ||
| self.MessageType.WIDGET: "ai", |
There was a problem hiding this comment.
@dsowinski2 I'm missing some context when it comes to how this is supposed to work. Could you add a description to this PR that describes the overall concept behind widget responses, how they're generated and managed?
There was a problem hiding this comment.
I've updated description and resolved conflicts, let me know if you need more details.
4f031a5 to
4934ea9
Compare
14841e5 to
bcef640
Compare
mateus-po
left a comment
There was a problem hiding this comment.
Two minor suggestions to the PresentProductTool implementation, otherwise LGTM
| ) | ||
| all_products = [] | ||
| for id in ids: | ||
| product = self._injector.repositories.product.get_by_id(int(id)) |
There was a problem hiding this comment.
Maybe it would be a good idea to prefetch all products first? By implementing a get_by_ids(ids: list[str]) method on a product registry that would fetch all products in one DB call. Not a big issue, but would speed up the tool + would reduce the number of DB calls.
| if self._streaming: | ||
| self._injector.callbacks_handler.on_product_widget_start( | ||
| json.dumps({"number_of_products": len(ids), "message": message_to_user}) | ||
| ) |
There was a problem hiding this comment.
I am not a big fan of these 3 if self._streaming: blocks in the run method. I would do it like this:
- Define a private method like:
def _handle_streaming(step: 'start' | 'in_progress' | 'end') -> void:
if not self._streaming: return
# remaining logic based on the streaming step- use it inside of the
runmethod
It would make the code inside of the run method more readible and the whole tool class more modular.
There was a problem hiding this comment.
Or more something like this (so that you can pass the streaming message data):
def _handle_streaming(step: 'start' | 'in_progress' | 'end', data: Optional[str]) -> void:
if not self._streaming: return
# remaining logic based on the streaming step
This PR adds possibility to render a product widget.