Skip to content

Commit

Permalink
fix the importing error
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyxuu committed Feb 7, 2024
1 parent 42a7ee5 commit 53b43bc
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion libs/community/langchain_community/utils/google.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
"""Utilities to use Google provided components."""

from importlib import metadata
from typing import Optional
from typing import Any, Callable, Optional, Union

import google.api_core
from google.api_core.gapic_v1.client_info import ClientInfo
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."""

errors = [
google.api_core.exceptions.ResourceExhausted,
google.api_core.exceptions.ServiceUnavailable,
google.api_core.exceptions.Aborted,
google.api_core.exceptions.DeadlineExceeded,
google.api_core.exceptions.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) -> "ClientInfo":
Expand Down

0 comments on commit 53b43bc

Please sign in to comment.