Skip to content

Commit 1e09ea4

Browse files
committed
refactor(genai): Update docs, filename and comments
* update template folder examples
1 parent 5e7b6c3 commit 1e09ea4

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# google-genai==1.2.0
1+
google-genai==1.2.0

genai/template_folder/templatefolder_with_txt.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@
1313
# limitations under the License.
1414

1515

16-
def simple_example() -> int:
17-
"Simple example for <template_folder> feature."
18-
# TODO: <ADD-START-REGION-TAG-HERE>
19-
from vertexai.preview.tokenization import get_tokenizer_for_model
20-
21-
# Using local tokenzier
22-
tokenizer = get_tokenizer_for_model("gemini-1.5-flash-002")
23-
24-
prompt = "hello world"
25-
response = tokenizer.count_tokens(prompt)
26-
print(f"Prompt Token Count: {response.total_tokens}")
16+
def generate_content() -> str:
17+
# [START googlegenaisdk_TEMPLATEFOLDER_with_txt]
18+
from google import genai
19+
from google.genai.types import HttpOptions
20+
21+
client = genai.Client(http_options=HttpOptions(api_version="v1"))
22+
response = client.models.generate_content(
23+
model="gemini-2.0-flash-001",
24+
contents="How does AI work?",
25+
)
26+
print(response.text)
2727
# Example response:
28-
# Prompt Token Count: 2
29-
30-
prompt = ["hello world", "what's the weather today"]
31-
response = tokenizer.count_tokens(prompt)
32-
print(f"Prompt Token Count: {response.total_tokens}")
33-
# Example response:
34-
# Prompt Token Count: 8
35-
36-
# TODO: <ADD-START-REGION-TAG-HERE>
37-
return response.total_tokens
28+
# Okay, let's break down how AI works. It's a broad field, so I'll focus on the ...
29+
#
30+
# Here's a simplified overview:
31+
# ...
32+
# [END googlegenaisdk_TEMPLATEFOLDER_with_txt]
33+
return response.text
3834

3935

4036
if __name__ == "__main__":
41-
simple_example()
37+
generate_content()

genai/template_folder/test_templatefolder_examples.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import os
1415

1516
import templatefolder_with_txt
1617

17-
18-
def test_templatefolder_with_txt() -> None:
19-
assert response
18+
os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "True"
19+
os.environ["GOOGLE_CLOUD_LOCATION"] = "us-central1"
20+
# The project name is included in the CICD pipeline
21+
# os.environ['GOOGLE_CLOUD_PROJECT'] = "add-your-project-name"
2022

2123

22-
def test_advanced_example() -> None:
23-
response = advanced_example.advanced_example()
24-
assert response
24+
def test_templatefolder_with_txt() -> None:
25+
assert templatefolder_with_txt.generate_content()

0 commit comments

Comments
 (0)