-
Notifications
You must be signed in to change notification settings - Fork 79
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
Multiple utterances #1114
Multiple utterances #1114
Conversation
WalkthroughWalkthroughThe update involves refactoring the logic for bot responses in a Python project, streamlining the response handling into two distinct functions for text and JSON. Additionally, the system's response dispatching mechanism has been enhanced. New integration tests have been added to ensure the updated Python script actions work correctly with multiple utterances and integer responses. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- kairon/shared/actions/utils.py (1 hunks)
- tests/integration_test/action_service_test.py (1 hunks)
Additional comments: 4
kairon/shared/actions/utils.py (1)
- 558-562: The changes to the
handle_utter_bot_response
method correctly handle the case wherebot_response
is a list by combining the list items into a single string separated by newlines. This aligns with the PR's objective to allow sending multiple utterances from a Python script action.tests/integration_test/action_service_test.py (3)
130-130: The assertion for the custom response structure seems correct, but ensure that the actual implementation of the
handle_utter_bot_response
function supports this format.131-207: The test case
test_pyscript_action_execution_with_multiple_utterances
is well-structured. However, there are a few points to consider:
- Ensure that the
Actions
andPyscriptActionConfig
classes handle the creation and saving of actions correctly.- The
responses.add
method is mocked correctly, but verify that the endpoint and the expected response match the actual service behavior.- The assertion on line 206 checks if the response is a single string with newline characters. Confirm that this is the expected format for the bot's response.
- 209-285: The test case
test_pyscript_action_execution_with_multiple_integer_utterances
is similar to the previous one, with the following observations:
- The setup and mocking are consistent with the previous test.
- The assertion on line 284 checks if the response is a single string with newline characters separating the numbers. Verify that this is the intended behavior, as it may not be the most user-friendly format for numeric responses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- kairon/shared/actions/utils.py (1 hunks)
- tests/integration_test/action_service_test.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- kairon/shared/actions/utils.py
- tests/integration_test/action_service_test.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- kairon/shared/actions/utils.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- kairon/shared/actions/utils.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- kairon/shared/actions/utils.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- kairon/shared/actions/utils.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tests/integration_test/action_service_test.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/integration_test/action_service_test.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- kairon/shared/actions/utils.py (1 hunks)
Additional comments: 2
kairon/shared/actions/utils.py (2)
- 547-582: The
handle_utter_bot_response
function has been refactored to usehandle_text_response
andhandle_json_response
to handle different types of bot responses. Theset_dispatcher_response
function has been added to set the dispatcher response based on the dispatch type. This refactoring improves the modularity and readability of the code. However, it's important to ensure that the dispatcher's behavior remains consistent with these changes.Verification successful
The executed scripts have successfully verified the usage of the new
set_dispatcher_response
function and the refactoredhandle_text_response
andhandle_json_response
functions within thekairon/shared/actions/utils.py
file. The results show that these functions are being called, indicating that the refactoring has been integrated into the codebase as intended.Based on the script outputs, we can confirm that the changes made to the
utils.py
file are consistent with the rest of the codebase, and the dispatcher's behavior has been updated to use the new utility functions for handling responses.* 560-568: The `handle_text_response` method has been added to handle text responses. It checks if the `bot_response` is a list and iterates over it, dispatching each message appropriately. This method enhances the ability to handle multiple messages in a single response, which aligns with the PR's objective to enable sending multiple utterances from a Python script action.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the dispatcher's behavior is consistent with the changes made to the response handling functions. # This script checks for the usage of the dispatcher's utter_message method with json_message and text parameters. rg --type python 'dispatcher.utter_message' -- '-json_message' '-text'Length of output: 97
Script:
#!/bin/bash # Verify that the dispatcher's behavior is consistent with the changes made to the response handling functions. # This script checks for the usage of the dispatcher's utter_message method with json_message and text parameters. rg 'dispatcher.utter_message' -- '-json_message' '-text'Length of output: 152
Script:
#!/bin/bash # Verify that the dispatcher's behavior is consistent with the changes made to the response handling functions. # This script checks for the usage of the dispatcher's utter_message method, excluding lines that contain 'json_message' or 'text'. rg 'dispatcher.utter_message' | rg -v 'json_message|text'Length of output: 1176
Script:
#!/bin/bash # Verify the usage of the new set_dispatcher_response function and the refactored handle_text_response and handle_json_response functions. rg 'ActionUtility.set_dispatcher_response' 'kairon/shared/actions/utils.py' rg 'ActionUtility.handle_text_response' 'kairon/shared/actions/utils.py' rg 'ActionUtility.handle_json_response' 'kairon/shared/actions/utils.py'Length of output: 904
def handle_json_response(dispatcher: CollectingDispatcher, bot_response: Any): | ||
from json import JSONDecodeError | ||
|
||
message = None | ||
try: | ||
bot_response = json.loads(bot_response) if isinstance(bot_response, str) else bot_response | ||
ActionUtility.set_dispatcher_response(dispatcher, bot_response, DispatchType.json.value) | ||
except JSONDecodeError as e: | ||
message = f'Failed to convert http response to json: {str(e)}' | ||
logger.exception(e) | ||
ActionUtility.set_dispatcher_response(dispatcher, bot_response, DispatchType.text.value) | ||
return message, bot_response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the absence of direct references to the handle_json_response
method in the test files, it appears that there are no specific test cases for this method, or they do not call the method directly. This could indicate a gap in the test coverage for the handle_json_response
method.
Analysis chain
The handle_json_response
method has been added to handle JSON responses. It attempts to parse the bot_response
as JSON and dispatches it. If parsing fails, it logs the exception and dispatches the response as text. This method should be tested to ensure that it handles various JSON structures and parsing errors gracefully.
I will correct the script to search for the handle_json_response
method without specifying the file type, allowing ripgrep
to automatically detect Python files.
To further verify the handling of various JSON structures and parsing errors by the handle_json_response
method, I will search for test cases that may be invoking this method.
Given the absence of direct references to the handle_json_response
method in the test files, I will now search for indirect references or patterns that might indicate testing of JSON response handling, such as tests that check for JSON parsing errors or dispatching logic.
To determine if the handle_json_response
method is indirectly tested, I will examine the action_test.py
file more closely, looking for tests that might involve JSON response handling.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify that the handle_json_response method handles various JSON structures and parsing errors gracefully.
# This script checks for the usage of the handle_json_response method and suggests creating test cases for different JSON structures.
rg --type python 'handle_json_response'
Length of output: 70
Script:
#!/bin/bash
# Search for the usage of the handle_json_response method in the codebase.
rg 'handle_json_response'
Length of output: 271
Script:
#!/bin/bash
# Search for test cases that involve the handle_json_response method.
rg 'handle_json_response' -- 'tests/'
Length of output: 35
Script:
#!/bin/bash
# Search for test cases that might indirectly involve the handle_json_response method by looking for JSON parsing errors or dispatching logic.
rg 'JSONDecodeError' -- 'tests/'
rg 'dispatcher' -- 'tests/'
Length of output: 7466
Script:
#!/bin/bash
# Examine the action_test.py file for tests related to JSON response handling.
cat tests/unit_test/action/action_test.py
Length of output: 239700
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved
Added code for sending multiple utterances from pyscript action.
Summary by CodeRabbit
Refactor
Tests