-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
Add the BQ job usage tracking from LangChain #17123
Merged
efriis
merged 16 commits into
langchain-ai:master
from
ashleyxuu:bq-vector-search-usage-tracking
Feb 13, 2024
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ff359e9
Add the BQ job usage tracking from LangChain
ashleyxuu a2b7914
fix failures
ashleyxuu dd320f7
fix lint
ashleyxuu 1b35a87
fix lint
ashleyxuu 8229cae
fix lint
ashleyxuu 4af528e
fix lint
ashleyxuu 87c13f5
fix lint
ashleyxuu 03e01d4
addres comments
ashleyxuu 42a7ee5
introduce google utils
ashleyxuu 53b43bc
fix the importing error
ashleyxuu e41dfe2
fix the importing error
ashleyxuu 2774304
fix the importing error
ashleyxuu 1349ed6
fix lint error
ashleyxuu c4b23db
fix error
ashleyxuu 6f0e783
delete unused retry decorator
efriis 3d4ec54
Merge branch 'master' into bq-vector-search-usage-tracking
efriis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Utilities to use Google provided components.""" | ||
|
||
from importlib import metadata | ||
from typing import Any, Callable, Optional, Union | ||
|
||
from langchain_core.callbacks import ( | ||
AsyncCallbackManagerForLLMRun, | ||
CallbackManagerForLLMRun, | ||
) | ||
from langchain_core.language_models.llms import create_base_retry_decorator | ||
|
||
|
||
def create_retry_decorator( | ||
*, | ||
max_retries: int = 1, | ||
run_manager: Optional[ | ||
Union[AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun] | ||
] = None, | ||
) -> Callable[[Any], Any]: | ||
"""Creates a retry decorator for Vertex / Palm LLMs.""" | ||
from google.api_core.exceptions import ( | ||
Aborted, | ||
DeadlineExceeded, | ||
GoogleAPIError, | ||
ResourceExhausted, | ||
ServiceUnavailable, | ||
) | ||
|
||
errors = [ | ||
ResourceExhausted, | ||
ServiceUnavailable, | ||
Aborted, | ||
DeadlineExceeded, | ||
GoogleAPIError, | ||
] | ||
decorator = create_base_retry_decorator( | ||
error_types=errors, max_retries=max_retries, run_manager=run_manager | ||
) | ||
return decorator | ||
|
||
|
||
def get_client_info(module: Optional[str] = None) -> Any: | ||
r"""Returns a custom user agent header. | ||
|
||
Args: | ||
module (Optional[str]): | ||
Optional. The module for a custom user agent header. | ||
Returns: | ||
google.api_core.gapic_v1.client_info.ClientInfo | ||
""" | ||
from google.api_core.gapic_v1.client_info import ClientInfo | ||
|
||
langchain_version = metadata.version("langchain") | ||
client_library_version = ( | ||
f"{langchain_version}-{module}" if module else langchain_version | ||
) | ||
return ClientInfo( | ||
client_library_version=client_library_version, | ||
user_agent=f"langchain/{client_library_version}", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can probably remove this right? Not used?