mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-06 18:50:44 +00:00
correct event loop management
This commit is contained in:
parent
ba85634758
commit
ee2d4a0b89
1 changed files with 5 additions and 9 deletions
|
@ -144,15 +144,12 @@ class LlamaStackAsLibraryClient(LlamaStackClient):
|
||||||
print(f"Removed handler {handler.__class__.__name__} from root logger")
|
print(f"Removed handler {handler.__class__.__name__} from root logger")
|
||||||
|
|
||||||
def request(self, *args, **kwargs):
|
def request(self, *args, **kwargs):
|
||||||
loop = asyncio.new_event_loop()
|
async_response = asyncio.run(self.async_client.request(*args, **kwargs))
|
||||||
asyncio.set_event_loop(loop)
|
|
||||||
async_response = loop.run_until_complete(
|
|
||||||
self.async_client.request(*args, **kwargs)
|
|
||||||
)
|
|
||||||
if kwargs.get("stream"):
|
if kwargs.get("stream"):
|
||||||
# NOTE: We are using AsyncLlamaStackClient under the hood
|
loop = asyncio.new_event_loop()
|
||||||
# We need to convert the AsyncStream from async client into
|
asyncio.set_event_loop(loop)
|
||||||
# SyncStream return type for streaming
|
|
||||||
def sync_generator():
|
def sync_generator():
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -165,7 +162,6 @@ class LlamaStackAsLibraryClient(LlamaStackClient):
|
||||||
|
|
||||||
return sync_generator()
|
return sync_generator()
|
||||||
else:
|
else:
|
||||||
loop.close()
|
|
||||||
return async_response
|
return async_response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue