From 509bde270159d9f1ad6e3a7ac4fc0d1ed744d87c Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Wed, 20 Mar 2024 10:01:34 -0700 Subject: [PATCH] Add docs for gemini --- .../drivers/embedding-drivers.md | 18 +++++++++++++ .../drivers/prompt-drivers.md | 27 +++++++++++++++++++ docs/griptape-framework/misc/tokenizers.md | 13 +++++++++ docs/griptape-framework/structures/config.md | 12 +++++++++ 4 files changed, 70 insertions(+) diff --git a/docs/griptape-framework/drivers/embedding-drivers.md b/docs/griptape-framework/drivers/embedding-drivers.md index 3abe721..2778ca3 100644 --- a/docs/griptape-framework/drivers/embedding-drivers.md +++ b/docs/griptape-framework/drivers/embedding-drivers.md @@ -51,6 +51,24 @@ print(embeddings[:3]) [-0.234375, -0.024902344, -0.14941406] ``` +### Google Embeddings +!!! info + This driver requires the `drivers-embedding-google` [extra](../index.md#extras). + +The [GoogleEmbeddingDriver](../../reference/griptape/drivers/embedding/google_embedding_driver.md) uses the [Google Embeddings API](https://ai.google.dev/tutorials/python_quickstart#use_embeddings). + +```python +from griptape.drivers import GoogleEmbeddingDriver + +embeddings = GoogleEmbeddingDriver().embed_string("Hello world!") + +# display the first 3 embeddings +print(embeddings[:3]) +``` +``` +[0.0588633, 0.0033929371, -0.072810836] +``` + ### Hugging Face Hub Embeddings !!! info diff --git a/docs/griptape-framework/drivers/prompt-drivers.md b/docs/griptape-framework/drivers/prompt-drivers.md index aaa131c..bbfec78 100644 --- a/docs/griptape-framework/drivers/prompt-drivers.md +++ b/docs/griptape-framework/drivers/prompt-drivers.md @@ -219,6 +219,33 @@ agent = Agent( agent.run('Where is the best place to see cherry blossums in Japan?') ``` +### Google + +!!! info + This driver requires the `drivers-prompt-google` [extra](../index.md#extras). + +The [GooglePromptDriver](../../reference/griptape/drivers/prompt/google_prompt_driver.md) connects to the [Google Generative AI](https://ai.google.dev/tutorials/python_quickstart#generate_text_from_text_inputs) API. + +```python +import os +from griptape.structures import Agent +from griptape.drivers import GooglePromptDriver +from griptape.config import StructureConfig, StructureGlobalDriversConfig + +agent = Agent( + config=StructureConfig( + global_drivers=StructureGlobalDriversConfig( + prompt_driver=GooglePromptDriver( + model="gemini-pro", + api_key=os.environ['GOOGLE_API_KEY'], + ) + ) + ) +) + +agent.run('Briefly explain how a computer works to a young child.') +``` + ### Hugging Face Hub !!! info diff --git a/docs/griptape-framework/misc/tokenizers.md b/docs/griptape-framework/misc/tokenizers.md index 259d10b..b523d04 100644 --- a/docs/griptape-framework/misc/tokenizers.md +++ b/docs/griptape-framework/misc/tokenizers.md @@ -49,6 +49,19 @@ print(tokenizer.count_input_tokens_left("Hello world!")) print(tokenizer.count_output_tokens_left("Hello world!")) ``` +### Google + +```python +import os +from griptape.tokenizers import GoogleTokenizer + +tokenizer = GoogleTokenizer(model="gemini-pro", api_key=os.environ["GOOGLE_API_KEY"]) + +print(tokenizer.count_tokens("Hello world!")) +print(tokenizer.count_input_tokens_left("Hello world!")) +print(tokenizer.count_output_tokens_left("Hello world!")) +``` + ### Hugging Face ```python from transformers import AutoTokenizer diff --git a/docs/griptape-framework/structures/config.md b/docs/griptape-framework/structures/config.md index fa1688f..af683ba 100644 --- a/docs/griptape-framework/structures/config.md +++ b/docs/griptape-framework/structures/config.md @@ -34,6 +34,18 @@ agent = Agent( ) ``` +#### Google +The [Google Structure Config](../../reference/griptape/config/structure_config.md#griptape.config.structure_config.GoogleStructureConfig) provides default Drivers for Google's Gemini APIs. + +```python +from griptape.structures import Agent +from griptape.config import GoogleStructureConfig + +agent = Agent( + config=GoogleStructureConfig() +) +``` + ### Custom Configs You can create your own [StructureConfig](../../reference/griptape/config/structure_config.md) by overriding the Drivers in [default_config](../../reference/griptape/config/structure_config.md#griptape.config.structure_config.StructureConfig.default_config).