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

fix: Fix app pydantic error #1478

Merged
merged 1 commit into from
Apr 29, 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
5 changes: 3 additions & 2 deletions dbgpt/serve/agent/app/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
):
Expand Down
41 changes: 30 additions & 11 deletions dbgpt/serve/agent/db/gpts_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
Loading