Compare commits
10
Commits
2d22ca57f4
...
feda794722
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
feda794722 | ||
|
|
4a6d21a23a | ||
|
|
129a127bfe | ||
|
|
457c80471d | ||
|
|
cd8d4144cb | ||
|
|
77158e4e52 | ||
|
|
8b953ebea1 | ||
|
|
013f670b1d | ||
|
|
0bfca91951 | ||
|
|
3b6d4a59b4 |
+21
-13
@@ -3,22 +3,22 @@ type: docker
|
|||||||
name: default
|
name: default
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
|
||||||
image: python:3.11-slim
|
|
||||||
commands:
|
|
||||||
- pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
image: python:3.11-slim
|
image: python:3.11-slim
|
||||||
commands:
|
commands:
|
||||||
- pip install --no-cache-dir -r requirements.txt
|
- pip install --no-cache-dir -r requirements.txt
|
||||||
- pip install pytest pytest-asyncio
|
- pip install --no-cache-dir pytest pytest-asyncio
|
||||||
- pytest tests/ -v || true
|
- pytest tests/ -v || true
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
- custom
|
||||||
|
|
||||||
- name: docker-build
|
- name: docker-build
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: gitea.allowlgroup.ru/allowlgroup/gptchat
|
repo: gitea.allowlgroup.ru/parser/gptchat
|
||||||
registry: https://gitea.allowlgroup.ru
|
registry: https://gitea.allowlgroup.ru
|
||||||
insecure: true
|
insecure: true
|
||||||
tags:
|
tags:
|
||||||
@@ -47,15 +47,23 @@ steps:
|
|||||||
from_secret: ssh_password
|
from_secret: ssh_password
|
||||||
port: 22
|
port: 22
|
||||||
script:
|
script:
|
||||||
- export DOCKER_HOST="unix:///var/run/docker.sock"
|
- docker login gitea.allowlgroup.ru -u $DOCKER_USER -p $DOCKER_PASS
|
||||||
- docker stop gptchat || true
|
- docker stop gptchat 2>/dev/null || true
|
||||||
- docker rm gptchat || true
|
- docker rm gptchat 2>/dev/null || true
|
||||||
- docker pull gitea.allowlgroup.ru/allowlgroup/gptchat:latest
|
- docker pull gitea.allowlgroup.ru/parser/gptchat:latest
|
||||||
- docker run -d --name gptchat -p 8484:8484 gitea.allowlgroup.ru/allowlgroup/gptchat:latest
|
- docker run -d --name gptchat -p 8484:8484 gitea.allowlgroup.ru/parser/gptchat:latest
|
||||||
|
- docker image prune -f
|
||||||
|
envs:
|
||||||
|
- docker_user
|
||||||
|
- docker_pass
|
||||||
|
environment:
|
||||||
|
docker_user:
|
||||||
|
from_secret: docker_username
|
||||||
|
docker_pass:
|
||||||
|
from_secret: docker_password
|
||||||
when:
|
when:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- main
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- custom
|
- custom
|
||||||
|
|
||||||
|
|||||||
@@ -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():
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user