This commit is contained in:
retoor 2024-11-27 23:46:21 +01:00
parent 3af0443f58
commit 89418d62b6
5 changed files with 26 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@ -18,3 +18,7 @@ install_requires =
[options.packages.find] [options.packages.find]
where = src where = src
[options.entry_points]
console_scripts =
yura = yura.cli:run

View File

@ -3,9 +3,11 @@ pyproject.toml
setup.cfg setup.cfg
src/yura/__init__.py src/yura/__init__.py
src/yura/__main__.py src/yura/__main__.py
src/yura/cli.py
src/yura/client.py src/yura/client.py
src/yura.egg-info/PKG-INFO src/yura.egg-info/PKG-INFO
src/yura.egg-info/SOURCES.txt src/yura.egg-info/SOURCES.txt
src/yura.egg-info/dependency_links.txt src/yura.egg-info/dependency_links.txt
src/yura.egg-info/entry_points.txt
src/yura.egg-info/requires.txt src/yura.egg-info/requires.txt
src/yura.egg-info/top_level.txt src/yura.egg-info/top_level.txt

View File

@ -14,9 +14,9 @@ class AsyncClient:
self.queue_out = asyncio.Queue() self.queue_out = asyncio.Queue()
self.communication_task = None self.communication_task = None
async def ensure_connection(): async def ensure_connection(self):
if not self.ws: # if not self.ws:
self.ws = await websockets.connect(self.url) self.ws = await websockets.connect(self.url)
return self.ws return self.ws
@ -29,6 +29,23 @@ class AsyncClient:
return self.communication_task return self.communication_task
async def chat(self, message): async def chat(self, message):
ws = await self.ensure_connection()
await ws.send(json.dumps(message))
response = None
while True:
response_raw = await ws.recv()
response = json.loads(response_raw)
if not response["done"]:
yield response
else:
break
if response and response["done"]:
yield response
async def chatw(self, message):
await self.ensure_communication() await self.ensure_communication()
await self.queue_out.put(message) await self.queue_out.put(message)
while True: while True:
@ -66,7 +83,6 @@ class AsyncClient:
if response["done"]: if response["done"]:
break break
await self.queue_in.put(response) await self.queue_in.put(response)
await self.queue_in.put(response) await self.queue_in.put(response)
@ -87,9 +103,6 @@ async def cli_client(url="ws://127.0.0.1:8470"):
print(response["content"], end="", flush=True) print(response["content"], end="", flush=True)
if response["done"]:
break
print("") print("")