From f157a1c08c03f7fb5d255038d4f714e2a4ab74b8 Mon Sep 17 00:00:00 2001 From: Humaun Kabir Date: Wed, 24 Jul 2024 20:37:33 +0300 Subject: [PATCH] Refactor codebase --- .DS_Store | Bin 6148 -> 6148 bytes __pycache__/commands.cpython-311.pyc | Bin 1385 -> 1367 bytes __pycache__/config.cpython-311.pyc | Bin 931 -> 621 bytes __pycache__/handler.cpython-311.pyc | Bin 1527 -> 1323 bytes __pycache__/processchat.cpython-311.pyc | Bin 2883 -> 2873 bytes commands.py | 4 ++-- handler.py | 30 ++++++++++++++---------- main.py | 12 +++++----- processchat.py | 6 ++--- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.DS_Store b/.DS_Store index f9aeaf0131ef7eec26683390eb08c32b64cccc17..8413f1561b142f6a8221a3da638eabdd5219d039 100644 GIT binary patch delta 70 zcmZoMXfc=|#>B`mu~2NHo+2a5#DLw5ER%VdvL|n3%G(^typCmKLkZ(%b`E|HpsLM@ Y%-@+O^NUz=FaQA~0|V3M0Ff=s0IV|+oB#j- delta 168 zcmZoMXfc=|#>B)qu~2NHo+2aL#DLw4KQJ;fvQ6e;%+}^*$YjW4$On?i45?0CK)FPv#e~1cFo3yjEMOeLcvPnp%mJ5;$%kuZ~LuNz@6*$pL_Z$MUC9Fkfr;PdogR_4?}Z7igPw2><{9 diff --git a/__pycache__/config.cpython-311.pyc b/__pycache__/config.cpython-311.pyc index ea527fb8af746e7eba1d51d1a1506b6aea4baf16..60e8a8bec851f7666cfa0e40d4fc044906ad6a1a 100644 GIT binary patch delta 425 zcmZXPJ5Rz;6oBs)1=#E{6dJPL8JK#c+dsbGwYxwIE(ENv~tNEbS?8h(Ls zaPq&Dt?A_IVB$~k65Txc&RM?m$a(dCxkGQk;1(dUlXw|K;BzPfZ=a7Eb7AY&iy?Li z+b2W{fh!OXey;oC(Ahi_Wh5EN0-eogb96DAE;G#8L-$gh4r(2)mp-oz>g??4ys6#P z^KGfrk(d_a_$%%1UANs}TgL7wKT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 zO#F?|Jgyo4j0E@!O9t40g9&(d{$=6#?$%!U!TG0!a=%dSUK%1+eaf}!dRqbP80rw(!lh%SGiAMRui9n%FB>I;}9{h up@}gbpnNx7161gyYk*0Z`*Tb>vbb< zNC+#$#40gMD%KvT`7x|NK>2YjWl_@jQxsiIYFy8(FK=$Fa5b};TjFDjnOtUlZFx1v z)f+1-U-Pl`jkT}7T*xgia+Q(0jO&!JfI3AfWHnGSfC9hc>!9{f6FmleT@E31GzxFS zPMYX@L}e^zf$NE_f~^5VeU)n!V%sj)mIlBomUFA2mnpH>Y~#)41a=dS%MyWu3H6!f z;Mt_aHQT*IXi}mke90Fq6R$o=Z~Cw#U9ALlD{yXETUDCAkzH^xNtZpAX64kD%Tk#5 zm5)BYmWJZZQ{_wwtWaR_YgbN(k40t?`RZ}5ECm; zq$V033KM)z1WQcpdFaUpGK&m7gleOeO~fWo<4o-8M6hz8u!}$A=Xw059RiP| z5tnW09BZi-4zj3lJ`ebxoDT5RPLTf_(UdP6_-{U;hLnv%~I7Sg@D>Tf-PnhJh$pFpO4#iy-=*U z)gnpCT=y($)qQSw)UA;sgOE`nmKZdyiZrgf0rLVz-vx%r3taOkl;I{Nw*%rsJ=Jr4 zMn$8jxWZf&?6`)5y600(gvEhSLnv`N!LZI7* z_QKykh3I;Cp)w4eWKAy=T;;ROvF@GA;Sgzb4{&evTW*yJ;M1xkr4swo{CEIWI340}wD-FHGay$g9uDxNfp7<2+%v5+0B+1k^B>F%;QMe#cnJ$iF#< zX)+_@lSwR77=KKj&GL&;Z1XhMulaF)N007cJBoqJu delta 144 zcmdlfc36yeIWI340}y;m4o>6Q$g9uDxM{L2<2+%H5+0B+1k^B>F%;QOe#cnJDwx6$ z%&<9wX)+_@tI2 str: - text = text.lower() - if 'hello' in text: - return 'Hello' - elif 'thank' in text: - return 'great.' + headers = {"Authorization": BEARER} + respurl = requests.post(APIURL, timeout=120,headers=headers, data=json.dumps({"stream":False,"prompt": text,"model":VLLM, "temperature":0.4})) + # print(f'API response is: {respurl.text}') + json_obj = json.loads(respurl.text) + resptext = json_obj['response'] + + print(respurl.status_code) + if respurl.status_code == 200: + return resptext else: - return 'I do not understand.' - + return 'Unfortunately I am offline, thanks you.' + def handle_file(path): print(path) # http = urllib3.PoolManager() @@ -21,9 +25,9 @@ def handle_file(path): # json_obj = json.loads(string) # resptext = "Jokes: " + json_obj['punchline'] + "\n" + "Type: " + json_obj['type'] + " " - respurl = requests.post(APIURL, headers={"Content-Type":"application/json","Authorization": AUTH}, data=json.dumps({"params":{"file_url": path,"data_points": DATAPOINT,"llm_choice":VLLM},"project": PROJECTID})) - print(respurl.text) - json_obj = json.loads(respurl.text) - resptext = json_obj['output']['data'] + # respurl = requests.post(APIURL, headers={"Content-Type":"application/json","Authorization": AUTH}, data=json.dumps({"params":{"file_url": path,"data_points": DATAPOINT,"llm_choice":VLLM},"project": PROJECTID})) + # print(respurl.text) + # json_obj = json.loads(respurl.text) + # resptext = json_obj['output']['data'] - return resptext \ No newline at end of file + # return resptext \ No newline at end of file diff --git a/main.py b/main.py index b2d53a8..d764a40 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,18 @@ -from config import TOKEN +from config import BOT_TOKEN from errorhandler import error from commands import start_command, help_command, info_command from processchat import handle_message, process_file, process_image -from telegram.ext import Application, CommandHandler, MessageHandler, filters +from telegram.ext import Application, CommandHandler, MessageHandler, filters # type: ignore if __name__ == '__main__': print('Bot started...') - app = Application.builder().token(TOKEN).build() + app = Application.builder().token(BOT_TOKEN).build() app.add_handler(CommandHandler('start', start_command)) app.add_handler(CommandHandler('help', help_command)) - app.add_handler(CommandHandler('info', info_command)) - app.add_handler(MessageHandler(filters.PHOTO, process_image)) - app.add_handler(MessageHandler(filters.Document.PDF, process_file)) + # app.add_handler(CommandHandler('info', info_command)) + # app.add_handler(MessageHandler(filters.PHOTO, process_image)) + # app.add_handler(MessageHandler(filters.Document.PDF, process_file)) app.add_handler(MessageHandler(filters.TEXT, handle_message)) app.add_error_handler(error) diff --git a/processchat.py b/processchat.py index bc43293..1edc595 100644 --- a/processchat.py +++ b/processchat.py @@ -1,7 +1,7 @@ from config import BOT_USER from handler import handle_file, handle_resp -from telegram import Update -from telegram.ext import ContextTypes +from telegram import Update # type: ignore +from telegram.ext import ContextTypes # type: ignore async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): @@ -13,8 +13,6 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): if BOT_USER in text: new_text: str = text.replace(BOT_USER, '').strip() response: str = handle_resp(new_text) - else: - return else: response: str = handle_resp(text)