Merge pull request #60 from yuanzhanghu/main

fixed the issue that websocket server closes connection when sequenceId reaches 1000.
This commit is contained in:
LanQian 2024-05-26 21:11:16 +08:00 committed by GitHub
commit 550068ddec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 3 deletions

View File

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

View File

@ -21,7 +21,7 @@
3. 接口返回的状态码和响应体
## 功能
### 最新版 v1.1.10
### 最新版 v1.1.11
> 已完成
> - [x] 流式、非流式传输

View File

@ -77,6 +77,13 @@ async def wss_stream_response(websocket, conversation_id):
data = resultObj.get("data", {})
if conversation_id != data.get("conversation_id", ""):
continue
sequenceId = resultObj.get('sequenceId')
if sequenceId and sequenceId % 80 == 0:
await websocket.send(
json.dumps(
{"type": "sequenceAck", "sequenceId": sequenceId}
)
)
decoded_bytes = pybase64.b64decode(data.get("body", None))
yield decoded_bytes
else:
@ -87,6 +94,7 @@ async def wss_stream_response(websocket, conversation_id):
except websockets.ConnectionClosed as e:
if e.code == 1000:
logger.error("WebSocket closed normally with code 1000 (OK)")
yield b"data: [DONE]\n\n"
else:
logger.error(f"WebSocket closed with error code {e.code}")
except Exception as e:

View File

@ -39,7 +39,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.1.10 | https://github.com/lanqian528/chat2api")
logger.info("Chat2Api v1.1.11 | https://github.com/lanqian528/chat2api")
logger.info("-" * 60)
logger.info("Environment variables:")
logger.info("API_PREFIX: " + str(api_prefix))