Skip to content

Commit 413c373

Browse files
committed
update oai client to pass all args
1 parent 0cc50a2 commit 413c373

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎rlm/clients/openai.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
class OpenAIClient(BaseLM):
2222
"""
2323
LM Client for running models with the OpenAI API. Works with vLLM as well.
24+
25+
Any additional keyword arguments (e.g. default_headers, default_query, max_retries)
26+
are passed through to the underlying openai.OpenAI and openai.AsyncOpenAI constructors.
27+
Only model_name is excluded, since it is not a client constructor argument.
2428
"""
2529

2630
def __init__(
@@ -42,11 +46,16 @@ def __init__(
4246
elif base_url == DEFAULT_PRIME_INTELLECT_BASE_URL:
4347
api_key = DEFAULT_PRIME_API_KEY
4448

45-
# For vLLM, set base_url to local vLLM server address.
46-
self.client = openai.OpenAI(api_key=api_key, base_url=base_url, timeout=self.timeout)
47-
self.async_client = openai.AsyncOpenAI(
48-
api_key=api_key, base_url=base_url, timeout=self.timeout
49-
)
49+
# Pass through arbitrary kwargs to the OpenAI client (e.g. default_headers, default_query, max_retries).
50+
# Exclude model_name since it is not an OpenAI client constructor argument.
51+
client_kwargs = {
52+
"api_key": api_key,
53+
"base_url": base_url,
54+
"timeout": self.timeout,
55+
**{k: v for k, v in self.kwargs.items() if k != "model_name"},
56+
}
57+
self.client = openai.OpenAI(**client_kwargs)
58+
self.async_client = openai.AsyncOpenAI(**client_kwargs)
5059
self.model_name = model_name
5160
self.base_url = base_url # Track for cost extraction
5261

0 commit comments

Comments
 (0)