-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,828 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
Oops, something went wrong.