|
4 | 4 | from typing import Optional |
5 | 5 |
|
6 | 6 | import requests |
7 | | -from requests.adapters import HTTPAdapter |
8 | | -from urllib3.util.retry import Retry |
9 | 7 |
|
10 | 8 | from ..logger import write_log |
11 | 9 | from ..url_utils import get_default_api_url, validate_base_url |
@@ -60,35 +58,14 @@ def process_deepseek( |
60 | 58 | "Authorization": f"Bearer {api_key}", |
61 | 59 | } |
62 | 60 |
|
63 | | - # Increase retry parameters for DeepSeek |
| 61 | + # DeepSeek-specific config: longer timeout and more retries for stability |
64 | 62 | max_retries = 5 |
65 | 63 | retry_delay = 3 |
66 | 64 | timeout = 90 |
67 | 65 |
|
68 | | - # Create a session with retry strategy |
69 | | - session = requests.Session() |
70 | | - |
71 | | - # Configure retry strategy for the session |
72 | | - retry_strategy = Retry( |
73 | | - total=max_retries, |
74 | | - backoff_factor=retry_delay, |
75 | | - status_forcelist=[429, 500, 502, 503, 504], |
76 | | - allowed_methods=["POST"], |
77 | | - ) |
78 | | - |
79 | | - # Mount the adapter to the session |
80 | | - adapter = HTTPAdapter(max_retries=retry_strategy) |
81 | | - session.mount("https://", adapter) |
82 | | - session.mount("http://", adapter) |
83 | | - |
84 | | - write_log( |
85 | | - f"Configured session with {max_retries} retries, {retry_delay}s backoff factor, and {timeout}s timeout" |
86 | | - ) |
87 | | - |
88 | 66 | for attempt in range(max_retries): |
89 | 67 | try: |
90 | | - write_log(f"Sending request (attempt {attempt + 1}/{max_retries})...") |
91 | | - response = session.post(url=url, headers=headers, json=body, timeout=timeout) |
| 68 | + response = requests.post(url=url, headers=headers, json=body, timeout=timeout) |
92 | 69 |
|
93 | 70 | # Check for errors |
94 | 71 | if response.status_code != 200: |
@@ -116,42 +93,11 @@ def process_deepseek( |
116 | 93 | # Clean up results (remove commas at the end of lines) |
117 | 94 | return [line.rstrip(",") for line in res] |
118 | 95 |
|
119 | | - except requests.exceptions.Timeout as e: |
120 | | - write_log( |
121 | | - f"Timeout during API call (attempt {attempt + 1}/{max_retries}): {str(e)}" |
122 | | - ) |
123 | | - if attempt < max_retries - 1: |
124 | | - wait_time = retry_delay * (2**attempt) |
125 | | - write_log(f"Waiting {wait_time} seconds before retrying...") |
126 | | - time.sleep(wait_time) |
127 | | - else: |
128 | | - write_log( |
129 | | - f"All retry attempts failed with timeout. Last error: {str(e)}", |
130 | | - level="error", |
131 | | - ) |
132 | | - raise |
133 | | - |
134 | | - except requests.exceptions.ConnectionError as e: |
135 | | - write_log( |
136 | | - f"Connection error during API call (attempt {attempt + 1}/{max_retries}): {str(e)}" |
137 | | - ) |
138 | | - if attempt < max_retries - 1: |
139 | | - wait_time = retry_delay * (2**attempt) |
140 | | - write_log(f"Waiting {wait_time} seconds before retrying...") |
141 | | - time.sleep(wait_time) |
142 | | - else: |
143 | | - write_log( |
144 | | - f"All retry attempts failed with connection error. Last error: {str(e)}", |
145 | | - level="error", |
146 | | - ) |
147 | | - raise |
148 | | - |
149 | 96 | except Exception as e: |
150 | 97 | write_log(f"Error during API call (attempt {attempt + 1}/{max_retries}): {str(e)}") |
151 | 98 | if attempt < max_retries - 1: |
152 | 99 | wait_time = retry_delay * (2**attempt) |
153 | 100 | write_log(f"Waiting {wait_time} seconds before retrying...") |
154 | 101 | time.sleep(wait_time) |
155 | 102 | else: |
156 | | - write_log(f"All retry attempts failed. Last error: {str(e)}", level="error") |
157 | 103 | raise |
0 commit comments