Skip to content

Commit

Permalink
code migration to community (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuligin authored Mar 26, 2024
1 parent ff57b2b commit 8a0d616
Show file tree
Hide file tree
Showing 13 changed files with 2,595 additions and 78 deletions.
11 changes: 11 additions & 0 deletions libs/community/langchain_google_community/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
from langchain_google_community.bigquery_vector_search import BigQueryVectorSearch
from langchain_google_community.docai import DocAIParser, DocAIParsingResults
from langchain_google_community.documentai_warehouse import DocumentAIWarehouseRetriever
from langchain_google_community.gcs_directory import GCSDirectoryLoader
from langchain_google_community.gcs_file import GCSFileLoader
from langchain_google_community.gmail.loader import GMailLoader
from langchain_google_community.gmail.toolkit import GmailToolkit
from langchain_google_community.google_speech_to_text import GoogleSpeechToTextLoader
from langchain_google_community.googledrive import GoogleDriveLoader
from langchain_google_community.vertex_ai_search import (
VertexAIMultiTurnSearchRetriever,
VertexAISearchRetriever,
)

__all__ = [
"BigQueryVectorSearch",
"DocAIParser",
"DocAIParsingResults",
"DocumentAIWarehouseRetriever",
"GCSDirectoryLoader",
"GCSFileLoader",
"GMailLoader",
"GmailToolkit",
"GoogleDriveLoader",
"GoogleSpeechToTextLoader",
"VertexAIMultiTurnSearchRetriever",
"VertexAISearchRetriever",
]
41 changes: 41 additions & 0 deletions libs/community/langchain_google_community/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Utilities to init Vertex AI."""

from importlib import metadata
from typing import Optional, Tuple

from google.api_core.gapic_v1.client_info import ClientInfo


def get_user_agent(module: Optional[str] = None) -> Tuple[str, str]:
r"""Returns a custom user agent header.
Args:
module (Optional[str]):
Optional. The module for a custom user agent header.
Returns:
Tuple[str, str]
"""
try:
langchain_version = metadata.version("langchain")
except metadata.PackageNotFoundError:
langchain_version = "0.0.0"
client_library_version = (
f"{langchain_version}-{module}" if module else langchain_version
)
return client_library_version, f"langchain/{client_library_version}"


def get_client_info(module: Optional[str] = None) -> "ClientInfo":
r"""Returns a client info object with 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
"""
client_library_version, user_agent = get_user_agent(module)
return ClientInfo(
client_library_version=client_library_version,
user_agent=user_agent,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import numpy as np
from google.api_core.exceptions import ClientError
from langchain_community.utils.google import get_client_info
from langchain_community.vectorstores.utils import (
DistanceStrategy,
maximal_marginal_relevance,
Expand All @@ -22,6 +21,8 @@
from langchain_core.embeddings import Embeddings
from langchain_core.vectorstores import VectorStore

from langchain_google_community._utils import get_client_info

DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.EUCLIDEAN_DISTANCE
DEFAULT_DOC_ID_COLUMN_NAME = "doc_id" # document id
DEFAULT_TEXT_EMBEDDING_COLUMN_NAME = "text_embedding" # embeddings vectors
Expand Down
Loading

0 comments on commit 8a0d616

Please sign in to comment.