DB-GPT/dbgpt/serve/agent/agents/dbgpts.py
明天 b124ecc10b
feat: (0.6)New UI (#1855)
Co-authored-by: 夏姜 <wenfengjiang.jwf@digital-engine.com>
Co-authored-by: aries_ckt <916701291@qq.com>
Co-authored-by: wb-lh513319 <wb-lh513319@alibaba-inc.com>
Co-authored-by: csunny <cfqsunny@163.com>
2024-08-21 17:37:45 +08:00

70 lines
1.7 KiB
Python

from __future__ import annotations
import dataclasses
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional
@dataclass
class DbGptsMessage:
sender: str
receiver: str
content: str
action_report: str
@staticmethod
def from_dict(d: Dict[str, Any]) -> DbGptsMessage:
return DbGptsMessage(
sender=d["sender"],
receiver=d["receiver"],
content=d["content"],
model_name=d["model_name"],
agent_name=d["agent_name"],
)
def to_dict(self) -> Dict[str, Any]:
return dataclasses.asdict(self)
@dataclass
class DbGptsTaskStep:
task_num: str
task_content: str
state: str
result: str
agent_name: str
model_name: str
@staticmethod
def from_dict(d: Dict[str, Any]) -> DbGptsTaskStep:
return DbGptsTaskStep(
task_num=d["task_num"],
task_content=d["task_content"],
state=d["state"],
result=d["result"],
agent_name=d["agent_name"],
model_name=d["model_name"],
)
def to_dict(self) -> Dict[str, Any]:
return dataclasses.asdict(self)
@dataclass
class DbGptsCompletion:
conv_id: str
task_steps: Optional[List[DbGptsTaskStep]]
messages: Optional[List[DbGptsMessage]]
@staticmethod
def from_dict(d: Dict[str, Any]) -> DbGptsCompletion:
return DbGptsCompletion(
conv_id=d.get("conv_id"),
task_steps=DbGptsTaskStep.from_dict(d["task_steps"]),
messages=DbGptsMessage.from_dict(d["messages"]),
)
def to_dict(self) -> Dict[str, Any]:
return dataclasses.asdict(self)