Skip to content

Commit

Permalink
fix:client mypy error
Browse files Browse the repository at this point in the history
  • Loading branch information
Aries-ckt committed Mar 20, 2024
1 parent 7bc5c59 commit f43abf3
Show file tree
Hide file tree
Showing 19 changed files with 1,828 additions and 94 deletions.
5 changes: 3 additions & 2 deletions dbgpt/app/openapi/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async def check_api_key(
@router.post("/v2/chat/completions", dependencies=[Depends(check_api_key)])
async def chat_completions(
request: ChatCompletionRequestBody = Body(),
flow_service: FlowService = Depends(get_chat_flow),
):
"""Chat V2 completions
Args:
Expand Down Expand Up @@ -121,7 +120,9 @@ async def chat_completions(
media_type="text/event-stream",
)
elif (
request.chat_mode is None or request.chat_mode == ChatMode.CHAT_KNOWLEDGE.value
request.chat_mode is None
or request.chat_mode == ChatMode.CHAT_NORMAL.value
or request.chat_mode == ChatMode.CHAT_KNOWLEDGE.value
):
with root_tracer.start_span(
"get_chat_instance", span_type=SpanType.CHAT, metadata=request.dict()
Expand Down
38 changes: 33 additions & 5 deletions dbgpt/client/app.py
Original file line number Diff line number Diff line change
@@ -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}")
16 changes: 5 additions & 11 deletions dbgpt/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,11 @@ def __init__(self, status=None, reason=None, http_resp=None):
reason: Optional[str], the reason for the exception.
http_resp: Optional[httpx.Response], the HTTP response object.
"""
reason = json.loads(reason)
if http_resp:
self.status = http_resp.status_code
self.reason = http_resp.content
self.body = http_resp.content
self.headers = None
else:
self.status = status
self.reason = reason
self.body = None
self.headers = None
self.status = status
self.reason = reason
self.http_resp = http_resp
self.headers = http_resp.headers if http_resp else None
self.body = http_resp.text if http_resp else None

def __str__(self):
"""Return the error message."""
Expand Down
81 changes: 70 additions & 11 deletions dbgpt/client/flow.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,114 @@
"""this module contains the flow client functions."""
from dbgpt.client.client import Client
from typing import List

from dbgpt.client.client import Client, ClientException
from dbgpt.core.awel.flow.flow_factory import FlowPanel
from dbgpt.serve.core import Result


async def create_flow(client: Client, flow: FlowPanel):
async def create_flow(client: Client, flow: FlowPanel) -> FlowPanel:
"""Create a new flow.
Args:
client (Client): The dbgpt client.
flow (FlowPanel): The flow panel.
"""
return await client.get("/awel/flows", flow.dict())
try:
res = await client.get("/awel/flows", flow.dict())
result: Result = res.json()
if result["success"]:
return FlowPanel(**result["data"])
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to create flow: {e}")


async def update_flow(client: Client, flow: FlowPanel):
async def update_flow(client: Client, flow: FlowPanel) -> FlowPanel:
"""Update a flow.
Args:
client (Client): The dbgpt client.
flow (FlowPanel): The flow panel.
Returns:
FlowPanel: The flow panel.
Raises:
ClientException: If the request failed.
"""
return await client.put("/awel/flows", flow.dict())
try:
res = await client.put("/awel/flows", flow.dict())
result: Result = res.json()
if result["success"]:
return FlowPanel(**result["data"])
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to update flow: {e}")


async def delete_flow(client: Client, flow_id: str):
async def delete_flow(client: Client, flow_id: str) -> FlowPanel:
"""
Delete a flow.
Args:
client (Client): The dbgpt client.
flow_id (str): The flow id.
Returns:
FlowPanel: The flow panel.
Raises:
ClientException: If the request failed.
"""
return await client.get("/awel/flows/" + flow_id)
try:
res = await client.delete("/awel/flows/" + flow_id)
result: Result = res.json()
if result["success"]:
return FlowPanel(**result["data"])
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to delete flow: {e}")


async def get_flow(client: Client, flow_id: str):
async def get_flow(client: Client, flow_id: str) -> FlowPanel:
"""
Get a flow.
Args:
client (Client): The dbgpt client.
flow_id (str): The flow id.
Returns:
FlowPanel: The flow panel.
Raises:
ClientException: If the request failed.
"""
return await client.get("/awel/flows/" + flow_id)
try:
res = await client.get("/awel/flows/" + flow_id)
result: Result = res.json()
if result["success"]:
return FlowPanel(**result["data"])
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to get flow: {e}")


async def list_flow(client: Client):
async def list_flow(client: Client) -> List[FlowPanel]:
"""
List flows.
Args:
client (Client): The dbgpt client.
Returns:
List[FlowPanel]: The list of flow panels.
Raises:
ClientException: If the request failed.
"""
return await client.get("/awel/flows")
try:
res = await client.get("/awel/flows")
result: Result = res.json()
if result["success"]:
return [FlowPanel(**flow) for flow in result["data"]["items"]]
else:
raise ClientException(status=result["err_code"], reason=result)
except Exception as e:
raise ClientException(f"Failed to list flows: {e}")
Loading

0 comments on commit f43abf3

Please sign in to comment.