Style upgrade

This commit is contained in:
retoor 2024-12-01 09:00:25 +01:00
parent 94e97f5c4e
commit 66e0e8aa4c
4 changed files with 40 additions and 39 deletions

View File

@ -20,12 +20,15 @@ yura ws://[host]:[port]/[path]/
## Python
```python
import asyncio
from yura.client import AsyncClient
async def communicate():
client = AsyncClient("ws://[host]:[port]/[path]/")
async for response in client.chat("Your prompt"):
print(response)
asyncio.run(communicate())
```

6
make
View File

@ -1,14 +1,16 @@
#!/usr/bin/env python3
import pathlib
import os
import pathlib
import sys
args = sys.argv[1:]
args_string = " ".join(args)
def install():
os.system("./.venv/bin/python -m pip install -e .")
def build():
os.system("./.venv/bin/python -m pip install build")
os.system("rm -r dist")
@ -17,7 +19,6 @@ def build():
os.system("./.venv/bin/python -m black .")
if not pathlib.Path(".venv").exists():
os.system("python3 -m venv .venv")
install()
@ -35,4 +36,3 @@ if "publish" in sys.argv:
if "run" in sys.argv:
os.system("./.venv/bin/yura " + args_string)

View File

@ -1,7 +1,8 @@
from yura.client import cli_client
import asyncio
import sys
from yura.client import cli_client
def run():
try:

View File

@ -1,8 +1,9 @@
import asyncio
import websockets
import json
import sys
import websockets
class AsyncRPCClient:
@ -27,21 +28,23 @@ class AsyncRPCClient:
response_raw = await ws.recv()
response = json.loads(response_raw)
yield response
if response.get('done'):
if response.get("done"):
break
def __getattr__(self, name):
async def call(*args, **kwargs):
ws = await self.ws
await ws.send(json.dumps(dict(
method=name,
args=args,
kwargs=kwargs
),default=str))
await ws.send(
json.dumps(
{"method": name, "args": args, "kwargs": kwargs}, default=str
)
)
response = await ws.recv()
return json.loads(response)
return call
class AsyncClient:
def __init__(self, url="ws://127.0.0.1:8470"):
@ -60,29 +63,23 @@ class AsyncClient:
pass
async def create(self, name, extends, system):
return await self.client.create(
name=name,
extends=extends,
system=system
)
return await self.client.create(name=name, extends=extends, system=system)
async def chat(self, token, message):
yield await self.client.chat(uid=token, message=message)
async for msg in self.client:
yield msg
if msg.get('done'):
if msg.get("done"):
break
async def connect(self, name):
return await self.client.connect(name)
async def cli_client(url="ws://127.0.0.1:8470"):
loop = asyncio.get_event_loop()
async_client = AsyncClient(url)
AsyncClient(url)
async with AsyncClient(url) as client:
name = "retoor3b"