Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion genai_bench/user/openai_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class OpenAIUser(BaseUser):
def on_start(self):
if not self.host or not self.auth_provider:
raise ValueError("API key and base must be set for OpenAIUser.")
auth_headers = self.auth_provider.get_headers()
self.headers = {
"Authorization": f"Bearer {self.auth_provider.get_credentials()}",
**auth_headers,
"Content-Type": "application/json",
}
Comment on lines 44 to 47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly fixes the Authorization header issue, the current dictionary unpacking order will always override the Content-Type header from the authentication provider. This could cause issues if an auth provider requires a specific Content-Type.

To make this more robust and give the ModelAuthProvider full control over headers, consider setting Content-Type as a default that can be overridden by the provider. This aligns better with the goal of delegating header management.

Suggested change
self.headers = {
"Authorization": f"Bearer {self.auth_provider.get_credentials()}",
**auth_headers,
"Content-Type": "application/json",
}
self.headers = {
"Content-Type": "application/json",
**auth_headers,
}

super().on_start()
Expand Down
5 changes: 1 addition & 4 deletions tests/user/test_openai_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def mock_openai_user():
# Set up mock auth provider
mock_auth = MagicMock()
mock_auth.get_credentials.return_value = "fake_api_key"
mock_auth.get_headers.return_value = {"Authorization": "Bearer fake_api_key"}
mock_auth.get_config.return_value = {
"api_base": "http://example.com",
"api_key": "fake_api_key",
Expand All @@ -27,10 +28,6 @@ def mock_openai_user():
OpenAIUser.host = "http://example.com"

user = OpenAIUser(environment=MagicMock())
user.headers = {
"Authorization": "Bearer fake_api_key",
"Content-Type": "application/json",
}
user.user_requests = [
UserChatRequest(
model="gpt-3",
Expand Down