Automated update of new package.

This commit is contained in:
bot 2024-12-20 21:24:49 +00:00
parent d111fb1dfb
commit 5446358163
8 changed files with 55 additions and 54 deletions

Binary file not shown.

Binary file not shown.

View File

@ -2,8 +2,8 @@ import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
log = logging.getLogger(__name__)

View File

@ -1,13 +1,14 @@
from aiohttp import web
from rbabel.app import create_app
from rbabel.args import parse_args
def main():
args = parse_args()
app = create_app(args.url)
web.run_app(app, host=args.host, port=args.port)
if __name__ == '__main__':
if __name__ == "__main__":
nain()

View File

@ -19,10 +19,12 @@ some modifications at the end of the file.
"""
try:
import sys
import os
import sys
sys.path.append(os.getcwd())
import env
API_KEY = env.API_KEY
ASSISTANT_ID = env.ASSISTANT_ID
except:
@ -193,6 +195,7 @@ class Agent:
print("Exiting..")
break
async def main():
"""
Example main function. The keys here are not real but look exactly like

View File

@ -1,9 +1,10 @@
from aiohttp import web
from yura.client import AsyncClient as LLMClient
from rbabel.agent import Agent
from rbabel import log
import sys
import os
import sys
from aiohttp import web
from rbabel.agent import Agent
sys.path.append(os.getcwd())
import env
@ -12,15 +13,22 @@ LLM_NAME = "rbabel"
LLM_CONTEXT = "You are an English grammar corrector. You repsond with only the corrected English of by user given prompt and nothing more. Also replace numbers with the word variant."
LLM_MODEL = "gemma2:latest"
class Application(web.Application):
def __init__(self, llm_url=None, llm_name=LLM_NAME, llm_model=LLM_MODEL,llm_context=LLM_CONTEXT, *args, **kwargs):
def __init__(
self,
llm_url=None,
llm_name=LLM_NAME,
llm_model=LLM_MODEL,
llm_context=LLM_CONTEXT,
*args,
**kwargs,
):
self.agent = Agent(env.API_KEY, env.ASSISTANT_ID)
super().__init__(*args, **kwargs)
self.router.add_post("/", self.optimize_grammar_handler)
async def fix_grammar(self, content):
async for message in self.agent.chat(content):
if message:
@ -29,7 +37,7 @@ class Application(web.Application):
async def optimize_grammar_handler(self, request):
text = await request.json()
assert(type(text) ==str)
assert type(text) == str
corrected = await self.fix_grammar(text)
print("was:", text)
print("became:", corrected)
@ -38,4 +46,3 @@ class Application(web.Application):
def create_app(llm_url):
return Application(llm_url, LLM_NAME, LLM_MODEL, LLM_CONTEXT)

View File

@ -1,35 +1,25 @@
import argparse
def parse_args():
parser = argparse.ArgumentParser(
description="AI enabled English corrector. Only minor improvements."
)
parser.add_argument(
'--url',
"--url",
type=str,
required=False,
default="http://127.0.0.1:3011/",
help='URL of Katya LLM Server.'
help="URL of Katya LLM Server.",
)
parser.add_argument(
'--host',
type=str,
default="127.0.0.1",
required=False,
help='Host to bind to.'
"--host", type=str, default="127.0.0.1", required=False, help="Host to bind to."
)
parser.add_argument(
'--port',
type=int,
default=3011,
required=False,
help='Port to bind to.'
"--port", type=int, default=3011, required=False, help="Port to bind to."
)
return parser.parse_args()

View File

@ -1,8 +1,10 @@
import asyncio
from aiohttp import ClientSession
from rbabel.args import parse_args
import time
from aiohttp import ClientSession
from rbabel.args import parse_args
async def cli_client(url):
@ -16,11 +18,12 @@ async def cli_client(url):
print(ex)
print(await response.text())
async def bench(url):
index = 0
while True:
index += 1
sentence = "I bougt {} woden shoe".format(index)
sentence = f"I bougt {index} woden shoe"
time_start = time.time()
async with ClientSession() as session:
async with session.post(url, json=sentence) as response:
@ -30,7 +33,7 @@ async def bench(url):
print(ex)
print(await response.text())
time_end = time.time()
print("Duration: {}".format(time_end-time_start))
print(f"Duration: {time_end - time_start}")
def cli_bench():
@ -42,9 +45,6 @@ def main():
args = parse_args()
asyncio.run(cli_client(args.url))
if __name__ == '__main__':
if __name__ == "__main__":
main()