Progress
This commit is contained in:
parent
3af0443f58
commit
89418d62b6
BIN
dist/yura-14.3.7-py3-none-any.whl
vendored
BIN
dist/yura-14.3.7-py3-none-any.whl
vendored
Binary file not shown.
BIN
dist/yura-14.3.7.tar.gz
vendored
BIN
dist/yura-14.3.7.tar.gz
vendored
Binary file not shown.
@ -18,3 +18,7 @@ install_requires =
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
yura = yura.cli:run
|
||||
|
@ -3,9 +3,11 @@ pyproject.toml
|
||||
setup.cfg
|
||||
src/yura/__init__.py
|
||||
src/yura/__main__.py
|
||||
src/yura/cli.py
|
||||
src/yura/client.py
|
||||
src/yura.egg-info/PKG-INFO
|
||||
src/yura.egg-info/SOURCES.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/top_level.txt
|
@ -14,9 +14,9 @@ class AsyncClient:
|
||||
self.queue_out = asyncio.Queue()
|
||||
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)
|
||||
|
||||
return self.ws
|
||||
@ -29,6 +29,23 @@ class AsyncClient:
|
||||
return self.communication_task
|
||||
|
||||
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.queue_out.put(message)
|
||||
while True:
|
||||
@ -66,7 +83,6 @@ class AsyncClient:
|
||||
|
||||
if response["done"]:
|
||||
break
|
||||
|
||||
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)
|
||||
|
||||
if response["done"]:
|
||||
break
|
||||
|
||||
print("")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user