mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-10 00:34:30 +01:00
Fix summarization happening in first cycle (#4719)
This commit is contained in:
@@ -67,29 +67,3 @@ def validate_json(
|
||||
logger.debug("The JSON object is valid.")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def validate_json_string(json_string: str, schema_name: str) -> dict | None:
|
||||
"""
|
||||
:type schema_name: object
|
||||
:param schema_name: str
|
||||
:type json_object: object
|
||||
"""
|
||||
|
||||
try:
|
||||
json_loaded = json.loads(json_string)
|
||||
if not validate_json(json_loaded, schema_name):
|
||||
return None
|
||||
return json_loaded
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def is_string_valid_json(json_string: str, schema_name: str) -> bool:
|
||||
"""
|
||||
:type schema_name: object
|
||||
:param schema_name: str
|
||||
:type json_object: object
|
||||
"""
|
||||
|
||||
return validate_json_string(json_string, schema_name) is not None
|
||||
|
||||
@@ -9,11 +9,7 @@ if TYPE_CHECKING:
|
||||
from autogpt.agent import Agent
|
||||
|
||||
from autogpt.config import Config
|
||||
from autogpt.json_utils.utilities import (
|
||||
LLM_DEFAULT_RESPONSE_FORMAT,
|
||||
extract_json_from_response,
|
||||
is_string_valid_json,
|
||||
)
|
||||
from autogpt.json_utils.utilities import extract_json_from_response
|
||||
from autogpt.llm.base import ChatSequence, Message, MessageRole, MessageType
|
||||
from autogpt.llm.providers.openai import OPEN_AI_CHAT_MODELS
|
||||
from autogpt.llm.utils import count_string_tokens, create_chat_completion
|
||||
@@ -105,8 +101,8 @@ class MessageHistory:
|
||||
)
|
||||
result_message = messages[i + 1]
|
||||
try:
|
||||
assert is_string_valid_json(
|
||||
ai_message.content, LLM_DEFAULT_RESPONSE_FORMAT
|
||||
assert (
|
||||
extract_json_from_response(ai_message.content) != {}
|
||||
), "AI response is not a valid JSON object"
|
||||
assert result_message.type == "action_result"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user