mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-30 23:28:35 +00:00
fix: replace deprecated method and add missing decorator (#2072)
Co-authored-by: songguodong <songguodong@songguodongdeMacBook-Air.local> Co-authored-by: aries_ckt <916701291@qq.com>
This commit is contained in:
parent
c398fb64c4
commit
253c367ceb
@ -72,7 +72,7 @@ class ActionOutput(BaseModel):
|
||||
"""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."""
|
||||
@ -181,10 +181,12 @@ class Action(ABC, Generic[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(
|
||||
|
@ -23,7 +23,7 @@ class DefaultGptsPlansMemory(GptsPlansMemory):
|
||||
|
||||
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))
|
||||
@ -36,7 +36,7 @@ class DefaultGptsPlansMemory(GptsPlansMemory):
|
||||
"""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):
|
||||
@ -47,7 +47,7 @@ class DefaultGptsPlansMemory(GptsPlansMemory):
|
||||
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))
|
||||
@ -105,7 +105,7 @@ class DefaultGptsMessageMemory(GptsMessageMemory):
|
||||
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):
|
||||
@ -123,11 +123,11 @@ class DefaultGptsMessageMemory(GptsMessageMemory):
|
||||
"""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):
|
||||
@ -137,7 +137,7 @@ class DefaultGptsMessageMemory(GptsMessageMemory):
|
||||
|
||||
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))
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Agent operator define."""
|
||||
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
@ -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")
|
||||
@ -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")
|
||||
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user