fix:client mypy error

This commit is contained in:
aries_ckt
2024-03-20 16:22:38 +08:00
parent 7bc5c59a89
commit f43abf3155
19 changed files with 1814 additions and 80 deletions

View File

@@ -1,21 +1,49 @@
"""App Client API."""
from dbgpt.client.client import Client
from typing import List
from dbgpt.client.client import Client, ClientException
from dbgpt.client.schemas import AppModel
from dbgpt.serve.core import Result
async def get_app(client: Client, app_id: str):
async def get_app(client: Client, app_id: str) -> AppModel:
"""Get an app.
Args:
client (Client): The dbgpt client.
app_id (str): The app id.
Returns:
AppModel: The app model.
Raises:
ClientException: If the request failed.
"""
return await client.get("/apps/" + app_id)
try:
res = await client.get("/apps/" + app_id)
result: Result = res.json()
if result["success"]:
return AppModel(**result["data"])
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to get app: {e}")
async def list_app(client: Client):
async def list_app(client: Client) -> List[AppModel]:
"""List apps.
Args:
client (Client): The dbgpt client.
Returns:
List[AppModel]: The list of app models.
Raises:
ClientException: If the request failed.
"""
return await client.get("/apps")
try:
res = await client.get("/apps")
result: Result = res.json()
if result["success"]:
return [AppModel(**app) for app in result["data"]["app_list"]]
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to list apps: {e}")