From 8b953ebea113d7123fdbc2d156759925ffcb2911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=91=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=83=D1=80=D0=B8=D1=81=D1=82?= Date: Sat, 8 Aug 2026 00:01:09 +1000 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BA=D0=B0=D1=87=D0=B0=D0=BB=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 71 ++++++++++++++++++++++++++--------------------- requirements.txt | Bin 137 -> 2322 bytes 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/main.py b/main.py index 572eb9a..3a95f80 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,7 @@ import threading # GPT Library import g4f from g4f.api import run_api +from g4f.errors import MissingAuthError, NoValidHarFileError, ProviderNotFoundError, RetryProviderError # Server from flask import Flask, redirect, render_template @@ -450,42 +451,50 @@ async def index() -> str: proxy = f"{proxy['protocol']}://{proxy['username']}:{proxy['password']}@{proxy['ip']}:{proxy['port']}" print("Proxy: " + proxy) - if (args.provider == "Auto"): - response = ( - await g4f.ChatCompletion.create_async( - model=args.model, - messages=message_history, - cookies=cookies, - proxy=proxy + try: + if (args.provider == "Auto"): + response = ( + await g4f.ChatCompletion.create_async( + model=args.model, + messages=message_history, + cookies=cookies, + proxy=proxy + ) ) - ) - else: - response = ( - await g4f.ChatCompletion.create_async( - model=args.model, - provider=args.provider, - messages=message_history, - cookies=cookies, - proxy=proxy + else: + response = ( + await g4f.ChatCompletion.create_async( + model=args.model, + provider=args.provider, + messages=message_history, + cookies=cookies, + proxy=proxy + ) ) - ) - print(response) + print(response) - #Joins the response into a single string - resp_str = "" - for message in response: - resp_str += message + #Joins the response into a single string + resp_str = "" + for message in response: + resp_str += message - # Cleans the response from the resources links - if (args.remove_sources): - if re.search(r"\[\^[0-9]+\^\]\[[0-9]+\]", resp_str): - resp_str = resp_str.split("\n\n") - if len(resp_str) > 1: - resp_str.pop(0) - resp_str = re.sub(r"\[\^[0-9]+\^\]\[[0-9]+\]", "", str(resp_str[0])) - # Returns the response - return resp_str + # Cleans the response from the resources links + if (args.remove_sources): + if re.search(r"\[\^[0-9]+\^\]\[[0-9]+\]", resp_str): + resp_str = resp_str.split("\n\n") + if len(resp_str) > 1: + resp_str.pop(0) + resp_str = re.sub(r"\[\^[0-9]+\^\]\[[0-9]+\]", "", str(resp_str[0])) + # Returns the response + return resp_str + except (MissingAuthError, NoValidHarFileError, ProviderNotFoundError, RetryProviderError) as e: + print(f"[X] Provider error: {type(e).__name__}: {e}") + print("[!] Returning empty JSON response") + return '{"translation_text": "", "short_text": "", "title": "", "category": ""}' + except Exception as e: + print(f"[X] Unexpected error: {type(e).__name__}: {e}") + return '{"translation_text": "", "short_text": "", "title": "", "category": ""}' # return "

" + resp + "

" # Uncomment if preferred def auth(): diff --git a/requirements.txt b/requirements.txt index eaac9b977db9d1a2a7082eaf6dce9f77827dbcab..6ab6ab591c68354cabbedfc3bea2569241e1dd59 100644 GIT binary patch literal 2322 zcmZveOK%f#48(m#;-dsLXUrAuK9A>!J4IQ=I3Am5&JL5a4tgsdv#2v~VLI$!YS~uGc&}#?57E;@RIo(k z88-2rV|S`*EkD--_Vr2ZL#jY5a`vSf-_-IxuH!~|=9zUbO(wC)tgf0m22Eb;yb)sh z55lqFzLR%R^+LYg8uzl!)03#gw?ZRjtyKTxF*o+N9s4G=0adi40(+0sYbV>Zu@7V! zG#xFfjb&}^*0cCC9k8B=UoZQxiDh=GieE=g@TD4eVVs=lI*i`vck6|wW3gT6*(e5a zN)PeAOfAQ<(XpLSv&5~X%psA(WKIt+8th((McgTFTLbofN8JzNxfX6BRGFcoRm*HD z+g4fG25ad!gH+pn{-|7_T$z2#q7dxj!9~# z=}Ix`_$K6_6Q%U+vwq)5nZ5M8(ch zPpQbNqu;5$7b9gvXQudn=z}t?)6Q14_r#s&4tFoo(cElY0OO8I=bx#G3D zf;!;rVJ#10RN&mBU46d|_bmbvZv+zISeSy`sBMvW#T&{|L~{wREr4tuR~>-YxsizLCeuKgrIG_B42QN)-oL N=n4EiS?(Lz{{lGMPs;!R literal 137 zcmZ9@I|>3Z5CG7AP9a#k2(evDuV5jv3^CaZiAkK#LOi|IHde2C-ncA2MgpXkRQv8C z&1V5LO>iqH`GGR3f5Li+a1Wfn!Pe{Srt{?fPHiuyEifDpeaNSf1_ym;YW4KCqSTQU NY$M;eLPSyQ^aFv-GD!dc