mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-20 19:09:24 +00:00
fix(examples): update client usage to prefer await aclose() in async context" (#2839)
This commit is contained in:
parent
0ecfeabd8e
commit
f364d10fb1
@ -22,8 +22,12 @@ async def main():
|
|||||||
# initialize client
|
# initialize client
|
||||||
DBGPT_API_KEY = "dbgpt"
|
DBGPT_API_KEY = "dbgpt"
|
||||||
client = Client(api_key=DBGPT_API_KEY)
|
client = Client(api_key=DBGPT_API_KEY)
|
||||||
res = await list_app(client)
|
try:
|
||||||
print(res)
|
res = await list_app(client)
|
||||||
|
print(res)
|
||||||
|
finally:
|
||||||
|
# explicitly close client to avoid event loop closed error
|
||||||
|
await client.aclose()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -57,12 +57,16 @@ async def main():
|
|||||||
# initialize client
|
# initialize client
|
||||||
DBGPT_API_KEY = "dbgpt"
|
DBGPT_API_KEY = "dbgpt"
|
||||||
client = Client(api_key=DBGPT_API_KEY)
|
client = Client(api_key=DBGPT_API_KEY)
|
||||||
data = await client.chat(model="Qwen2.5-72B-Instruct", messages="hello")
|
try:
|
||||||
|
data = await client.chat(model="Qwen2.5-72B-Instruct", messages="hello")
|
||||||
|
print(data)
|
||||||
|
finally:
|
||||||
|
# explicitly close client to avoid event loop closed error
|
||||||
|
await client.aclose()
|
||||||
# async for data in client.chat_stream(
|
# async for data in client.chat_stream(
|
||||||
# model="chatgpt_proxyllm",
|
# model="chatgpt_proxyllm",
|
||||||
# messages="hello",
|
# messages="hello",
|
||||||
# ):
|
# ):
|
||||||
print(data)
|
|
||||||
|
|
||||||
# res = await client.chat(model="chatgpt_proxyllm" ,messages="hello")
|
# res = await client.chat(model="chatgpt_proxyllm" ,messages="hello")
|
||||||
# print(res)
|
# print(res)
|
||||||
|
@ -83,8 +83,12 @@ async def main():
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
data = await run_evaluation(client, request=request)
|
try:
|
||||||
print(data)
|
data = await run_evaluation(client, request=request)
|
||||||
|
print(data)
|
||||||
|
finally:
|
||||||
|
# explicitly close client to avoid event loop closed error
|
||||||
|
await client.aclose()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -55,8 +55,12 @@ async def main():
|
|||||||
# initialize client
|
# initialize client
|
||||||
DBGPT_API_KEY = "dbgpt"
|
DBGPT_API_KEY = "dbgpt"
|
||||||
client = Client(api_key=DBGPT_API_KEY)
|
client = Client(api_key=DBGPT_API_KEY)
|
||||||
res = await list_datasource(client)
|
try:
|
||||||
print(res)
|
res = await list_datasource(client)
|
||||||
|
print(res)
|
||||||
|
finally:
|
||||||
|
# explicitly close client to avoid event loop closed error
|
||||||
|
await client.aclose()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -37,8 +37,12 @@ async def main():
|
|||||||
# initialize client
|
# initialize client
|
||||||
DBGPT_API_KEY = "dbgpt"
|
DBGPT_API_KEY = "dbgpt"
|
||||||
client = Client(api_key=DBGPT_API_KEY)
|
client = Client(api_key=DBGPT_API_KEY)
|
||||||
res = await list_flow(client)
|
try:
|
||||||
print(res)
|
res = await list_flow(client)
|
||||||
|
print(res)
|
||||||
|
finally:
|
||||||
|
# explicitly close client to avoid event loop closed error
|
||||||
|
await client.aclose()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -75,16 +75,20 @@ async def main():
|
|||||||
DBGPT_API_KEY = "dbgpt"
|
DBGPT_API_KEY = "dbgpt"
|
||||||
client = Client(api_key=DBGPT_API_KEY)
|
client = Client(api_key=DBGPT_API_KEY)
|
||||||
|
|
||||||
res = await create_space(
|
try:
|
||||||
client,
|
res = await create_space(
|
||||||
SpaceModel(
|
client,
|
||||||
name="test_space_1",
|
SpaceModel(
|
||||||
vector_type="Chroma",
|
name="test_space_1",
|
||||||
desc="for client space desc",
|
vector_type="Chroma",
|
||||||
owner="dbgpt",
|
desc="for client space desc",
|
||||||
),
|
owner="dbgpt",
|
||||||
)
|
),
|
||||||
print(res)
|
)
|
||||||
|
print(res)
|
||||||
|
finally:
|
||||||
|
# explicitly close client to avoid event loop closed error
|
||||||
|
await client.aclose()
|
||||||
|
|
||||||
# list all spaces
|
# list all spaces
|
||||||
# res = await list_space(client)
|
# res = await list_space(client)
|
||||||
|
Loading…
Reference in New Issue
Block a user