Skip to content

Commit 4d39563

Browse files
xuanyang15copybara-github
authored andcommitted
chore: add yaml files to the ADK Vertex AI Search datastore
PiperOrigin-RevId: 808895175
1 parent 006a406 commit 4d39563

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

contributing/samples/adk_answering_agent/upload_docs_to_vertex_ai_search.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def upload_directory_to_gcs(
7272
# into hidden directories.
7373
dirs[:] = [d for d in dirs if not d.startswith(".")]
7474

75-
# Keep only .md and .py files.
76-
files = [f for f in files if f.endswith(".md") or f.endswith(".py")]
75+
# Keep only .md, .py and .yaml files.
76+
files = [f for f in files if f.endswith((".md", ".py", ".yaml"))]
7777

7878
for filename in files:
7979
local_path = os.path.join(root, filename)
@@ -99,6 +99,19 @@ def upload_directory_to_gcs(
9999
bucket.blob(gcs_path).upload_from_string(
100100
html_content, content_type=content_type
101101
)
102+
elif filename.lower().endswith(".yaml"):
103+
# Vertex AI search doesn't recognize yaml,
104+
# convert it to text and use text/plain instead
105+
content_type = "text/plain"
106+
with open(local_path, "r", encoding="utf-8") as f:
107+
yaml_content = f.read()
108+
if not yaml_content:
109+
print(" - Skipped empty file: " + local_path)
110+
continue
111+
gcs_path = gcs_path.removesuffix(".yaml") + ".txt"
112+
bucket.blob(gcs_path).upload_from_string(
113+
yaml_content, content_type=content_type
114+
)
102115
else: # Python files
103116
bucket.blob(gcs_path).upload_from_filename(
104117
local_path, content_type=content_type

contributing/samples/adk_answering_agent/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def convert_gcs_to_https(gcs_uri: str) -> Optional[str]:
115115
if relative_path.endswith(".html"):
116116
relative_path = relative_path.removesuffix(".html") + ".md"
117117

118+
# Replace .txt with .yaml
119+
if relative_path.endswith(".txt"):
120+
relative_path = relative_path.removesuffix(".txt") + ".yaml"
121+
118122
# Convert the links for adk-docs
119123
if prefix == "adk-docs" and relative_path.startswith("docs/"):
120124
path_after_docs = relative_path[len("docs/") :]

0 commit comments

Comments
 (0)