Skip to content

Commit

Permalink
fix api key selector
Browse files Browse the repository at this point in the history
  • Loading branch information
trisongz committed Feb 15, 2024
1 parent aff729b commit ce50aaf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion async_openai/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def init_external_api_client(
from async_openai.external_client import ExternalOpenAIClient
if 'client_callbacks' not in kwargs and self.client_callbacks:
kwargs['client_callbacks'] = self.client_callbacks
extra = ''
if not disable_proxy and provider.config.has_proxy:
# Configure the proxy version of the client
client = ExternalOpenAIClient(
Expand All @@ -403,6 +404,7 @@ def init_external_api_client(
**kwargs
)
self.configure_external_client(non_proxy_client, set_as_default = False)
extra += ' Proxied,'
else:
client = ExternalOpenAIClient(
name = client_name,
Expand All @@ -412,7 +414,10 @@ def init_external_api_client(
**kwargs
)
self.configure_external_client(client, set_as_default = set_as_default)
logger.info(f'Registered `|g|{client.name}|e|` @ `{client.provider.config.api_url}` (External - {client.provider.name})', colored = True)
if client.provider.config.has_api_keys:
extra += f' Multiple API Keys: {len(client.provider.config.api_keys)},'
extra = extra.strip().rstrip(',')
logger.info(f'Registered `|g|{client.name}|e|` @ `{client.provider.config.api_url}` (External: |g|{client.provider.name}|e|, {extra})', colored = True)
return client


Expand Down
6 changes: 3 additions & 3 deletions async_openai/utils/external_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ def get_api_key(self) -> Optional[str]:
"""
if self.config.has_api_keys:
if len(self.config.api_keys) == 1:
return self.config.api_keys[0]
return random.choice(self.config.api_keys)
return self.config.api_key
return self.config.api_keys_value[0]
return random.choice(self.config.api_keys_value)
return self.config.api_key_value

@property
def has_api_key(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# 'file-io',
'backoff',
'tiktoken',
'lazyops >= 0.2.72', # Pydantic Support
'lazyops >= 0.2.74', # Pydantic Support
'pydantic',
'jinja2',
'pyyaml',
Expand Down

0 comments on commit ce50aaf

Please sign in to comment.