Initialize OpenAI-compatible API wrapper. Args: model: Model name, e.g., gpt-4, Qwen2-VL-72B. key: API key (uses OPENAI_API_KEY env var if not provided). temperature: Generation temperature. top_p: Nucleus sampling threshold (0~1).
(
self,
model: str,
key: str = None,
temperature: float = 0.6,
top_p: float = 0.95,
top_k: int = 20,
min_p: float = 0.0,
presence_penalty: float = 1.0,
repetition_penalty: float = 1.0,
api_base: str = None,
port: int = None,
retry: int = 10,
wait: int = 3,
timeout: tuple = (30, 1800),
max_tokens: int = 16384,
thread_num: int = 8192,
return_dict: bool = False,
logger=None,
max_connections: int = None,
enable_thinking: bool = False,
**kwargs,
)
| 28 | """ |
| 29 | |
| 30 | def __init__( |
| 31 | self, |
| 32 | model: str, |
| 33 | key: str = None, |
| 34 | temperature: float = 0.6, |
| 35 | top_p: float = 0.95, |
| 36 | top_k: int = 20, |
| 37 | min_p: float = 0.0, |
| 38 | presence_penalty: float = 1.0, |
| 39 | repetition_penalty: float = 1.0, |
| 40 | api_base: str = None, |
| 41 | port: int = None, |
| 42 | retry: int = 10, |
| 43 | wait: int = 3, |
| 44 | timeout: tuple = (30, 1800), |
| 45 | max_tokens: int = 16384, |
| 46 | thread_num: int = 8192, |
| 47 | return_dict: bool = False, |
| 48 | logger=None, |
| 49 | max_connections: int = None, |
| 50 | enable_thinking: bool = False, |
| 51 | **kwargs, |
| 52 | ): |
| 53 | """Initialize OpenAI-compatible API wrapper. |
| 54 | |
| 55 | Args: |
| 56 | model: Model name, e.g., gpt-4, Qwen2-VL-72B. |
| 57 | key: API key (uses OPENAI_API_KEY env var if not provided). |
| 58 | temperature: Generation temperature. |
| 59 | top_p: Nucleus sampling threshold (0~1). |
| 60 | top_k: Top-K sampling (0 to disable). vLLM/SGLang extra param. |
| 61 | min_p: Minimum probability threshold. vLLM/SGLang extra param. |
| 62 | presence_penalty: Penalize tokens already present in the output. |
| 63 | repetition_penalty: Penalize repeated tokens. vLLM/SGLang extra param. |
| 64 | api_base: API base URL (full URL to chat/completions endpoint). |
| 65 | port: Port number for local deployments. |
| 66 | retry: Number of retry attempts on API failure. |
| 67 | wait: Max wait time between retries (seconds). |
| 68 | timeout: Request timeout as (connect_timeout, read_timeout) tuple. |
| 69 | max_tokens: Maximum tokens in response. |
| 70 | thread_num: Maximum number of concurrent requests (semaphore limit). |
| 71 | return_dict: Whether to parse response as dict via load_str_to_dict. |
| 72 | logger: Logger instance. |
| 73 | max_connections: Max TCP connections in the pool. Defaults to |
| 74 | min(thread_num, 16384). |
| 75 | enable_thinking: Whether to enable thinking mode for models that support it |
| 76 | (e.g., Qwen3 on vLLM/SGLang). Default False. |
| 77 | **kwargs: Additional API parameters passed to payload. |
| 78 | """ |
| 79 | super().__init__( |
| 80 | retry=retry, |
| 81 | wait=wait, |
| 82 | timeout=timeout, |
| 83 | logger=logger, |
| 84 | openai_format=True, |
| 85 | image_key_name="image_url", |
| 86 | thread_num=thread_num, |
| 87 | **kwargs, |