-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
959 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
search: | ||
boost: 2 | ||
--- | ||
|
||
## Overview | ||
|
||
File Manager Drivers can be used to load and save files with local or external file systems. | ||
|
||
You can use File Manager Drivers with Loaders: | ||
|
||
```python | ||
--8<-- "docs/griptape-framework/drivers/src/file_manager_driver.py" | ||
``` | ||
|
||
Or use them independently as shown below for each driver: | ||
|
||
## File Manager Drivers | ||
|
||
### Griptape Cloud | ||
|
||
!!! info | ||
This driver requires the `drivers-file-manager-griptape-cloud` [extra](../index.md#extras). | ||
|
||
The [GriptapeCloudFileManagerDriver](../../reference/griptape/drivers/file_manager/griptape_cloud_file_manager_driver.md) allows you to load and save files sourced from Griptape Cloud Asset and Bucket resources. | ||
|
||
```python | ||
--8<-- "docs/griptape-framework/drivers/src/griptape_cloud_file_manager_driver.py" | ||
``` | ||
|
||
### Local | ||
|
||
The [LocalFileManagerDriver](../../reference/griptape/drivers/file_manager/local_file_manager_driver.md) allows you to load and save files sourced from a local directory. | ||
|
||
```python | ||
--8<-- "docs/griptape-framework/drivers/src/local_file_manager_driver.py" | ||
``` | ||
|
||
### Amazon S3 | ||
|
||
!!! info | ||
This driver requires the `drivers-file-manager-amazon-s3` [extra](../index.md#extras). | ||
|
||
The [LocalFile ManagerDriver](../../reference/griptape/drivers/file_manager/amazon_s3_file_manager_driver.md) allows you to load and save files sourced from an Amazon S3 bucket. | ||
|
||
```python | ||
--8<-- "docs/griptape-framework/drivers/src/amazon_s3_file_manager_driver.py" | ||
``` |
24 changes: 24 additions & 0 deletions
24
docs/griptape-framework/drivers/src/amazon_s3_file_manager_driver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
|
||
import boto3 | ||
|
||
from griptape.drivers import AmazonS3FileManagerDriver | ||
|
||
amazon_s3_file_manager_driver = AmazonS3FileManagerDriver( | ||
bucket=os.environ["AMAZON_S3_BUCKET"], | ||
session=boto3.Session( | ||
region_name=os.environ["AWS_DEFAULT_REGION"], | ||
aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"], | ||
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"], | ||
), | ||
) | ||
|
||
# Download File | ||
file_contents = amazon_s3_file_manager_driver.load_file(os.environ["AMAZON_S3_KEY"]) | ||
|
||
print(file_contents) | ||
|
||
# Upload File | ||
response = amazon_s3_file_manager_driver.save_file(os.environ["AMAZON_S3_KEY"], file_contents.value) | ||
|
||
print(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from griptape.drivers import LocalFileManagerDriver | ||
from griptape.loaders import TextLoader | ||
|
||
local_file_manager_driver = LocalFileManagerDriver() | ||
|
||
loader = TextLoader(file_manager_driver=local_file_manager_driver) | ||
text_artifact = loader.load("tests/resources/test.txt") | ||
|
||
print(text_artifact.value) |
18 changes: 18 additions & 0 deletions
18
docs/griptape-framework/drivers/src/griptape_cloud_file_manager_driver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
from griptape.drivers import GriptapeCloudFileManagerDriver | ||
|
||
gtc_file_manager_driver = GriptapeCloudFileManagerDriver( | ||
api_key=os.environ["GT_CLOUD_API_KEY"], | ||
bucket_id=os.environ["GT_CLOUD_BUCKET_ID"], | ||
) | ||
|
||
# Download File | ||
file_contents = gtc_file_manager_driver.load_file(os.environ["GT_CLOUD_ASSET_NAME"]) | ||
|
||
print(file_contents) | ||
|
||
# Upload File | ||
response = gtc_file_manager_driver.save_file(os.environ["GT_CLOUD_ASSET_NAME"], file_contents.value) | ||
|
||
print(response) |
13 changes: 13 additions & 0 deletions
13
docs/griptape-framework/drivers/src/local_file_manager_driver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from griptape.drivers import LocalFileManagerDriver | ||
|
||
local_file_manager_driver = LocalFileManagerDriver() | ||
|
||
# Download File | ||
file_contents = local_file_manager_driver.load_file("tests/resources/test.txt") | ||
|
||
print(file_contents) | ||
|
||
# Upload File | ||
response = local_file_manager_driver.save_file("tests/resources/test.txt", file_contents.value) | ||
|
||
print(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from griptape.drivers import OpenAiChatPromptDriver | ||
from griptape.events import ActionChunkEvent, EventBus, EventListener, TextChunkEvent | ||
from griptape.structures import Pipeline | ||
from griptape.tasks import ToolkitTask | ||
from griptape.tools import PromptSummaryTool, WebScraperTool | ||
|
||
EventBus.add_event_listeners( | ||
[ | ||
EventListener( | ||
lambda e: print(str(e), end="", flush=True), | ||
event_types=[TextChunkEvent], | ||
), | ||
EventListener( | ||
lambda e: print(str(e), end="", flush=True), | ||
event_types=[ActionChunkEvent], | ||
), | ||
] | ||
) | ||
|
||
pipeline = Pipeline() | ||
pipeline.add_tasks( | ||
ToolkitTask( | ||
"Based on https://griptape.ai, tell me what griptape is.", | ||
prompt_driver=OpenAiChatPromptDriver(model="gpt-4o", stream=True), | ||
tools=[WebScraperTool(off_prompt=True), PromptSummaryTool(off_prompt=False)], | ||
) | ||
) | ||
|
||
pipeline.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.