From 8eca72ece8a055daa2869657477e9e91975721d6 Mon Sep 17 00:00:00 2001 From: yym68686 Date: Sat, 7 Sep 2024 00:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Bug:=201.=20Fix=20the=20bug=20of?= =?UTF-8?q?=20log=20errors=20being=20repeatedly=20displayed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2. Fix the bug when the model list is empty. 💻 Code: Remove the redundant redirection code from the GPT model interface --- main.py | 6 ++---- response.py | 52 ++++++++++++---------------------------------------- utils.py | 25 +++++++++++++------------ 3 files changed, 27 insertions(+), 56 deletions(-) diff --git a/main.py b/main.py index 726d7d5..df4107b 100644 --- a/main.py +++ b/main.py @@ -220,8 +220,6 @@ async def process_request(request: Union[RequestModel, ImageGenerationRequest], return response except (Exception, HTTPException, asyncio.CancelledError, httpx.ReadError) as e: - logger.error(f"Error with provider {provider['provider']}: {str(e)}") - # 更新失败计数 async with app.middleware_stack.app.lock: app.middleware_stack.app.channel_failure_counts[provider['provider']] += 1 @@ -340,9 +338,9 @@ async def request_model(self, request: Union[RequestModel, ImageGenerationReques if provider['provider'] == provider_name: new_matching_providers.append(provider) matching_providers = new_matching_providers - # import json - # print("matching_providers", json.dumps(matching_providers, indent=4, ensure_ascii=False, default=circular_list_encoder)) + # import json + # print("matching_providers", json.dumps(matching_providers, indent=4, ensure_ascii=False, default=circular_list_encoder)) use_round_robin = True auto_retry = True if safe_get(config, 'api_keys', api_index, "preferences", "USE_ROUND_ROBIN") == False: diff --git a/response.py b/response.py index 5d3f831..f4cc127 100644 --- a/response.py +++ b/response.py @@ -140,48 +140,20 @@ async def fetch_vertex_claude_response_stream(client, url, headers, payload, mod yield "data: [DONE]\n\r\n" async def fetch_gpt_response_stream(client, url, headers, payload, max_redirects=5): - redirect_count = 0 - while redirect_count < max_redirects: - # logger.info(f"fetch_gpt_response_stream: {url}") - async with client.stream('POST', url, headers=headers, json=payload) as response: - error_message = await check_response(response, "fetch_gpt_response_stream") - if error_message: - yield error_message - return - - buffer = "" - try: - async for chunk in response.aiter_text(): - # logger.info(f"chunk: {repr(chunk)}") - buffer += chunk - if chunk.startswith("