refactor: Modify instruction in prompt for increased JSON output reliability
- Update the instruction in the prompt strategy to ensure the response is pure JSON. - Remove unnecessary text and make the instruction clearer. - Also update the error logging to include the received JSON content. This commit refactors the code in the `one_shot.py` file and the `utilities.py` file.pull/6497/head
parent
b8b792e844
commit
775a27eea0
|
@ -315,12 +315,9 @@ class OneShotAgentPromptStrategy(PromptStrategy):
|
|||
)
|
||||
|
||||
instruction = (
|
||||
(
|
||||
"Respond strictly with a JSON object containing your thoughts, "
|
||||
"and a tool_call specifying the next command to use."
|
||||
)
|
||||
"Respond with pure JSON containing your thoughts, " "and invoke a tool."
|
||||
if use_functions_api
|
||||
else "Respond strictly with a JSON object."
|
||||
else "Respond with pure JSON."
|
||||
)
|
||||
|
||||
return (
|
||||
|
|
|
@ -30,6 +30,6 @@ def extract_dict_from_response(response_content: str) -> dict[str, Any]:
|
|||
return ast.literal_eval(response_content)
|
||||
except BaseException as e:
|
||||
logger.info(f"Error parsing JSON response with literal_eval {e}")
|
||||
logger.debug(f"Invalid JSON received in response: {response_content}")
|
||||
logger.debug(f"Invalid JSON received in response:\n{response_content}")
|
||||
# TODO: How to raise an error here without causing the program to exit?
|
||||
return {}
|
||||
|
|
Loading…
Reference in New Issue