fix(examples): update client usage to prefer await aclose() in async context" (#2839)

This commit is contained in:
huhao0926 2025-07-13 16:58:46 +08:00 committed by GitHub
parent 0ecfeabd8e
commit f364d10fb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 20 deletions

View File

@ -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)
try:
res = await list_app(client) res = await list_app(client)
print(res) print(res)
finally:
# explicitly close client to avoid event loop closed error
await client.aclose()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -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)
try:
data = await client.chat(model="Qwen2.5-72B-Instruct", messages="hello") 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)

View File

@ -83,8 +83,12 @@ async def main():
} }
], ],
) )
try:
data = await run_evaluation(client, request=request) data = await run_evaluation(client, request=request)
print(data) print(data)
finally:
# explicitly close client to avoid event loop closed error
await client.aclose()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -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)
try:
res = await list_datasource(client) res = await list_datasource(client)
print(res) print(res)
finally:
# explicitly close client to avoid event loop closed error
await client.aclose()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -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)
try:
res = await list_flow(client) res = await list_flow(client)
print(res) print(res)
finally:
# explicitly close client to avoid event loop closed error
await client.aclose()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -75,6 +75,7 @@ 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)
try:
res = await create_space( res = await create_space(
client, client,
SpaceModel( SpaceModel(
@ -85,6 +86,9 @@ async def main():
), ),
) )
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)