Skip to content

Commit

Permalink
fix: replace deprecated method and add missing decorator (#2072)
Browse files Browse the repository at this point in the history
Co-authored-by: songguodong <[email protected]>
Co-authored-by: aries_ckt <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent c398fb6 commit 253c367
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions dbgpt/agent/core/action/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def from_dict(
"""Convert dict to ActionOutput object."""
if not param:
return None
return cls.parse_obj(param)
return cls.model_validate(param)

def to_dict(self) -> Dict[str, Any]:
"""Convert the object to a dictionary."""
Expand Down Expand Up @@ -181,10 +181,12 @@ def _input_convert(self, ai_message: str, cls: Type[T]) -> T:
if get_origin(cls) == list:
inner_type = get_args(cls)[0]
typed_cls = cast(Type[BaseModel], inner_type)
return [typed_cls.parse_obj(item) for item in json_result] # type: ignore
return [
typed_cls.model_validate(item) for item in json_result
] # type: ignore
else:
typed_cls = cast(Type[BaseModel], cls)
return typed_cls.parse_obj(json_result)
return typed_cls.model_validate(json_result)

@abstractmethod
async def run(
Expand Down
14 changes: 7 additions & 7 deletions dbgpt/agent/core/memory/gpts/default_gpts_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def batch_save(self, plans: list[GptsPlan]):

def get_by_conv_id(self, conv_id: str) -> List[GptsPlan]:
"""Get plans by conv_id."""
result = self.df.query(f"conv_id==@conv_id") # noqa: F541
result = self.df.query("conv_id==@conv_id") # noqa: F541
plans = []
for row in result.itertuples(index=False, name=None):
row_dict = dict(zip(self.df.columns, row))
Expand All @@ -36,7 +36,7 @@ def get_by_conv_id_and_num(
"""Get plans by conv_id and task number."""
task_nums_int = [int(num) for num in task_nums] # noqa:F841
result = self.df.query( # noqa
f"conv_id==@conv_id and sub_task_num in @task_nums_int" # noqa
"conv_id==@conv_id and sub_task_num in @task_nums_int" # noqa
)
plans = []
for row in result.itertuples(index=False, name=None):
Expand All @@ -47,7 +47,7 @@ def get_by_conv_id_and_num(
def get_todo_plans(self, conv_id: str) -> List[GptsPlan]:
"""Get unfinished planning steps."""
todo_states = [Status.TODO.value, Status.RETRYING.value] # noqa: F841
result = self.df.query(f"conv_id==@conv_id and state in @todo_states") # noqa
result = self.df.query("conv_id==@conv_id and state in @todo_states") # noqa
plans = []
for row in result.itertuples(index=False, name=None):
row_dict = dict(zip(self.df.columns, row))
Expand Down Expand Up @@ -105,7 +105,7 @@ def append(self, message: GptsMessage):
def get_by_agent(self, conv_id: str, agent: str) -> Optional[List[GptsMessage]]:
"""Get all messages sent or received by the agent in the conversation."""
result = self.df.query(
f"conv_id==@conv_id and (sender==@agent or receiver==@agent)" # noqa: F541
"conv_id==@conv_id and (sender==@agent or receiver==@agent)" # noqa: F541
)
messages = []
for row in result.itertuples(index=False, name=None):
Expand All @@ -123,11 +123,11 @@ def get_between_agents(
"""Get all messages between two agents in the conversation."""
if current_goal:
result = self.df.query(
f"conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1)) and current_goal==@current_goal" # noqa
"conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1)) and current_goal==@current_goal" # noqa
)
else:
result = self.df.query(
f"conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1))" # noqa
"conv_id==@conv_id and ((sender==@agent1 and receiver==@agent2) or (sender==@agent2 and receiver==@agent1))" # noqa
)
messages = []
for row in result.itertuples(index=False, name=None):
Expand All @@ -137,7 +137,7 @@ def get_between_agents(

def get_by_conv_id(self, conv_id: str) -> List[GptsMessage]:
"""Get all messages in the conversation."""
result = self.df.query(f"conv_id==@conv_id") # noqa: F541
result = self.df.query("conv_id==@conv_id") # noqa: F541
messages = []
for row in result.itertuples(index=False, name=None):
row_dict = dict(zip(self.df.columns, row))
Expand Down
4 changes: 4 additions & 0 deletions dbgpt/agent/core/plan/awel/agent_operator_resource.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Agent operator define."""

import json
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -146,6 +147,7 @@ class AWELAgentKnowledgeResource(AgentResource):
"""AWELAgentKnowledgeResource."""

@model_validator(mode="before")
@classmethod
def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""Pre fill the agent ResourceType."""
value = values.pop("agent_resource_value")
Expand Down Expand Up @@ -191,6 +193,7 @@ class AgentPrompt(BaseModel):
code: str

@model_validator(mode="before")
@classmethod
def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""Pre fill the agent ResourceType."""
code = values.pop("agent_prompt_code")
Expand Down Expand Up @@ -243,6 +246,7 @@ class AWELAgentConfig(LLMConfig):
"""AWEL Agent Config."""

@model_validator(mode="before")
@classmethod
def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""Prefill the agent ResourceType."""
strategy_context = values.pop("strategy_context")
Expand Down

0 comments on commit 253c367

Please sign in to comment.