google_genai.py — langchain Source File
Architecture documentation for google_genai.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f4db06b3_ed5e_25a2_b81c_b03df989dd7f["google_genai.py"] 66c6348c_7716_027c_42d7_71449bc64eeb["base64"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> 66c6348c_7716_027c_42d7_71449bc64eeb 67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> d758344f_537f_649e_f467_b9d7442e86df 67d9204c_49ef_a623_53ad_d78199dd66bc["langchain_core.messages.content"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> 67d9204c_49ef_a623_53ad_d78199dd66bc ca9b4c77_fe2d_1e5c_f238_b01bcb075875["filetype"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> ca9b4c77_fe2d_1e5c_f238_b01bcb075875 23170be8_e8a8_a728_6471_2a7fe6195245["langchain_core.messages.block_translators"] f4db06b3_ed5e_25a2_b81c_b03df989dd7f --> 23170be8_e8a8_a728_6471_2a7fe6195245 style f4db06b3_ed5e_25a2_b81c_b03df989dd7f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Derivations of standard content blocks from Google (GenAI) content."""
import base64
import re
from collections.abc import Iterator
from typing import Any, cast
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.content import Citation, create_citation
try:
import filetype # type: ignore[import-not-found]
_HAS_FILETYPE = True
except ImportError:
_HAS_FILETYPE = False
def _bytes_to_b64_str(bytes_: bytes) -> str:
"""Convert bytes to base64 encoded string."""
return base64.b64encode(bytes_).decode("utf-8")
def translate_grounding_metadata_to_citations(
grounding_metadata: dict[str, Any],
) -> list[Citation]:
"""Translate Google AI grounding metadata to LangChain Citations.
Args:
grounding_metadata: Google AI grounding metadata containing web search
queries, grounding chunks, and grounding supports.
Returns:
List of Citation content blocks derived from the grounding metadata.
Example:
>>> metadata = {
... "web_search_queries": ["UEFA Euro 2024 winner"],
... "grounding_chunks": [
... {
... "web": {
... "uri": "https://uefa.com/euro2024",
... "title": "UEFA Euro 2024 Results",
... }
... }
... ],
... "grounding_supports": [
... {
... "segment": {
... "start_index": 0,
... "end_index": 47,
... "text": "Spain won the UEFA Euro 2024 championship",
... },
... "grounding_chunk_indices": [0],
... }
... ],
... }
>>> citations = translate_grounding_metadata_to_citations(metadata)
>>> len(citations)
// ... (507 more lines)
Domain
Subdomains
Functions
Dependencies
- base64
- collections.abc
- filetype
- langchain_core.messages
- langchain_core.messages.block_translators
- langchain_core.messages.content
- re
- typing
Source
Frequently Asked Questions
What does google_genai.py do?
google_genai.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in google_genai.py?
google_genai.py defines 9 function(s): _HAS_FILETYPE, _bytes_to_b64_str, _convert_to_v1_from_genai, _convert_to_v1_from_genai_input, _register_google_genai_translator, filetype, translate_content, translate_content_chunk, translate_grounding_metadata_to_citations.
What does google_genai.py depend on?
google_genai.py imports 8 module(s): base64, collections.abc, filetype, langchain_core.messages, langchain_core.messages.block_translators, langchain_core.messages.content, re, typing.
Where is google_genai.py in the architecture?
google_genai.py is located at libs/core/langchain_core/messages/block_translators/google_genai.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/langchain_core/messages/block_translators).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free