Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Fix summarization happening in first cycle (Significant-Gravitas#4719)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynehamadi authored Jun 17, 2023
1 parent d923004 commit 0b6fec4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
26 changes: 0 additions & 26 deletions autogpt/json_utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 3 additions & 7 deletions autogpt/memory/message_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
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
Expand Down Expand Up @@ -105,8 +101,8 @@ def per_cycle(self, messages: list[Message] | None = None):
)
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"

Expand Down

0 comments on commit 0b6fec4

Please sign in to comment.