Skip to content
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

Better response parsing #385

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/agents/action/action.py
Expand Up @@ -25,11 +25,9 @@ def render(

def validate_response(self, response: str):
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()

try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand Down
4 changes: 1 addition & 3 deletions src/agents/answer/answer.py
Expand Up @@ -27,10 +27,8 @@ def render(
def validate_response(self, response: str):
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()

try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand Down
4 changes: 1 addition & 3 deletions src/agents/decision/decision.py
Expand Up @@ -17,11 +17,9 @@ def render(self, prompt: str) -> str:

def validate_response(self, response: str):
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()

try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand Down
4 changes: 1 addition & 3 deletions src/agents/internal_monologue/internal_monologue.py
Expand Up @@ -17,11 +17,9 @@ def render(self, current_prompt: str) -> str:

def validate_response(self, response: str):
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()

try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand Down
3 changes: 1 addition & 2 deletions src/agents/researcher/researcher.py
Expand Up @@ -25,9 +25,8 @@ def render(self, step_by_step_plan: str, contextual_keywords: str) -> str:
def validate_response(self, response: str) -> dict | bool:
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()
try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand Down
8 changes: 2 additions & 6 deletions src/agents/runner/runner.py
Expand Up @@ -53,11 +53,9 @@ def render_rerunner(

def validate_response(self, response: str):
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()

try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand All @@ -69,13 +67,11 @@ def validate_response(self, response: str):

def validate_rerunner_response(self, response: str):
response = response.strip().replace("```json", "```")

if response.startswith("```") and response.endswith("```"):
response = response[3:-3].strip()

print(response)

try:
response = response.split("```")[1].split("```")[0]
response = json.loads(response)
except Exception as _:
return False
Expand Down