feat(client): Modify api address

This commit is contained in:
Fangyin Cheng 2024-03-21 09:58:32 +08:00
parent 01ea5f8064
commit ab3e8e54a1
15 changed files with 98 additions and 97 deletions

View File

@ -1 +1,5 @@
"""This module is the client of the dbgpt package."""
from .client import Client, ClientException # noqa: F401
__ALL__ = ["Client", "ClientException"]

View File

@ -1,7 +1,7 @@
"""App Client API."""
from typing import List
from dbgpt.client.client import Client, ClientException
from dbgpt.client import Client, ClientException
from dbgpt.client.schemas import AppModel
from dbgpt.serve.core import Result

View File

@ -1,5 +1,6 @@
"""This module contains the client for the DB-GPT API."""
import json
import os
from typing import Any, AsyncGenerator, List, Optional, Union
from urllib.parse import urlparse
@ -50,7 +51,7 @@ class Client:
def __init__(
self,
api_base: str = "http://localhost:5000",
api_base: Optional[str] = None,
api_key: Optional[str] = None,
version: str = "v2",
timeout: Optional[httpx._types.TimeoutTypes] = 120,
@ -59,7 +60,7 @@ class Client:
Args:
api_base: Optional[str], a full URL for the DB-GPT API.
Defaults to the `http://localhost:5000`.
Defaults to the `http://localhost:5000/api/v2`.
api_key: Optional[str], The dbgpt api key to use for authentication.
Defaults to None.
timeout: Optional[httpx._types.TimeoutTypes]: The timeout to use.
@ -73,20 +74,25 @@ class Client:
--------
.. code-block:: python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_BASE = "http://localhost:5000"
DBGPT_API_BASE = "http://localhost:5000/api/v2"
DBGPT_API_KEY = "dbgpt"
client = Client(api_base=DBGPT_API_BASE, api_key=DBGPT_API_KEY)
client.chat(model="chatgpt_proxyllm", messages="Hello?")
"""
if not api_base:
api_base = os.getenv(
"DBGPT_API_BASE", f"http://localhost:5000/{CLIENT_API_PATH}/{version}"
)
if not api_key:
api_key = os.getenv("DBGPT_API_KEY")
if api_base and is_valid_url(api_base):
self._api_url = api_base.rstrip("/")
self._api_url = api_base
else:
raise ValueError(f"api url {api_base} does not exist or is not accessible.")
self._api_key = api_key
self._version = version
self._api_url = api_base + CLIENT_API_PATH + "/" + version
self._timeout = timeout
headers = {"Authorization": f"Bearer {self._api_key}"} if self._api_key else {}
self._http_client = httpx.AsyncClient(
@ -135,9 +141,9 @@ class Client:
--------
.. code-block:: python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_BASE = "http://localhost:5000"
DBGPT_API_BASE = "http://localhost:5000/api/v2"
DBGPT_API_KEY = "dbgpt"
client = Client(api_base=DBGPT_API_BASE, api_key=DBGPT_API_KEY)
res = await client.chat(model="chatgpt_proxyllm", messages="Hello?")
@ -210,9 +216,9 @@ class Client:
--------
.. code-block:: python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_BASE = "http://localhost:5000"
DBGPT_API_BASE = "http://localhost:5000/api/v2"
DBGPT_API_KEY = "dbgpt"
client = Client(api_base=DBGPT_API_BASE, api_key=DBGPT_API_KEY)
res = await client.chat_stream(model="chatgpt_proxyllm", messages="Hello?")
@ -257,7 +263,6 @@ class Client:
error = await response.aread()
yield json.loads(error)
except Exception as e:
yield f"data:[SERVER_ERROR]{str(e)}\n\n"
async def get(self, path: str, *args):
@ -274,7 +279,6 @@ class Client:
)
return response
finally:
await self._http_client.aclose()
async def post(self, path: str, args):

View File

@ -1,7 +1,7 @@
"""this module contains the flow client functions."""
from typing import List
from dbgpt.client.client import Client, ClientException
from dbgpt.client import Client, ClientException
from dbgpt.core.awel.flow.flow_factory import FlowPanel
from dbgpt.serve.core import Result

View File

@ -2,7 +2,7 @@
import json
from typing import List
from dbgpt.client.client import Client, ClientException
from dbgpt.client import Client, ClientException
from dbgpt.client.schemas import DocumentModel, SpaceModel, SyncModel
from dbgpt.serve.core import Result

View File

@ -42,7 +42,7 @@ import TabItem from '@theme/TabItem';
<TabItem value="python">
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_KEY = "dbgpt"
APP_ID="{YOUR_APP_ID}"
@ -94,7 +94,7 @@ curl -X GET "http://localhost:5000/api/v2/serve/apps/$APP_ID" -H "Authorization:
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.app import get_app
DBGPT_API_KEY = "dbgpt"
@ -146,7 +146,7 @@ curl -X GET 'http://localhost:5000/api/v2/serve/apps' -H "Authorization: Bearer
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.app import list_app
DBGPT_API_KEY = "dbgpt"

View File

@ -42,7 +42,7 @@ import TabItem from '@theme/TabItem';
<TabItem value="python">
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_KEY = "dbgpt"
@ -104,7 +104,7 @@ data: [DONE]
<TabItem value="python">
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_KEY = "dbgpt"
client = Client(api_key=DBGPT_API_KEY)

View File

@ -42,7 +42,7 @@ curl -X POST "http://localhost:5000/api/v2/chat/completions" \
<TabItem value="python">
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_KEY = "dbgpt"
FLOW_ID="{YOUR_FLOW_ID}"
@ -115,7 +115,7 @@ FLOW_ID={YOUR_FLOW_ID}
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.flow import delete_flow
DBGPT_API_KEY = "dbgpt"
@ -168,7 +168,7 @@ curl -X GET "http://localhost:5000/api/v2/serve/awel/flows/$FLOW_ID" -H "Authori
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.knowledge import get_flow
DBGPT_API_KEY = "dbgpt"
@ -222,7 +222,7 @@ curl -X GET "http://localhost:5000/api/v2/serve/awel/flows" -H "Authorization: B
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.flow import list_flow
DBGPT_API_KEY = "dbgpt"

View File

@ -21,7 +21,7 @@ Example with the DB-GPT API curl command:
Example with the DB-GPT Client Python package:
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_KEY = "dbgpt"
client = Client(api_key=DBGPT_API_KEY)

View File

@ -41,7 +41,7 @@ curl -X POST "http://localhost:5000/api/v2/chat/completions" \
<TabItem value="python">
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
DBGPT_API_KEY = "dbgpt"
SPACE_NAME="{YOUR_SPACE_NAME}"
@ -345,7 +345,7 @@ POST /api/v2/serve/knowledge/spaces
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.knowledge import create_space
from dbgpt.client.schemas import SpaceModel
@ -422,7 +422,7 @@ PUT /api/v2/serve/knowledge/spaces
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.knowledge import update_space
from dbgpt.client.schemas import SpaceModel
@ -504,7 +504,7 @@ DELETE /api/v2/serve/knowledge/spaces
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.knowledge import delete_space
DBGPT_API_KEY = "dbgpt"
@ -556,7 +556,7 @@ curl -X GET "http://localhost:5000/api/v2/serve/knowledge/spaces/$SPACE_ID" -H "
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.knowledge import get_space
DBGPT_API_KEY = "dbgpt"
@ -608,7 +608,7 @@ curl -X GET 'http://localhost:5000/api/v2/serve/knowledge/spaces' -H "Authorizat
```python
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.knowledge import list_space
DBGPT_API_KEY = "dbgpt"

View File

@ -1,25 +1,20 @@
"""Client: Simple App CRUD example.
This example demonstrates how to use the dbgpt client to get, list apps.
Example:
.. code-block:: python
DBGPT_API_KEY = "dbgpt"
client = Client(api_key=DBGPT_API_KEY)
# 1. List all apps
res = await list_app(client)
# 2. Get an app
res = await get_app(client, app_id="bf1c7561-13fc-4fe0-bf5d-c22e724766a8")
"""
import asyncio
from dbgpt.client import Client
from dbgpt.client.app import list_app
from dbgpt.client.client import Client
"""
Client: Simple App CRUD example
This example demonstrates how to use the dbgpt client to get, list apps.
Example:
.. code-block:: python
DBGPT_API_KEY = "dbgpt"
client = Client(api_key=DBGPT_API_KEY)
# 1. List all apps
res = await list_app(client)
# 2. Get an app
res = await get_app(
client, app_id="bf1c7561-13fc-4fe0-bf5d-c22e724766a8"
)
"""
async def main():

View File

@ -1,13 +1,8 @@
import asyncio
"""Client: Simple Chat example.
from dbgpt.client.client import Client
This example demonstrates how to use the dbgpt client to chat with the chatgpt model.
"""
Client: Simple Chat example
This example demonstrates how to use the dbgpt client to chat with the chatgpt model.
Example:
Example:
.. code-block:: python
DBGPT_API_KEY = "dbgpt"
@ -53,6 +48,10 @@ Client: Simple Chat example
print(data.dict())
"""
import asyncio
from dbgpt.client import Client
async def main():
# initialize client

View File

@ -1,38 +1,36 @@
"""Client: Simple Flow CRUD example
This example demonstrates how to use the dbgpt client to create, get, update, and
delete flows.
Example:
.. code-block:: python
DBGPT_API_KEY = "dbgpt"
client = Client(api_key=DBGPT_API_KEY)
# 1. Create a flow
res = await create_flow(
client,
FlowPanel(name="test_flow", desc="for client flow", owner="dbgpt"),
)
# 2. Update a flow
res = await update_flow(
client,
FlowPanel(name="test_flow", desc="for client flow333", owner="dbgpt"),
)
# 3. Delete a flow
res = await delete_flow(client, flow_id="bf1c7561-13fc-4fe0-bf5d-c22e724766a8")
# 4. Get a flow
res = await get_flow(client, flow_id="bf1c7561-13fc-4fe0-bf5d-c22e724766a8")
# 5. List all flows
res = await list_flow(client)
"""
import asyncio
from dbgpt.client.client import Client
from dbgpt.client import Client
from dbgpt.client.flow import list_flow
"""
Client: Simple Flow CRUD example
This example demonstrates how to use the dbgpt client to create, get, update, and delete flows.
Example:
.. code-block:: python
DBGPT_API_KEY = "dbgpt"
client = Client(api_key=DBGPT_API_KEY)
# 1. Create a flow
res = await create_flow(
client,
FlowPanel(name="test_flow", desc="for client flow", owner="dbgpt"),
)
# 2. Update a flow
res = await update_flow(
client,
FlowPanel(name="test_flow", desc="for client flow333", owner="dbgpt"),
)
# 3. Delete a flow
res = await delete_flow(
client, flow_id="bf1c7561-13fc-4fe0-bf5d-c22e724766a8"
)
# 4. Get a flow
res = await get_flow(client, flow_id="bf1c7561-13fc-4fe0-bf5d-c22e724766a8")
# 5. List all flows
res = await list_flow(client)
"""
async def main():
# initialize client

View File

@ -1,13 +1,9 @@
import asyncio
"""Client: Simple Knowledge CRUD example.
from dbgpt.client.client import Client
from dbgpt.client.knowledge import create_space
from dbgpt.client.schemas import SpaceModel
This example demonstrates how to use the dbgpt client to create, get, update, and
delete knowledge spaces and documents.
"""Client: Simple Knowledge CRUD example
This example demonstrates how to use the dbgpt client to create, get, update, and delete knowledge spaces and documents.
Example:
Example:
.. code-block:: python
DBGPT_API_KEY = "dbgpt"
@ -66,6 +62,11 @@ from dbgpt.client.schemas import SpaceModel
# 10. Delete a document
res = await delete_document(client, "150")
"""
import asyncio
from dbgpt.client import Client
from dbgpt.client.knowledge import create_space
from dbgpt.client.schemas import SpaceModel
async def main():