Skip to content

Commit f1e17a6

Browse files
sararobcopybara-github
authored andcommitted
docs: add GenAI client examples to readme
PiperOrigin-RevId: 772016883
1 parent 9b48d24 commit f1e17a6

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

README.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,65 @@ Gemini API and Generative AI on Vertex AI
1010
For Gemini API and Generative AI on Vertex AI, please reference `Vertex Generative AI SDK for Python`_
1111
.. _Vertex Generative AI SDK for Python: https://cloud.google.com/vertex-ai/generative-ai/docs/reference/python/latest
1212

13+
Using the Google Gen AI SDK client from the Vertex AI SDK (Experimental)
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
To use features from the Google Gen AI SDK from the Vertex AI SDK, you can instantiate the client with the following:
17+
18+
.. code-block:: Python
19+
20+
import vertexai
21+
from vertexai import types
22+
23+
# Instantiate GenAI client from Vertex SDK
24+
# Replace with your project ID and location
25+
client = vertexai.Client(project='my-project', location='us-central1')
26+
27+
See the examples below for guidance on how to use specific features supported by the Gen AI SDK client.
28+
29+
Gen AI Evaluation
30+
^^^^^^^^^^^^^^^^^
31+
32+
To run evaluation, first generate model responses from a set of prompts.
33+
34+
.. code-block:: Python
35+
36+
import pandas as pd
37+
38+
prompts_df = pd.DataFrame({
39+
"prompt": [
40+
"What is the capital of France?",
41+
"Write a haiku about a cat.",
42+
"Write a Python function to calculate the factorial of a number.",
43+
"Translate 'How are you?' to French.",
44+
],
45+
46+
"reference": [
47+
"Paris",
48+
"Sunbeam on the floor,\nA furry puddle sleeping,\nTwitching tail tells tales.",
49+
"def factorial(n):\n if n < 0:\n return 'Factorial does not exist for negative numbers'\n elif n == 0:\n return 1\n else:\n fact = 1\n i = 1\n while i <= n:\n fact *= i\n i += 1\n return fact",
50+
"Comment ça va ?",
51+
]
52+
})
53+
54+
inference_results = client.evals.run_inference(
55+
model="gemini-2.5-flash-preview-05-20",
56+
src=prompts_df
57+
)
58+
59+
Then run evaluation by providing the inference results and specifying the metric types.
60+
61+
.. code-block:: Python
62+
63+
eval_result = client.evals.evaluate(
64+
dataset=inference_results,
65+
metrics=[
66+
types.Metric(name='exact_match'),
67+
types.Metric(name='rouge_l_sum'),
68+
types.PrebuiltMetric.TEXT_QUALITY,
69+
]
70+
)
71+
1372
-----------------------------------------
1473

1574
|GA| |pypi| |versions| |unit-tests| |system-tests| |sample-tests|

0 commit comments

Comments
 (0)