MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / OpenAIHTTPClient

Class OpenAIHTTPClient

src/core/http_client.py:231–395  ·  view source on GitHub ↗

OpenAI 专用 HTTP 客户端 包含 OpenAI API 特定的请求方法

Source from the content-addressed store, hash-verified

229
230
231class OpenAIHTTPClient(HTTPClient):
232 """
233 OpenAI 专用 HTTP 客户端
234 包含 OpenAI API 特定的请求方法
235 """
236
237 def __init__(
238 self,
239 proxy_url: Optional[str] = None,
240 config: Optional[RequestConfig] = None
241 ):
242 """
243 初始化 OpenAI HTTP 客户端
244
245 Args:
246 proxy_url: 代理 URL
247 config: 请求配置
248 """
249 super().__init__(proxy_url, config)
250
251 # OpenAI 特定的默认配置
252 if config is None:
253 self.config.timeout = 30
254 self.config.max_retries = 3
255
256 # 默认请求头
257 self.default_headers = {
258 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
259 "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
260 "Accept": "application/json",
261 "Accept-Language": "en-US,en;q=0.9",
262 "Accept-Encoding": "gzip, deflate, br",
263 "Connection": "keep-alive",
264 "Sec-Fetch-Dest": "empty",
265 "Sec-Fetch-Mode": "cors",
266 "Sec-Fetch-Site": "same-site",
267 }
268
269 def check_ip_location(self) -> Tuple[bool, Optional[str]]:
270 """
271 检查 IP 地理位置
272
273 Returns:
274 Tuple[是否支持, 位置信息]
275 """
276 try:
277 response = self.get("https://cloudflare.com/cdn-cgi/trace", timeout=10)
278 trace_text = response.text
279
280 # 解析位置信息
281 import re
282 loc_match = re.search(r"loc=([A-Z]+)", trace_text)
283 loc = loc_match.group(1) if loc_match else None
284
285 # 检查是否支持
286 if loc in ["CN", "HK", "MO", "TW"]:
287 return False, loc
288 return True, loc

Callers 3

__init__Method · 0.85
create_openai_clientFunction · 0.85

Calls

no outgoing calls

Tested by 1