скачал обновления

This commit is contained in:
2026-08-08 00:01:09 +10:00
parent 013f670b1d
commit 8b953ebea1
2 changed files with 40 additions and 31 deletions
+40 -31
View File
@@ -11,6 +11,7 @@ import threading
# GPT Library # GPT Library
import g4f import g4f
from g4f.api import run_api from g4f.api import run_api
from g4f.errors import MissingAuthError, NoValidHarFileError, ProviderNotFoundError, RetryProviderError
# Server # Server
from flask import Flask, redirect, render_template 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']}" proxy = f"{proxy['protocol']}://{proxy['username']}:{proxy['password']}@{proxy['ip']}:{proxy['port']}"
print("Proxy: " + proxy) print("Proxy: " + proxy)
if (args.provider == "Auto"): try:
response = ( if (args.provider == "Auto"):
await g4f.ChatCompletion.create_async( response = (
model=args.model, await g4f.ChatCompletion.create_async(
messages=message_history, model=args.model,
cookies=cookies, messages=message_history,
proxy=proxy cookies=cookies,
proxy=proxy
)
) )
) else:
else: response = (
response = ( await g4f.ChatCompletion.create_async(
await g4f.ChatCompletion.create_async( model=args.model,
model=args.model, provider=args.provider,
provider=args.provider, messages=message_history,
messages=message_history, cookies=cookies,
cookies=cookies, proxy=proxy
proxy=proxy )
) )
)
print(response) print(response)
#Joins the response into a single string #Joins the response into a single string
resp_str = "" resp_str = ""
for message in response: for message in response:
resp_str += message resp_str += message
# Cleans the response from the resources links # Cleans the response from the resources links
if (args.remove_sources): if (args.remove_sources):
if re.search(r"\[\^[0-9]+\^\]\[[0-9]+\]", resp_str): if re.search(r"\[\^[0-9]+\^\]\[[0-9]+\]", resp_str):
resp_str = resp_str.split("\n\n") resp_str = resp_str.split("\n\n")
if len(resp_str) > 1: if len(resp_str) > 1:
resp_str.pop(0) resp_str.pop(0)
resp_str = re.sub(r"\[\^[0-9]+\^\]\[[0-9]+\]", "", str(resp_str[0])) resp_str = re.sub(r"\[\^[0-9]+\^\]\[[0-9]+\]", "", str(resp_str[0]))
# Returns the response # Returns the response
return resp_str 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 "<p id='response'>" + resp + "</p>" # Uncomment if preferred # return "<p id='response'>" + resp + "</p>" # Uncomment if preferred
def auth(): def auth():
BIN
View File
Binary file not shown.