Automated update of new package.
This commit is contained in:
parent
d111fb1dfb
commit
5446358163
BIN
dist/rbabel-1.0.0-py3-none-any.whl
vendored
BIN
dist/rbabel-1.0.0-py3-none-any.whl
vendored
Binary file not shown.
BIN
dist/rbabel-1.0.0.tar.gz
vendored
BIN
dist/rbabel-1.0.0.tar.gz
vendored
Binary file not shown.
@ -2,8 +2,8 @@ import logging
|
|||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||||
datefmt='%Y-%m-%d %H:%M:%S'
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
)
|
)
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
from rbabel.app import create_app
|
from rbabel.app import create_app
|
||||||
from rbabel.args import parse_args
|
from rbabel.args import parse_args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
app = create_app(args.url)
|
app = create_app(args.url)
|
||||||
web.run_app(app,host=args.host,port=args.port)
|
web.run_app(app, host=args.host, port=args.port)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
nain()
|
nain()
|
||||||
|
|
||||||
|
@ -19,10 +19,12 @@ some modifications at the end of the file.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
import env
|
import env
|
||||||
|
|
||||||
API_KEY = env.API_KEY
|
API_KEY = env.API_KEY
|
||||||
ASSISTANT_ID = env.ASSISTANT_ID
|
ASSISTANT_ID = env.ASSISTANT_ID
|
||||||
except:
|
except:
|
||||||
@ -193,6 +195,7 @@ class Agent:
|
|||||||
print("Exiting..")
|
print("Exiting..")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""
|
"""
|
||||||
Example main function. The keys here are not real but look exactly like
|
Example main function. The keys here are not real but look exactly like
|
||||||
|
@ -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 os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from aiohttp import web
|
||||||
|
|
||||||
|
from rbabel.agent import Agent
|
||||||
|
|
||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
|
|
||||||
import env
|
import env
|
||||||
@ -12,30 +13,36 @@ 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_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"
|
LLM_MODEL = "gemma2:latest"
|
||||||
|
|
||||||
|
|
||||||
class Application(web.Application):
|
class Application(web.Application):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
def __init__(self, llm_url=None, llm_name=LLM_NAME, llm_model=LLM_MODEL,llm_context=LLM_CONTEXT, *args, **kwargs):
|
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)
|
self.agent = Agent(env.API_KEY, env.ASSISTANT_ID)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.router.add_post("/", self.optimize_grammar_handler)
|
self.router.add_post("/", self.optimize_grammar_handler)
|
||||||
|
|
||||||
|
|
||||||
async def fix_grammar(self, content):
|
async def fix_grammar(self, content):
|
||||||
async for message in self.agent.chat(content):
|
async for message in self.agent.chat(content):
|
||||||
if message:
|
if message:
|
||||||
print("<<<<",message,"<<<<")
|
print("<<<<", message, "<<<<")
|
||||||
return message
|
return message
|
||||||
|
|
||||||
async def optimize_grammar_handler(self,request):
|
async def optimize_grammar_handler(self, request):
|
||||||
text = await request.json()
|
text = await request.json()
|
||||||
assert(type(text) ==str)
|
assert type(text) == str
|
||||||
corrected = await self.fix_grammar(text)
|
corrected = await self.fix_grammar(text)
|
||||||
print("was:",text)
|
print("was:", text)
|
||||||
print("became:",corrected)
|
print("became:", corrected)
|
||||||
return web.json_response(corrected,content_type="application/json")
|
return web.json_response(corrected, content_type="application/json")
|
||||||
|
|
||||||
|
|
||||||
def create_app(llm_url):
|
def create_app(llm_url):
|
||||||
return Application(llm_url, LLM_NAME, LLM_MODEL, LLM_CONTEXT)
|
return Application(llm_url, LLM_NAME, LLM_MODEL, LLM_CONTEXT)
|
||||||
|
|
||||||
|
@ -1,35 +1,25 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="AI enabled English corrector. Only minor improvements."
|
description="AI enabled English corrector. Only minor improvements."
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--url',
|
"--url",
|
||||||
type=str,
|
type=str,
|
||||||
required=False,
|
required=False,
|
||||||
default="http://127.0.0.1:3011/",
|
default="http://127.0.0.1:3011/",
|
||||||
help='URL of Katya LLM Server.'
|
help="URL of Katya LLM Server.",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--host',
|
"--host", type=str, default="127.0.0.1", required=False, help="Host to bind to."
|
||||||
type=str,
|
|
||||||
default="127.0.0.1",
|
|
||||||
required=False,
|
|
||||||
help='Host to bind to.'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--port',
|
"--port", type=int, default=3011, required=False, help="Port to bind to."
|
||||||
type=int,
|
|
||||||
default=3011,
|
|
||||||
required=False,
|
|
||||||
help='Port to bind to.'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from aiohttp import ClientSession
|
|
||||||
from rbabel.args import parse_args
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
|
from rbabel.args import parse_args
|
||||||
|
|
||||||
|
|
||||||
async def cli_client(url):
|
async def cli_client(url):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
sentence = input("> ")
|
sentence = input("> ")
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
async with session.post("http://localhost:8080",json=sentence) as response:
|
async with session.post("http://localhost:8080", json=sentence) as response:
|
||||||
try:
|
try:
|
||||||
print(await response.json())
|
print(await response.json())
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(ex)
|
print(ex)
|
||||||
print(await response.text())
|
print(await response.text())
|
||||||
|
|
||||||
|
|
||||||
async def bench(url):
|
async def bench(url):
|
||||||
index = 0
|
index = 0
|
||||||
while True:
|
while True:
|
||||||
index += 1
|
index += 1
|
||||||
sentence = "I bougt {} woden shoe".format(index)
|
sentence = f"I bougt {index} woden shoe"
|
||||||
time_start = time.time()
|
time_start = time.time()
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
async with session.post(url,json=sentence) as response:
|
async with session.post(url, json=sentence) as response:
|
||||||
try:
|
try:
|
||||||
print(await response.json())
|
print(await response.json())
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(ex)
|
print(ex)
|
||||||
print(await response.text())
|
print(await response.text())
|
||||||
time_end = time.time()
|
time_end = time.time()
|
||||||
print("Duration: {}".format(time_end-time_start))
|
print(f"Duration: {time_end - time_start}")
|
||||||
|
|
||||||
|
|
||||||
def cli_bench():
|
def cli_bench():
|
||||||
@ -42,9 +45,6 @@ def main():
|
|||||||
args = parse_args()
|
args = parse_args()
|
||||||
asyncio.run(cli_client(args.url))
|
asyncio.run(cli_client(args.url))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user