Fix the bug of connection timeout when non-streaming output.
Browse files- response.py +12 -4
response.py
CHANGED
@@ -141,8 +141,16 @@ async def fetch_claude_response_stream(client, url, headers, payload, model):
|
|
141 |
yield sse_string
|
142 |
|
143 |
async def fetch_response(client, url, headers, payload):
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
async def fetch_response_stream(client, url, headers, payload, engine, model):
|
148 |
for _ in range(2):
|
@@ -163,8 +171,8 @@ async def fetch_response_stream(client, url, headers, payload, engine, model):
|
|
163 |
raise ValueError("Unknown response")
|
164 |
break
|
165 |
except httpx.ConnectError as e:
|
166 |
-
print(f"连接错误: {e}")
|
167 |
continue
|
168 |
except httpx.ReadTimeout as e:
|
169 |
-
print(f"读取响应超时: {e}")
|
170 |
continue
|
|
|
141 |
yield sse_string
|
142 |
|
143 |
async def fetch_response(client, url, headers, payload):
|
144 |
+
for _ in range(2):
|
145 |
+
try:
|
146 |
+
response = await client.post(url, headers=headers, json=payload)
|
147 |
+
return response.json()
|
148 |
+
except httpx.ConnectError as e:
|
149 |
+
print(f"fetch_response 连接错误: {e}")
|
150 |
+
continue
|
151 |
+
except httpx.ReadTimeout as e:
|
152 |
+
print(f"fetch_response 读取响应超时: {e}")
|
153 |
+
continue
|
154 |
|
155 |
async def fetch_response_stream(client, url, headers, payload, engine, model):
|
156 |
for _ in range(2):
|
|
|
171 |
raise ValueError("Unknown response")
|
172 |
break
|
173 |
except httpx.ConnectError as e:
|
174 |
+
print(f"fetch_response_stream 连接错误: {e}")
|
175 |
continue
|
176 |
except httpx.ReadTimeout as e:
|
177 |
+
print(f"fetch_response_stream 读取响应超时: {e}")
|
178 |
continue
|