mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-24 12:45:45 +00:00
fix: Fix app pydantic error (#1478)
This commit is contained in:
parent
939b67715c
commit
8427fef5f3
@ -15,6 +15,7 @@ from dbgpt.serve.agent.db.gpts_app import (
|
||||
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
|
||||
):
|
||||
|
@ -7,7 +7,13 @@ from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
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 @@ class GptsApp(BaseModel):
|
||||
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 @@ class GptsAppDao(BaseDao):
|
||||
),
|
||||
"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 @@ class GptsAppDao(BaseDao):
|
||||
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 @@ class GptsAppDao(BaseDao):
|
||||
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,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user