diff --git a/.env.example b/.env.example index e0f91b0..50a74bb 100644 --- a/.env.example +++ b/.env.example @@ -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 \ No newline at end of file +ENABLE_GATEWAY=true +CONVERSATION_ONLY=false \ No newline at end of file diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index c8c1e7a..9a65cf4 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -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 diff --git a/README.md b/README.md index 080c8ec..4140487 100644 --- a/README.md +++ b/README.md @@ -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时可以开启,开启则直接使用对话接口 ``` diff --git a/chatgpt/ChatService.py b/chatgpt/ChatService.py index 2629dc8..7d1135f 100644 --- a/chatgpt/ChatService.py +++ b/chatgpt/ChatService.py @@ -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" diff --git a/chatgpt/proofofWork.py b/chatgpt/proofofWork.py index e2cfd2b..d4b184c 100644 --- a/chatgpt/proofofWork.py +++ b/chatgpt/proofofWork.py @@ -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() diff --git a/utils/config.py b/utils/config.py index 6888557..e4231c6 100644 --- a/utils/config.py +++ b/utils/config.py @@ -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)