Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Add docs for gemini
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Mar 22, 2024
1 parent 90be393 commit 509bde2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/griptape-framework/drivers/embedding-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions docs/griptape-framework/drivers/prompt-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions docs/griptape-framework/misc/tokenizers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/griptape-framework/structures/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 509bde2

Please sign in to comment.