fix conflict

pull/1866/head
Merwane Hamadi 2023-04-16 11:36:51 -07:00
parent 45a2dea042
commit fdb0a06803
2 changed files with 0 additions and 54 deletions

View File

@ -3,58 +3,13 @@ from __future__ import annotations
import contextlib
import json
<<<<<<< HEAD
import regex
from colorama import Fore
from autogpt.logs import logger
=======
from typing import Optional
>>>>>>> 67f32105 (Remove deprecated function from bracket_termination.py)
from autogpt.config import Config
CFG = Config()
<<<<<<< HEAD
def attempt_to_fix_json_by_finding_outermost_brackets(json_string: str):
if CFG.speak_mode and CFG.debug_mode:
say_text(
"I have received an invalid JSON response from the OpenAI API. "
"Trying to fix it now."
)
logger.typewriter_log("Attempting to fix JSON by finding outermost brackets\n")
try:
json_pattern = regex.compile(r"\{(?:[^{}]|(?R))*\}")
json_match = json_pattern.search(json_string)
if json_match:
# Extract the valid JSON object from the string
json_string = json_match.group(0)
logger.typewriter_log(
title="Apparently json was fixed.", title_color=Fore.GREEN
)
if CFG.speak_mode and CFG.debug_mode:
say_text("Apparently json was fixed.")
else:
raise ValueError("No valid JSON object found")
except (json.JSONDecodeError, ValueError):
if CFG.debug_mode:
logger.error(f"Error: Invalid JSON: {json_string}\n")
if CFG.speak_mode:
say_text("Didn't work. I will have to ignore this response then.")
logger.error("Error: Invalid JSON, setting it to empty JSON now.\n")
json_string = {}
return json_string
def balance_braces(json_string: str) -> str | None:
=======
def balance_braces(json_string: str) -> Optional[str]:
>>>>>>> 67f32105 (Remove deprecated function from bracket_termination.py)
"""
Balance the braces in a JSON string.

View File

@ -3,14 +3,9 @@ from __future__ import annotations
import contextlib
import json
<<<<<<< HEAD
from typing import Any
=======
from typing import Any, Dict, Union
from colorama import Fore
from regex import regex
>>>>>>> d3d8253b (Refactor parsing module and move JSON fix function to appropriate location)
from autogpt.config import Config
from autogpt.json_fixes.auto_fix import fix_json
from autogpt.json_fixes.bracket_termination import balance_braces
@ -115,11 +110,7 @@ def fix_and_parse_json(
def try_ai_fix(
try_to_fix_with_gpt: bool, exception: Exception, json_to_load: str
<<<<<<< HEAD
) -> str | dict[Any, Any]:
=======
) -> Dict[Any, Any]:
>>>>>>> d3d8253b (Refactor parsing module and move JSON fix function to appropriate location)
"""Try to fix the JSON with the AI
Args: