v1.2.3 fix bugs

This commit is contained in:
LanQian 2024-06-11 00:15:26 +08:00
parent 9093c4eac3
commit c469ee32fb
4 changed files with 13 additions and 7 deletions

View File

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

View File

@ -22,7 +22,7 @@
## 功能
### 最新版 v1.2.2
### 最新版 v1.2.3
> 已完成
> - [x] 流式、非流式传输

View File

@ -65,7 +65,11 @@ class ChatService:
self.s = Client(proxy=self.proxy_url)
self.ws = None
self.wss_mode, self.wss_url = await token2wss(self.req_token)
if conversation_only:
self.wss_mode = False
self.wss_url = None
else:
self.wss_mode, self.wss_url = await token2wss(self.req_token)
self.oai_device_id = str(uuid.uuid4())
self.persona = None
@ -287,12 +291,11 @@ class ChatService:
async def send_conversation(self):
try:
subprotocols = ["json.reliable.webpubsub.azure.v1"]
try:
if self.wss_mode:
if not self.wss_url:
self.wss_url = await self.get_wss_url()
self.ws = await websockets.connect(self.wss_url, ping_interval=None, subprotocols=subprotocols)
self.ws = await websockets.connect(self.wss_url, ping_interval=None, subprotocols=["json.reliable.webpubsub.azure.v1"])
except Exception as e:
logger.error(f"Failed to connect to wss: {str(e)}", )
raise HTTPException(status_code=502, detail="Failed to connect to wss")
@ -308,10 +311,13 @@ class ChatService:
check_is_limit(detail, token=self.req_token, model=self.req_model)
else:
if "cf-please-wait" in rtext:
logger.error(f"Failed to send conversation: cf-please-wait")
raise HTTPException(status_code=r.status_code, detail="cf-please-wait")
if r.status_code == 429:
logger.error(f"Failed to send conversation: rate-limit")
raise HTTPException(status_code=r.status_code, detail="rate-limit")
detail = r.text[:100]
logger.error(f"Failed to send conversation: {detail}")
raise HTTPException(status_code=r.status_code, detail=detail)
content_type = r.headers.get("Content-Type", "")
@ -332,7 +338,7 @@ class ChatService:
logger.info(f"next wss_url: {self.wss_url}")
if not self.ws:
try:
self.ws = await websockets.connect(self.wss_url, ping_interval=None, subprotocols=subprotocols)
self.ws = await websockets.connect(self.wss_url, ping_interval=None, subprotocols=["json.reliable.webpubsub.azure.v1"])
except Exception as e:
logger.error(f"Failed to connect to wss: {str(e)}", )
raise HTTPException(status_code=502, detail="Failed to connect to wss")

View File

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