1- /*
2- * Copyright 2024 Google LLC
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
1+ // / *
2+ // * Copyright 2024 Google LLC
3+ // *
4+ // * Licensed under the Apache License, Version 2.0 (the "License");
5+ // * you may not use this file except in compliance with the License.
6+ // * You may obtain a copy of the License at
7+ // *
8+ // * http://www.apache.org/licenses/LICENSE-2.0
9+ // *
10+ // * Unless required by applicable law or agreed to in writing, software
11+ // * distributed under the License is distributed on an "AS IS" BASIS,
12+ // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // * See the License for the specific language governing permissions and
14+ // * limitations under the License.
15+ // */
1616
17- package vertexai .gemini ;
17+ // package vertexai.gemini;
1818
19- // [START generativeaionvertexai_grounding_private_data_basic]
20- import com .google .cloud .vertexai .VertexAI ;
21- import com .google .cloud .vertexai .api .GenerateContentResponse ;
22- import com .google .cloud .vertexai .api .GroundingMetadata ;
23- import com .google .cloud .vertexai .api .Retrieval ;
24- import com .google .cloud .vertexai .api .Tool ;
25- import com .google .cloud .vertexai .api .VertexAISearch ;
26- import com .google .cloud .vertexai .generativeai .GenerativeModel ;
27- import com .google .cloud .vertexai .generativeai .ResponseHandler ;
28- import java .io .IOException ;
29- import java .util .Collections ;
19+ // // [START generativeaionvertexai_grounding_private_data_basic]
20+ // import com.google.cloud.vertexai.VertexAI;
21+ // import com.google.cloud.vertexai.api.GenerateContentResponse;
22+ // import com.google.cloud.vertexai.api.GroundingMetadata;
23+ // import com.google.cloud.vertexai.api.Retrieval;
24+ // import com.google.cloud.vertexai.api.Tool;
25+ // import com.google.cloud.vertexai.api.VertexAISearch;
26+ // import com.google.cloud.vertexai.generativeai.GenerativeModel;
27+ // import com.google.cloud.vertexai.generativeai.ResponseHandler;
28+ // import java.io.IOException;
29+ // import java.util.Collections;
3030
31- public class GroundingWithPrivateData {
32- public static void main (String [] args ) throws IOException {
33- // TODO(developer): Replace these variables before running the sample.
34- String projectId = "your-google-cloud-project-id" ;
35- String location = "us-central1" ;
36- String modelName = "gemini-2.0-flash-001" ;
37- String datastore = String .format (
38- "projects/%s/locations/global/collections/default_collection/dataStores/%s" ,
39- projectId , "datastore_id" );
31+ // public class GroundingWithPrivateData {
32+ // public static void main(String[] args) throws IOException {
33+ // // TODO(developer): Replace these variables before running the sample.
34+ // String projectId = "your-google-cloud-project-id";
35+ // String location = "us-central1";
36+ // String modelName = "gemini-2.0-flash-001";
37+ // String datastore = String.format(
38+ // "projects/%s/locations/global/collections/default_collection/dataStores/%s",
39+ // projectId, "datastore_id");
4040
41- groundWithPrivateData (projectId , location , modelName , datastore );
42- }
41+ // groundWithPrivateData(projectId, location, modelName, datastore);
42+ // }
4343
44- // A request whose response will be "grounded"
45- // with information found in Vertex AI Search datastores.
46- public static String groundWithPrivateData (String projectId , String location , String modelName ,
47- String datastoreId )
48- throws IOException {
49- // Initialize client that will be used to send requests.
50- // This client only needs to be created once, and can be reused for multiple requests.
51- try (VertexAI vertexAI = new VertexAI (projectId , location )) {
52- Tool datastoreTool = Tool .newBuilder ()
53- .setRetrieval (
54- Retrieval .newBuilder ()
55- .setVertexAiSearch (VertexAISearch .newBuilder ().setDatastore (datastoreId ))
56- .setDisableAttribution (false ))
57- .build ();
44+ // // A request whose response will be "grounded"
45+ // // with information found in Vertex AI Search datastores.
46+ // public static String groundWithPrivateData(String projectId, String location, String modelName,
47+ // String datastoreId)
48+ // throws IOException {
49+ // // Initialize client that will be used to send requests.
50+ // // This client only needs to be created once, and can be reused for multiple requests.
51+ // try (VertexAI vertexAI = new VertexAI(projectId, location)) {
52+ // Tool datastoreTool = Tool.newBuilder()
53+ // .setRetrieval(
54+ // Retrieval.newBuilder()
55+ // .setVertexAiSearch(VertexAISearch.newBuilder().setDatastore(datastoreId))
56+ // .setDisableAttribution(false))
57+ // .build();
5858
59- GenerativeModel model = new GenerativeModel (modelName , vertexAI ).withTools (
60- Collections .singletonList (datastoreTool )
61- );
59+ // GenerativeModel model = new GenerativeModel(modelName, vertexAI).withTools(
60+ // Collections.singletonList(datastoreTool)
61+ // );
6262
63- GenerateContentResponse response = model .generateContent (
64- "How do I make an appointment to renew my driver's license?" );
63+ // GenerateContentResponse response = model.generateContent(
64+ // "How do I make an appointment to renew my driver's license?");
6565
66- GroundingMetadata groundingMetadata = response .getCandidates (0 ).getGroundingMetadata ();
67- String answer = ResponseHandler .getText (response );
66+ // GroundingMetadata groundingMetadata = response.getCandidates(0).getGroundingMetadata();
67+ // String answer = ResponseHandler.getText(response);
6868
69- System .out .println ("Answer: " + answer );
70- System .out .println ("Grounding metadata: " + groundingMetadata );
69+ // System.out.println("Answer: " + answer);
70+ // System.out.println("Grounding metadata: " + groundingMetadata);
7171
72- return answer ;
73- }
74- }
75- }
76- // [END generativeaionvertexai_grounding_private_data_basic]
72+ // return answer;
73+ // }
74+ // }
75+ // }
76+ // // [END generativeaionvertexai_grounding_private_data_basic]
0 commit comments