support CONVERSATION_ONLY

This commit is contained in:
LanQian 2024-05-20 14:05:28 +08:00
parent e828c34707
commit 4a106cedb2
6 changed files with 19 additions and 4 deletions

View File

@ -5,4 +5,5 @@ PROXY_URL=your_first_proxy, your_second_proxy
ARKOSE_TOKEN_URL=https://arkose.example.com/token
POW_DIFFICULTY=000032
RETRY_TIMES=3
ENABLE_GATEWAY=true
ENABLE_GATEWAY=true
CONVERSATION_ONLY=false

View File

@ -35,7 +35,7 @@ jobs:
images: lanqian528/chat2api
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=v1.0.6
type=raw,value=v1.0.7
- name: Build and push
uses: docker/build-push-action@v5

View File

@ -137,6 +137,7 @@ ARKOSE_TOKEN_URL=https://arkose.example.com/token // 获取Arkose token的地
POW_DIFFICULTY=000032 // 要解决的工作量证明难度字符串越小计算时间越长建议000032
RETRY_TIMES=3 // 出错重试次数
ENABLE_GATEWAY=true // 是否启用网关模式(WEBUI)true为启用
CONVERSATION_ONLY=false // 使用的网关支持在服务端处理pow和arkose时可以开启开启则直接使用对话接口
```

View File

@ -14,7 +14,8 @@ from chatgpt.proofofWork import get_config, get_dpl, get_answer_token, get_requi
from chatgpt.wssClient import ac2wss, set_wss
from utils.Client import Client
from utils.Logger import logger
from utils.config import proxy_url_list, chatgpt_base_url_list, arkose_token_url_list, history_disabled, pow_difficulty
from utils.config import proxy_url_list, chatgpt_base_url_list, arkose_token_url_list, history_disabled, pow_difficulty, \
conversation_only
class ChatService:
@ -94,6 +95,8 @@ class ChatService:
raise HTTPException(status_code=r.status_code, detail=f"Failed to get wss url: {str(e)}")
async def get_chat_requirements(self):
if conversation_only:
return None
url = f'{self.base_url}/sentinel/chat-requirements'
headers = self.base_headers.copy()
try:
@ -180,6 +183,11 @@ class ChatService:
if self.arkose_token:
self.chat_headers['Openai-Sentinel-Arkose-Token'] = self.arkose_token
if conversation_only:
self.chat_headers.pop('Openai-Sentinel-Chat-Requirements-Token', None)
self.chat_headers.pop('Openai-Sentinel-Proof-Token', None)
self.chat_headers.pop('Openai-Sentinel-Arkose-Token', None)
conversation_mode = {"kind": "primary_assistant"}
if "gpt-4o" in self.origin_model:
model = "gpt-4o"

View File

@ -8,6 +8,7 @@ from html.parser import HTMLParser
import pybase64
from utils.Logger import logger
from utils.config import conversation_only
cores = [16, 24, 32]
screens = [3000, 4000, 6000]
@ -300,6 +301,8 @@ async def get_dpl(service):
cached_dpl = "453ebaec0d44c2decab71692e1bfe39be35a24b3"
cached_time = int(time.time())
try:
if conversation_only:
return True
r = await service.s.get(f"{service.host_url}/?oai-dm=1", headers=headers, timeout=5)
r.raise_for_status()
parser = ScriptSrcParser()

View File

@ -27,6 +27,7 @@ history_disabled = is_true(os.getenv('HISTORY_DISABLED', True))
pow_difficulty = os.getenv('POW_DIFFICULTY', '000032')
retry_times = int(os.getenv('RETRY_TIMES', 3))
enable_gateway = is_true(os.getenv('ENABLE_GATEWAY', True))
conversation_only = is_true(os.getenv('CONVERSATION_ONLY', False))
authorization_list = authorization.split(',') if authorization else []
chatgpt_base_url_list = chatgpt_base_url.split(',') if chatgpt_base_url else []
@ -34,7 +35,7 @@ arkose_token_url_list = arkose_token_url.split(',') if arkose_token_url else []
proxy_url_list = proxy_url.split(',') if proxy_url else []
logger.info("-" * 60)
logger.info("Chat2Api v1.0.6 | https://github.com/lanqian528/chat2api")
logger.info("Chat2Api v1.0.7 | https://github.com/lanqian528/chat2api")
logger.info("-" * 60)
logger.info("Environment variables:")
logger.info("API_PREFIX: " + str(api_prefix))
@ -46,4 +47,5 @@ logger.info("HISTORY_DISABLED: " + str(history_disabled))
logger.info("POW_DIFFICULTY: " + str(pow_difficulty))
logger.info("RETRY_TIMES: " + str(retry_times))
logger.info("ENABLE_GATEWAY: " + str(enable_gateway))
logger.info("CONVERSATION_ONLY: " + str(conversation_only))
logger.info("-" * 60)