diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 9a65cf4..3e2761c 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.7 + type=raw,value=v1.0.8 - name: Build and push uses: docker/build-push-action@v5 diff --git a/.gitignore b/.gitignore index 6e49c93..e534f31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env /.idea/ *.pyc +/tmp/ diff --git a/app.py b/app.py index 19f77d6..af7baa0 100644 --- a/app.py +++ b/app.py @@ -29,8 +29,8 @@ app.add_middleware( async def to_send_conversation(request_data, access_token): chat_service = ChatService(access_token) - await chat_service.set_dynamic_data(request_data) try: + await chat_service.set_dynamic_data(request_data) await chat_service.get_chat_requirements() return chat_service except HTTPException as e: diff --git a/chatgpt/ChatService.py b/chatgpt/ChatService.py index 7d1135f..531cd98 100644 --- a/chatgpt/ChatService.py +++ b/chatgpt/ChatService.py @@ -124,7 +124,9 @@ class ChatService: if proofofwork_diff <= pow_difficulty: raise HTTPException(status_code=403, detail=f"Proof of work difficulty too high: {proofofwork_diff}") proofofwork_seed = proofofwork.get("seed") - self.proof_token = await run_in_threadpool(get_answer_token, proofofwork_seed, proofofwork_diff, config) + self.proof_token, solved = await run_in_threadpool(get_answer_token, proofofwork_seed, proofofwork_diff, config) + if not solved: + raise HTTPException(status_code=403, detail="Failed to solve proof of work") arkose_required = arkose.get('required') if arkose_required: @@ -154,7 +156,7 @@ class ChatService: self.chat_token = resp.get('token') if not self.chat_token: - raise HTTPException(status_code=502, detail=f"Failed to get chat token: {r.text}") + raise HTTPException(status_code=403, detail=f"Failed to get chat token: {r.text}") return self.chat_token else: if "application/json" == r.headers.get("Content-Type", ""): diff --git a/chatgpt/proofofWork.py b/chatgpt/proofofWork.py index d4b184c..0885cb7 100644 --- a/chatgpt/proofofWork.py +++ b/chatgpt/proofofWork.py @@ -343,7 +343,7 @@ def get_answer_token(seed, diff, config): answer, solved = generate_answer(seed, diff, config) end = time.time() logger.info(f'diff: {diff}, time: {int((end - start) * 1e6) / 1e3}ms, solved: {solved}') - return "gAAAAAB" + answer + return "gAAAAAB" + answer, solved def generate_answer(seed, diff, config): diff --git a/utils/config.py b/utils/config.py index e4231c6..36cbe9d 100644 --- a/utils/config.py +++ b/utils/config.py @@ -35,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.7 | https://github.com/lanqian528/chat2api") +logger.info("Chat2Api v1.0.8 | https://github.com/lanqian528/chat2api") logger.info("-" * 60) logger.info("Environment variables:") logger.info("API_PREFIX: " + str(api_prefix)) diff --git a/utils/retry.py b/utils/retry.py index 7f103eb..f487758 100644 --- a/utils/retry.py +++ b/utils/retry.py @@ -11,8 +11,9 @@ async def async_retry(func, *args, max_retries=retry_times, **kwargs): return result except HTTPException as e: if attempt == max_retries: + logger.error(f"Throw an exception {e.status_code}, {e.detail}") raise HTTPException(status_code=e.status_code, detail=e.detail) - logger.error(f"Retry {attempt + 1} status code {e.status_code}, {e.detail}. Retrying...") + logger.info(f"Retry {attempt + 1} status code {e.status_code}, {e.detail}. Retrying...") def retry(func, *args, max_retries=retry_times, **kwargs): @@ -22,5 +23,6 @@ def retry(func, *args, max_retries=retry_times, **kwargs): return result except HTTPException as e: if attempt == max_retries: + logger.error(f"Throw an exception {e.status_code}, {e.detail}") raise HTTPException(status_code=e.status_code, detail=e.detail) logger.error(f"Retry {attempt + 1} status code {e.status_code}, {e.detail}. Retrying...")