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

refactor(agent): Refactor & improve create_chat_completion #7082

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
CompletionModelFunction,
)
from autogpt.core.utils.json_schema import JSONSchema
from autogpt.core.utils.json_utils import json_loads

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -203,9 +202,7 @@
f"LLM did not call {self._create_agent_function.name} function; "
"agent profile creation failed"
)
arguments: object = json_loads(
response_content.tool_calls[0].function.arguments
)
arguments: object = response_content.tool_calls[0].function.arguments

Check warning on line 205 in autogpts/autogpt/autogpt/agent_factory/profile_generator.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/agent_factory/profile_generator.py#L205

Added line #L205 was not covered by tests
ai_profile = AIProfile(
ai_name=arguments.get("name"),
ai_role=arguments.get("description"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
CompletionModelFunction,
)
from autogpt.core.utils.json_schema import JSONSchema
from autogpt.core.utils.json_utils import extract_dict_from_json, json_loads
from autogpt.core.utils.json_utils import extract_dict_from_json
from autogpt.prompts.utils import format_numbered_list, indent


Expand Down Expand Up @@ -436,7 +436,7 @@ def extract_command(
raise InvalidAgentResponseError("No 'tool_calls' in assistant reply")
assistant_reply_json["command"] = {
"name": assistant_reply.tool_calls[0].function.name,
"args": json_loads(assistant_reply.tool_calls[0].function.arguments),
"args": assistant_reply.tool_calls[0].function.arguments,
}
try:
if not isinstance(assistant_reply_json, dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CompletionModelFunction,
)
from autogpt.core.utils.json_schema import JSONSchema
from autogpt.core.utils.json_utils import json_loads

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -195,9 +194,7 @@
f"LLM did not call {self._create_plan_function.name} function; "
"plan creation failed"
)
parsed_response: object = json_loads(
response_content.tool_calls[0].function.arguments
)
parsed_response: object = response_content.tool_calls[0].function.arguments

Check warning on line 197 in autogpts/autogpt/autogpt/core/planning/prompt_strategies/initial_plan.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/core/planning/prompt_strategies/initial_plan.py#L197

Added line #L197 was not covered by tests
parsed_response["task_list"] = [
Task.parse_obj(task) for task in parsed_response["task_list"]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
CompletionModelFunction,
)
from autogpt.core.utils.json_schema import JSONSchema
from autogpt.core.utils.json_utils import json_loads

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -141,9 +140,7 @@
f"LLM did not call {self._create_agent_function} function; "
"agent profile creation failed"
)
parsed_response = json_loads(
response_content.tool_calls[0].function.arguments
)
parsed_response = response_content.tool_calls[0].function.arguments

Check warning on line 143 in autogpts/autogpt/autogpt/core/planning/prompt_strategies/name_and_goals.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/core/planning/prompt_strategies/name_and_goals.py#L143

Added line #L143 was not covered by tests
except KeyError:
logger.debug(f"Failed to parse this response content: {response_content}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CompletionModelFunction,
)
from autogpt.core.utils.json_schema import JSONSchema
from autogpt.core.utils.json_utils import json_loads

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -188,9 +187,7 @@
raise ValueError("LLM did not call any function")

function_name = response_content.tool_calls[0].function.name
function_arguments = json_loads(
response_content.tool_calls[0].function.arguments
)
function_arguments = response_content.tool_calls[0].function.arguments

Check warning on line 190 in autogpts/autogpt/autogpt/core/planning/prompt_strategies/next_ability.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/core/planning/prompt_strategies/next_ability.py#L190

Added line #L190 was not covered by tests
parsed_response = {
"motivation": function_arguments.pop("motivation"),
"self_criticism": function_arguments.pop("self_criticism"),
Expand Down
Loading
Loading