Skip to content

Commit 20c97ae

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add Tool compatibility with RagRetrievalConfig in both Vertex AI SDK and GenAI SDK for use with generate_content.
PiperOrigin-RevId: 890232571
1 parent 1ccad7b commit 20c97ae

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
import os
3+
4+
# Set up path so we can import and run scripts as if they were in the workspace.
5+
sys.path.append(os.getcwd())
6+
7+
from third_party.py.google.genai import types
8+
from third_party.py.google.genai import models
9+
from third_party.py.google.genai import _common
10+
import json
11+
12+
class MockApiClient:
13+
def __init__(self):
14+
self.vertexai = True
15+
self.location = 'us-central1'
16+
self.project = 'test-project'
17+
18+
def test_transformation():
19+
tool = types.Tool(
20+
retrieval=types.Retrieval(
21+
vertex_rag_store=types.VertexRagStore(
22+
rag_resources=[
23+
types.VertexRagStoreRagResource(
24+
rag_corpus='projects/test-project/locations/us-central1/ragCorpora/test-corpus'
25+
)
26+
],
27+
rag_retrieval_config=types.RagRetrievalConfig(
28+
filter=types.RagRetrievalConfigFilter(
29+
metadata_filter='color = "red"',
30+
),
31+
),
32+
)
33+
),
34+
)
35+
36+
api_client = MockApiClient()
37+
# Mocking internal transform
38+
transformed = models._Tool_to_vertex(api_client, tool)
39+
final_dict = _common.convert_to_dict(transformed)
40+
print(json.dumps(final_dict, indent=2))
41+
42+
if __name__ == '__main__':
43+
test_transformation()

0 commit comments

Comments
 (0)