Skip to content

Instantly share code, notes, and snippets.

@kyleroche
Created May 13, 2023 20:10
Show Gist options
  • Select an option

  • Save kyleroche/3d57c44c502a986ba2666913f6ea3933 to your computer and use it in GitHub Desktop.

Select an option

Save kyleroche/3d57c44c502a986ba2666913f6ea3933 to your computer and use it in GitHub Desktop.
Sample moving SQL results to file manager (on a ramp)
from griptape.memory import Memory
from griptape.executors import DockerExecutor
from griptape.ramps import TextStorageRamp, BlobStorageRamp
from griptape.structures import Pipeline
from griptape.tasks import ToolkitTask, PromptTask
from griptape.tools import WebScraper, TextProcessor, FileManager, SqlClient
# Ramps enable LLMs to store and manipulate data without ever looking at it directly.
text_storage = TextStorageRamp()
blob_storage = BlobStorageRamp()
sql_client = SqlClient(
engine_url="sqlite:////path/acs-1-year-2015.sqlite",
engine_name="sqlite",
ramps={
"query": [text_storage]
}
)
# Connect a web scraper to load web pages.
web_scraper = WebScraper(
ramps={
"get_content": [text_storage]
}
)
# TextProcessor enables LLMs to summarize and query text.
text_processor = TextProcessor(
ramps={
"summarize": [text_storage],
"query": [text_storage]
}
)
# File manager can load and store files locally.
file_manager = FileManager(
ramps={
"load": [blob_storage],
"save": [text_storage, blob_storage]
}
)
# Pipelines represent sequences of tasks.
pipeline = Pipeline(
memory=Memory()
)
pipeline.add_tasks(
# Load up the first argument from `pipeline.run`.
ToolkitTask(
"{{ args[0] }}",
tools=[file_manager, sql_client]
#executor=DockerExecutor()
)
)
result = pipeline.run("using the sql table states, get the per capita income by state and store it in states.txt")
#result = pipeline.run("copy README.md to README_new.md")
print(result.output.to_text())
@kyleroche
Copy link
Author

[05/13/23 13:07:48] INFO     Task fd2a5d776c984277ba8fc9926e76706d              
                             Input: using the sql table states, get the per     
                             capita income by state and store it in states.txt  
[05/13/23 13:07:55] INFO     Subtask 467e69103d004cb2932e3ec2fc0ee4c6           
                             Thought: I can use the SqlClient tool to execute a 
                             SQL query that retrieves the per capita income by  
                             state from the table "states" and then use the     
                             FileManager tool to save the result in a file named
                             "states.txt".                                      
                             Action:                                            
                             {"type":"tool","name":"SqlClient","activity":"query
                             ","input":{"values":{"query":"SELECT state,        
                             per_capita_income FROM states;"}}}                 
[05/13/23 13:07:58] INFO     Subtask 467e69103d004cb2932e3ec2fc0ee4c6           
                             Observation: Output of "SqlClient.query" was stored
                             in ramp "TextStorageRamp" with the following       
                             artifact names: 86f7076323e147749ea22db8ac8ed8a4   
[05/13/23 13:08:04] INFO     Subtask 40296aa4810a4974ac3f2a3f5b2dc2af           
                             Action: {"type": "tool", "name": "FileManager",    
                             "activity": "save", "input": {"values": {"paths":  
                             ["states.txt"]}, "artifacts": {"sources":          
                             [{"ramp_name": "TextStorageRamp", "artifact_names":
                             ["86f7076323e147749ea22db8ac8ed8a4"]}]} }}         
[05/13/23 13:08:07] INFO     Subtask 40296aa4810a4974ac3f2a3f5b2dc2af           
                             Observation: saved successfully                    
[05/13/23 13:08:09] INFO     Task fd2a5d776c984277ba8fc9926e76706d              
                             Output: The per capita income by state has been    
                             retrieved from the "states" table and stored in    
                             "states.txt".                                      
The per capita income by state has been retrieved from the "states" table and stored in "states.txt".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment