-
Notifications
You must be signed in to change notification settings - Fork 22
fix: Make auth tokens resolved dynamically per request. #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ccepting http_client parameter.
nunogoncalves03
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
| if callable(api_key): | ||
| api_key_getter_fn = api_key | ||
| else: | ||
| def api_key_getter_fn() -> Optional[str]: | ||
| if api_key is None: | ||
| return os.environ.get('SINGLESTOREDB_USER_TOKEN') | ||
| return api_key | ||
|
|
||
| if obo_token_getter is not None: | ||
| obo_token_getter_fn = obo_token_getter | ||
| else: | ||
| if callable(obo_token): | ||
| obo_token_getter_fn = obo_token | ||
| else: | ||
| def obo_token_getter_fn() -> Optional[str]: | ||
| return obo_token | ||
|
|
||
| # handle model info | ||
| if base_url is None: | ||
| base_url = os.environ.get('SINGLESTOREDB_INFERENCE_API_BASE_URL') | ||
| if hosting_platform is None: | ||
| hosting_platform = os.environ.get('SINGLESTOREDB_INFERENCE_API_HOSTING_PLATFORM') | ||
| if base_url is None or hosting_platform is None: | ||
| inference_api_manager = ( | ||
| manage_workspaces().organizations.current.inference_apis | ||
| ) | ||
| info = inference_api_manager.get(model_name=model_name) | ||
| else: | ||
| info = InferenceAPIInfo( | ||
| service_id='', | ||
| model_name=model_name, | ||
| name='', | ||
| connection_url=base_url, | ||
| project_id='', | ||
| hosting_platform=hosting_platform, | ||
| ) | ||
| if base_url is not None: | ||
| info.connection_url = base_url | ||
| if hosting_platform is not None: | ||
| info.hosting_platform = hosting_platform | ||
|
|
||
| # Extract timeouts from http_client if provided | ||
| t = http_client.timeout if http_client is not None else None | ||
| connect_timeout = None | ||
| read_timeout = None | ||
| if t is not None: | ||
| if isinstance(t, httpx.Timeout): | ||
| if t.connect is not None: | ||
| connect_timeout = float(t.connect) | ||
| if t.read is not None: | ||
| read_timeout = float(t.read) | ||
| if connect_timeout is None and read_timeout is not None: | ||
| connect_timeout = read_timeout | ||
| if read_timeout is None and connect_timeout is not None: | ||
| read_timeout = connect_timeout | ||
| elif isinstance(t, (int, float)): | ||
| connect_timeout = float(t) | ||
| read_timeout = float(t) | ||
| if timeout is not None: | ||
| connect_timeout = timeout | ||
| read_timeout = timeout | ||
| t = httpx.Timeout(timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks nearly identical to the code in SingleStoreChatFactory. Is there a reason they can't be combined into a single function that is called to do these operations instead of duplicating code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do this refactoring as part of cleaning up the code along with the deprecated parameters.
Summary
WIth this change we:
hosting_platformand theendpoint_urlof the provided InferenceAPI model.http_clientparameter in favor oftimeout. In the next release we are going to remove it.obo_token_getterparameter in favor ofobo_token. In the next release we are going to remove it.JIRA Issues
MCDB-86327
MCDB-86334