mirror of
https://github.com/lanqian528/chat2api.git
synced 2026-06-13 21:02:46 +08:00
refry proofofwork
This commit is contained in:
parent
f9698e2179
commit
478d55cfb8
2
.github/workflows/build_docker.yml
vendored
2
.github/workflows/build_docker.yml
vendored
@ -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
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.env
|
||||
/.idea/
|
||||
*.pyc
|
||||
/tmp/
|
||||
|
||||
2
app.py
2
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:
|
||||
|
||||
@ -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", ""):
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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...")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user