diff --git a/dbgpt/serve/agent/app/controller.py b/dbgpt/serve/agent/app/controller.py index c57df1e96..4a914bc34 100644 --- a/dbgpt/serve/agent/app/controller.py +++ b/dbgpt/serve/agent/app/controller.py @@ -15,6 +15,7 @@ GptsAppCollectionDao, GptsAppDao, GptsAppQuery, + GptsAppResponse, ) from dbgpt.serve.agent.hub.plugin_hub import plugin_hub from dbgpt.serve.agent.team.base import TeamMode @@ -36,7 +37,7 @@ async def create(gpts_app: GptsApp): return Result.failed(code="E000X", msg=f"create app error: {ex}") -@router.post("/v1/app/list") +@router.post("/v1/app/list", response_model=Result[GptsAppResponse]) async def app_list(query: GptsAppQuery): try: return Result.succ(gpts_dao.app_list(query, True)) @@ -137,7 +138,7 @@ async def llm_strategy_values(type: str): ) -@router.get("/v1/app/resources/list", response_model=Result[str]) +@router.get("/v1/app/resources/list", response_model=Result[list[str]]) async def app_resources( type: str, name: str = None, user_code: str = None, sys_code: str = None ): diff --git a/dbgpt/serve/agent/db/gpts_app.py b/dbgpt/serve/agent/db/gpts_app.py index b3f7b32be..b2d00a69d 100644 --- a/dbgpt/serve/agent/db/gpts_app.py +++ b/dbgpt/serve/agent/db/gpts_app.py @@ -7,7 +7,13 @@ from sqlalchemy import Column, DateTime, Integer, String, Text, UniqueConstraint -from dbgpt._private.pydantic import BaseModel, ConfigDict, Field, model_to_json +from dbgpt._private.pydantic import ( + BaseModel, + ConfigDict, + Field, + model_to_json, + model_validator, +) from dbgpt.agent.plan.awel.team_awel_layout import AWELTeamContext from dbgpt.agent.resource.resource_api import AgentResource from dbgpt.serve.agent.team.base import TeamMode @@ -129,11 +135,20 @@ def from_dict(cls, d: Dict[str, Any]): details=d.get("details", None), ) + @model_validator(mode="before") + @classmethod + def pre_fill(cls, values): + if not isinstance(values, dict): + return values + is_collected = values.get("is_collected") + if is_collected is not None and isinstance(is_collected, bool): + values["is_collected"] = "true" if is_collected else "false" + return values + class GptsAppQuery(GptsApp): page_size: int = 100 page_no: int = 1 - is_collected: Optional[str] = None class GptsAppResponse(BaseModel): @@ -377,9 +392,9 @@ def app_list(self, query: GptsAppQuery, parse_llm_strategy: bool = False): ), "user_code": app_info.user_code, "sys_code": app_info.sys_code, - "is_collected": "true" - if app_info.app_code in app_codes - else "false", + "is_collected": ( + "true" if app_info.app_code in app_codes else "false" + ), "created_at": app_info.created_at, "updated_at": app_info.updated_at, "details": [ @@ -502,9 +517,11 @@ def create(self, gpts_app: GptsApp): resources=json.dumps(resource_dicts, ensure_ascii=False), prompt_template=item.prompt_template, llm_strategy=item.llm_strategy, - llm_strategy_value=None - if item.llm_strategy_value is None - else json.dumps(tuple(item.llm_strategy_value.split(","))), + llm_strategy_value=( + None + if item.llm_strategy_value is None + else json.dumps(tuple(item.llm_strategy_value.split(","))) + ), created_at=item.created_at, updated_at=item.updated_at, ) @@ -546,9 +563,11 @@ def edit(self, gpts_app: GptsApp): resources=json.dumps(resource_dicts, ensure_ascii=False), prompt_template=item.prompt_template, llm_strategy=item.llm_strategy, - llm_strategy_value=None - if item.llm_strategy_value is None - else json.dumps(tuple(item.llm_strategy_value.split(","))), + llm_strategy_value=( + None + if item.llm_strategy_value is None + else json.dumps(tuple(item.llm_strategy_value.split(","))) + ), created_at=item.created_at, updated_at=item.updated_at, )