Skip to content

Commit

Permalink
Migrate autogpt/agents/prompt_strategies/code_flow.py to Pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Jul 4, 2024
1 parent 8b1d416 commit 2c4afd4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions autogpt/autogpt/agents/prompt_strategies/code_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(
):
self.config = configuration
self.response_schema = JSONSchema.from_dict(
CodeFlowAgentActionProposal.schema()
CodeFlowAgentActionProposal.model_json_schema()
)
self.logger = logger
self.commands: Sequence[Command] = [] # Sequence -> disallow list modification
Expand Down Expand Up @@ -175,7 +175,7 @@ def build_system_prompt(
)

def response_format_instruction(self) -> tuple[str, str]:
response_schema = self.response_schema.copy(deep=True)
response_schema = self.response_schema.model_copy(deep=True)
assert response_schema.properties

# Unindent for performance
Expand Down Expand Up @@ -260,7 +260,9 @@ async def parse_response_content(
)
assistant_reply_dict = extract_dict_from_json(response.content)

parsed_response = CodeFlowAgentActionProposal.parse_obj(assistant_reply_dict)
parsed_response = CodeFlowAgentActionProposal.model_validate(
assistant_reply_dict
)
if not parsed_response.python_code:
raise ValueError("python_code is empty")

Check warning on line 267 in autogpt/autogpt/agents/prompt_strategies/code_flow.py

View check run for this annotation

Codecov / codecov/patch

autogpt/autogpt/agents/prompt_strategies/code_flow.py#L267

Added line #L267 was not covered by tests

Expand Down Expand Up @@ -299,8 +301,8 @@ async def parse_response_content(
available_functions=available_functions,
).validate_code(parsed_response.python_code)

clean_response = response.copy()
clean_response.content = parsed_response.json(indent=4)
clean_response = response.model_copy()
clean_response.content = parsed_response.model_dump_json(indent=4)

# TODO: prevent combining finish with other functions
if _finish_call := re.search(
Expand Down

0 comments on commit 2c4afd4

Please sign in to comment.