### Instantiate Prompt Drivers and Pass to Structures Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/prompt-drivers.md Instantiate drivers and pass them to structures. This example shows the basic setup for using prompt drivers with Griptape Structures. ```python from griptape.structures import Agents from griptape.drivers import OpenAiChatPromptDriver agents = Agents(prompt_driver=OpenAiChatPromptDriver()) agents.run("Hello World") ``` -------------------------------- ### Install Neovim Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/logs/prompt_summary_tool_1.txt Install the compiled Neovim application to your system using 'sudo make install'. This command places the executables and related files in the appropriate system directories. ```bash sudo make install ``` -------------------------------- ### MkDocs Serve Output Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/contributing.md Example output when serving the Griptape documentation locally with MkDocs. This shows the build process and the local server address. ```text INFO - Building documentation... INFO - Cleaning site directory INFO - Documentation built in 0.19 seconds INFO - [09:28:33] Watching paths for changes: 'docs', 'mkdocs.yml' INFO - [09:28:33] Serving on http://127.0.0.1:8000/ INFO - [09:28:37] Browser connected: http://127.0.0.1:8000/ ``` -------------------------------- ### Hello World Example in Python Source: https://github.com/griptape-ai/griptape/blob/main/README.md A minimal example demonstrating basic Griptape usage with a prompt task. Ensure you have the necessary OpenAI drivers and rules configured. ```python from griptape.drivers.prompt.openai import OpenAiChatPromptDriver from griptape.rules import Rule from griptape.tasks import PromptTask task = PromptTask( prompt_driver=OpenAiChatPromptDriver(model="gpt-4.1"), rules=[Rule("Keep your answer to a few sentences.")], ) result = task.run("How do I do a kickflip?") print(result.value) ``` ```text To do a kickflip, start by positioning your front foot slightly angled near the middle of the board and your back foot on the tail. Pop the tail down with your back foot while flicking the edge of the board with your front foot to make it spin. Jump and keep your body centered over the board, then catch it with your feet and land smoothly. Practice and patience are key! ``` -------------------------------- ### Install Griptape Dependencies Source: https://github.com/griptape-ai/griptape/blob/main/CONTRIBUTING.md Installs all project dependencies using Make. Ensure you have Make installed. ```shell make install ``` -------------------------------- ### Install Griptape Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/logs/web_search_drivers_perplexity.txt Install the Griptape framework using pip. This command installs all necessary packages. ```bash pip install griptape-all ``` -------------------------------- ### Install Docs Dependencies with uv Source: https://github.com/griptape-ai/griptape/blob/main/docs/contributing.md Install the necessary dependencies for contributing to Griptape documentation using the 'docs' extra with uv. ```bash uv install --group docs ``` -------------------------------- ### Install Core Griptape Dependencies with uv Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/index.md Install only the core Griptape dependencies using uv. This provides a minimal setup for essential features. ```bash uv add griptape ``` -------------------------------- ### Install Griptape with Pip Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/index.md Install Griptape with all optional dependencies using pip. The -U flag ensures you get the latest version. ```bash pip install "griptape[all]" -U ``` -------------------------------- ### Install Litestar Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_13.txt Use pip to install the Litestar framework. ```bash pip install litestar ``` -------------------------------- ### Task and Workflow Example in Python Source: https://github.com/griptape-ai/griptape/blob/main/README.md An example demonstrating a Griptape workflow for researching open-source projects. It utilizes multiple tasks, prompt drivers, and tools, including web search and scraping. The output is structured using Pydantic models. ```python from griptape.drivers.prompt.openai_chat_prompt_driver import OpenAiChatPromptDriver from griptape.drivers.web_search.duck_duck_go import DuckDuckGoWebSearchDriver from griptape.rules import Rule, Ruleset from griptape.structures import Workflow from griptape.tasks import PromptTask, TextSummaryTask from griptape.tools import WebScraperTool, WebSearchTool from griptape.utils import StructureVisualizer from pydantic import BaseModel class Feature(BaseModel): name: str description: str emoji: str class Output(BaseModel): answer: str key_features: list[Feature] projects = ["griptape", "langchain", "crew-ai", "pydantic-ai"] prompt_driver = OpenAiChatPromptDriver(model="gpt-4.1") workflow = Workflow( tasks=[ [ PromptTask( id=f"project-{project}", input="Tell me about the open source project: {{ project }}.", prompt_driver=prompt_driver, context={"project": projects}, output_schema=Output, tools=[ WebSearchTool( web_search_driver=DuckDuckGoWebSearchDriver(), ), WebScraperTool(), ], child_ids=["summary"], ) for project in projects ], TextSummaryTask( input="{{ parents_output_text }}", id="summary", rulesets=[ Ruleset( name="Format", rules=[Rule("Be detailed."), Rule("Include emojis.")] ) ], ), ] ) workflow.run() print(StructureVisualizer(workflow).to_url()) ``` ```text Output: Here's a detailed summary of the open-source projects mentioned: 1. **Griptape** 🛠️: - Griptape is a modular Python framework designed for creating AI-powered applications. It focuses on securely connecting to enterprise data and APIs. The framework provides structured components like Agents, Pipelines, and Workflows, allowing for both parallel and sequential operations. It includes built-in tools and supports custom tool creation for data and service interaction. 2. **LangChain** 🔗: - LangChain is a framework for building applications powered by Large Language Models (LLMs). It offers a standard interface for models, embeddings, and vector stores, facilitating real-time data augmentation and model interoperability. LangChain integrates with various data sources and external systems, making it adaptable to evolving technologies. 3. **CrewAI** 🤖: - CrewAI is a standalone Python framework for orchestrating multi-agent AI systems. It allows developers to create and manage AI agents that collaborate on complex tasks. CrewAI emphasizes ease of use and scalability, providing tools and documentation to help developers build AI-powered solutions. 4. **Pydantic-AI** 🧩: - Pydantic-AI is a Python agent framework that simplifies the development of production-grade applications with Generative AI. Built on Pydantic, it supports various AI models and provides features like type-safe design, structured response validation, and dependency injection. Pydantic-AI aims to bring the ease of FastAPI development to AI applications. These projects offer diverse tools and frameworks for developing AI applications, each with unique features and capabilities tailored to different aspects of AI development. ``` ```mermaid graph TD; griptape-->summary; langchain-->summary; pydantic-ai-->summary; crew-ai-->summary; ``` -------------------------------- ### Install Griptape OpenWeather Extension Source: https://github.com/griptape-ai/griptape/blob/main/MIGRATION.md The `OpenWeatherTool` is now available in the `griptape-openweather` extension. Install it using poetry to access weather-related functionalities. ```bash poetry add git+https://github.com/griptape-ai/griptape-open-weather.git ``` -------------------------------- ### Instantiate Event Listener Drivers in a Structure Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/event-listener-drivers.md Instantiate Event Listener Drivers and pass them to Event Listeners in your Structure. This example shows a general setup. ```python from griptape.structures import Structure from griptape.listeners import EventListener from griptape.drivers import AmazonSqsEventListenerDriver structure = Structure(event_listeners=[ EventListener(driver=AmazonSqsEventListenerDriver(queue_url="my-queue-url")), ]) ``` -------------------------------- ### Install Torch Separately Source: https://github.com/griptape-ai/griptape/blob/main/MIGRATION.md Provides instructions for installing `torch` separately after its removal from the `transformers` dependency extras. ```bash pip install griptape[drivers-prompt-huggingface-hub] pip install torch ``` -------------------------------- ### Install Griptape Google Extension Source: https://github.com/griptape-ai/griptape/blob/main/MIGRATION.md Google tools have been moved to the `griptape-google` extension. Install it using poetry to access tools like `GoogleGmailTool`. ```bash poetry add git+https://github.com/griptape-ai/griptape-google.git ``` -------------------------------- ### Install FastAPI Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_12.txt Install FastAPI with standard extras. Ensure quotes are used for compatibility across terminals. ```bash $ pip install "fastapi[standard]" ``` -------------------------------- ### Handling GET Requests with Optional Query Parameters Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_12.txt Demonstrates how to handle GET requests with an optional query parameter 'q'. If the parameter is not provided, it defaults to None. ```python return {"item_name": item.name, "item_id": item_id} ``` -------------------------------- ### Install Specific Optional Dependencies with uv Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/index.md Install Griptape with specific optional dependencies, such as Anthropic and Pinecone drivers, using uv. ```bash uv add "griptape[drivers-prompt-anthropic,drivers-vector-pinecone]" ``` -------------------------------- ### Task Hooks Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/tasks.md Illustrates the use of 'on_before_run' and 'on_after_run' hooks for custom logic before and after a Task executes. ```python from griptape.tasks import PromptTask class MyTask(PromptTask): def on_before_run(self): print("Before run") def on_after_run(self): print("After run") task = MyTask(input="Hello") task.run() ``` -------------------------------- ### Import OpenWeatherTool from Griptape OpenWeather Extension Source: https://github.com/griptape-ai/griptape/blob/main/MIGRATION.md After installing the `griptape-openweather` extension, import `OpenWeatherTool` from `griptape.openweather.tools`. ```python from griptape.openweather.tools import OpenWeatherTool ``` -------------------------------- ### Build a Workflow for Project Research Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_11.txt This example demonstrates setting up a Griptape workflow to research multiple open-source projects. It defines custom Pydantic models for output and utilizes web search tools within prompt tasks. Ensure all necessary drivers, tasks, and tools are imported. ```python from griptape.drivers.prompt.openai_chat_prompt_driver import OpenAiChatPromptDriver from griptape.drivers.web_search.duck_duck_go import DuckDuckGoWebSearchDriver from griptape.rules import Rule, Ruleset from griptape.structures import Workflow from griptape.tasks import PromptTask, TextSummaryTask from griptape.tools import WebScraperTool, WebSearchTool from griptape.utils import StructureVisualizer from pydantic import BaseModel class Feature(BaseModel): name: str description: str emoji: str class Output(BaseModel): answer: str key_features: list[Feature] projects = ["griptape", "langchain", "crew-ai", "pydantic-ai"] prompt_driver = OpenAiChatPromptDriver(model="gpt-4o") workflow = Workflow( tasks=[ [ PromptTask( id=f"project-{project}", input="Tell me about the open source project: {{ project }}", prompt_driver=prompt_driver, context={"project": projects}, output_schema=Output, tools=[ WebSearchTool( web_search_driver=DuckDuckGoWebSearchDriver(), ), ], ) ] ] ) ``` -------------------------------- ### Litestar Class-Based Controller Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_13.txt Implement class-based controllers for route handlers in Litestar. This example shows POST, GET, PATCH, and PUT methods with different path parameters and DTOs. ```python from typing import List, Optional from datetime import datetime from litestar import Controller, get, post, put, patch, delete from litestar.dto import DTOData from pydantic import UUID4 from my_app.models import User, PartialUserDTO class UserController(Controller): path = "/users" @post() async def create_user(self, data: User) -> User: ... @get() async def list_users(self) -> List[User]: ... @get(path="/{date:int}") async def list_new_users(self, date: datetime) -> List[User]: ... @patch(path="/{user_id:uuid}", dto=PartialUserDTO) async def partial_update_user( self, user_id: UUID4, data: DTOData[PartialUserDTO] ) -> User: ... @put(path="/{user_id:uuid}") async def update_user(self, user_id: UUID4, data: User) -> User: ... @get(path="/{user_name:str}") ``` -------------------------------- ### Enable Conversation Memory in a Structure Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/conversation-memory.md By default, all structures are created with ConversationMemory. This example shows the default setup. ```python from griptape.structures import Agent agent = Agent() agent.run("Hello World") ``` -------------------------------- ### Equivalent Task Relationship Setups Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/workflows.md Demonstrates equivalent ways to set up task relationships using bitshift operators and explicit method calls. ```python task1 >> task2 task1.add_child(task2) ``` ```python task2 << task1 task2.add_parent(task1) ``` ```python task3 >> [task4, task5] task3.add_children([task4, task5]) ``` -------------------------------- ### Initialize RagEngine with Griptape Cloud Vector Store Driver Source: https://github.com/griptape-ai/griptape/blob/main/MIGRATION.md This snippet shows how to initialize a RagEngine using the Griptape Cloud Vector Store Driver for retrieval and a PromptResponseRagModule for responses. Ensure GT_CLOUD_API_KEY and GT_CLOUD_KB_ID environment variables are set. ```python from __future__ import annotations import os from griptape.drivers import GriptapeCloudVectorStoreDriver from griptape.engines.rag import RagEngine from griptape.engines.rag.modules import ( PromptResponseRagModule, VectorStoreRetrievalRagModule, ) from griptape.engines.rag.stages import ( ResponseRagStage, RetrievalRagStage, ) from griptape.structures import Agent from griptape.tools import RagTool engine = RagEngine( retrieval_stage=RetrievalRagStage( retrieval_modules=[ VectorStoreRetrievalRagModule( vector_store_driver=GriptapeCloudVectorStoreDriver( api_key=os.environ["GT_CLOUD_API_KEY"], knowledge_base_id=os.environ["GT_CLOUD_KB_ID"], ) ) ] ), response_stage=ResponseRagStage( response_modules=[PromptResponseRagModule()], ), ) agent = Agent( tools=[ RagTool( description="Contains information about the company and its operations", rag_engine=engine, ), ], ) agent.run("What is the company's corporate travel policy?") ``` -------------------------------- ### Use MarkdownifyWebScraperDriver Directly Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/web-scraper-drivers.md Example of using MarkdownifyWebScraperDriver to scrape a URL and get markdown output. Requires 'drivers-web-scraper-markdownify' extra and playwright browsers. ```python from griptape.drivers import MarkdownifyWebScraperDriver driver = MarkdownifyWebScraperDriver() result = driver.scrape_url("https://www.example.com") print(result.value) ``` -------------------------------- ### Initialize Griptape Project with uv Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/index.md Initialize a new Griptape project using uv, a fast dependency manager. This command creates a new project directory. ```bash uv init griptape-quickstart ``` -------------------------------- ### Define User Routes with Litestar Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_14.txt Example of defining route handlers for user-related operations (update, get by name, get by ID, delete) using Litestar decorators. Ensure all route handlers have type-annotated return values for OpenAPI generation and data validation. ```python from litestar import Litestar, get, post, put, delete from litestar.dto import DTOData from uuid import UUID4 from .models import User from .schemas import PartialUserDTO class UserController: @post() async def create_user(self, data: DTOData[PartialUserDTO]) -> User: ... @put(path="/{user_id:uuid}") async def update_user(self, user_id: UUID4, data: User) -> User: ... @get(path="/{user_name:str}") async def get_user_by_name(self, user_name: str) -> Optional[User]: ... @get(path="/{user_id:uuid}") async def get_user(self, user_id: UUID4) -> User: ... @delete(path="/{user_id:uuid}") async def delete_user(self, user_id: UUID4) -> None: ... ``` -------------------------------- ### FastAPI Request Validation Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_13.txt This example demonstrates how FastAPI validates path parameters, optional query parameters, and request bodies for GET and PUT requests. It ensures data types are correct and handles missing or invalid data with clear error messages. ```python http://127.0.0.1:8000/items/foo?q=somequery ``` -------------------------------- ### Define Root Endpoint in FastAPI Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_13.txt This snippet defines the root endpoint for a FastAPI application, returning a simple JSON response. It's a basic example for starting a web service. ```python @app.get("/") def read_root(): return {"Hello": "World"} ``` -------------------------------- ### Build a Simple Workflow Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/workflows.md This example demonstrates building a basic workflow to generate a world, create characters, and write a story. It uses the declarative syntax with `parent_ids`. ```python from griptape.structures import Workflow from griptape.tasks import WorkflowTask workflow = Workflow( tasks=[ WorkflowTask( id="world", task=lambda: print("Generating a fantasy world...") ), WorkflowTask( id="story", task=lambda: print("Writing a story...") ) ], parents_ids={"story": ["world"]} ) workflow.run() print(workflow.output) ``` -------------------------------- ### Vectorize Webpage and Setup Griptape Agent Source: https://github.com/griptape-ai/griptape/blob/main/docs/recipes/talk-to-a-webpage.md This Python script shows how to use Griptape to vectorize a webpage and configure an agent with the RagClient tool for conversational access to the webpage's content. Ensure the necessary libraries are installed. ```python from griptape.agents import Agent from griptape.tools import RagClient agent = Agent( tools=[ RagClient( url="http://localhost:8000", api_key="sk-1234567890", ) ] ) agent.run("What is the content of the webpage?") ``` -------------------------------- ### Using VectorStoreTool with Local Driver Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/index.md Example of initializing and using the VectorStoreTool with a local vector store driver for querying vector databases. ```python --8<-- "docs/griptape-framework/tools/official-tools/src/vector_store_tool_1.py" ``` -------------------------------- ### Prevent Task Memory Looping in Griptape Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/task-memory.md Configure Tools to prevent LLMs from entering infinite loops by ensuring query tools do not write back to Task Memory. This example demonstrates a correct setup to avoid such loops. ```python --8<-- "docs/griptape-framework/structures/src/task_memory_8.py" ``` -------------------------------- ### Python Video Upload and Query Source: https://github.com/griptape-ai/griptape/blob/main/docs/recipes/talk-to-a-video.md This Python script uploads a video file using Gemini's file API and then queries it using an Agent. Note that this example relies on Gemini-specific features and requires the appropriate setup for file uploads. ```python from griptape.drivers import GeminiPromptDriver from griptape.agents import Agent from griptape.artifacts import GenericArtifact # Initialize the Gemini Prompt Driver # Ensure you have your GOOGLE_API_KEY set in your environment variables prompt_driver = GeminiPromptDriver() # Initialize the Agent agent = Agent(prompt_driver=prompt_driver) # Upload the video file using Gemini's file API # Replace 'path/to/your/video.mp4' with the actual path to your video file video_file = prompt_driver.upload_file('path/to/your/video.mp4', display_name='griptape-comfyui.mp4') # Create a GenericArtifact from the uploaded video file video_artifact = GenericArtifact(value=video_file) # Ask a question about the video response = agent.run("Are there any scenes that show a character with earings?", input=video_artifact) # Print the response print(response.value) ``` -------------------------------- ### Vectorize PDF and Setup Agent for Conversation Source: https://github.com/griptape-ai/griptape/blob/main/docs/recipes/talk-to-a-pdf.md This Python script vectorizes a PDF document and initializes a Griptape agent. The agent is configured with rules and the VectorStoreTool to enable conversations based on the PDF's content. Ensure necessary libraries are installed. ```python from griptape.tools import VectorStoreTool from griptape.agents import Agent from griptape.rules import Rules # Vectorize the PDF vector_store_tool = VectorStoreTool(name="pdf_vector_store", path="attention_is_all_you_need.pdf") # Setup the agent agent = Agent( tools=[vector_store_tool], rules=Rules("You are a helpful assistant that answers questions about the provided PDF.") ) # Start conversation response = agent.run("What is the core idea of the attention mechanism?") print(response) ``` -------------------------------- ### PromptTask with Tools Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/tasks.md Shows how to initialize a PromptTask with a list of Tools that the LLM can utilize via Chain of Thought (CoT) reasoning. ```python from griptape.tasks import PromptTask from griptape.tools import Calculator, Date task = PromptTask( input="What is the current date and time?", tools=[Calculator(), Date()] ) task.run() ``` -------------------------------- ### Use Tools in Griptape Pipelines Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/index.md Example of a Pipeline using tools in Griptape. Ensure necessary imports and configurations are in place before execution. ```python from griptape.drivers import OpenAiPromptDriver from griptape.pipelines import Pipeline from griptape.tools import Calculator, FileLoader class MyPipeline(Pipeline): def __init__(self): super().__init__( prompt_driver=OpenAiPromptDriver( model="gpt-3.5-turbo", # use_native_tools=True # Uncomment to use native tool calling ), tools=[ Calculator(), FileLoader(), ]) def run(self, value): return self.prompt_driver.prompt(value) pipeline = MyPipeline() # Example usage: result = pipeline.run("What is 2 + 2?") print(result) result = pipeline.run("Load the content of the file 'test.txt'") print(result) ``` -------------------------------- ### Initialize Griptape Cloud Tool Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/index.md Instantiates the Griptape Cloud Tool for integrating with Griptape Cloud's hosted Tools. Requires a hosted Tool and an API Key. ```python from griptape.tools import GriptapeCloudToolTool tool = GriptapeCloudToolTool(api_key="my-api-key") ``` -------------------------------- ### Basic Hello World App with Litestar Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_13.txt Create a simple Litestar application with a 'hello world' endpoint. This example demonstrates the basic structure of a Litestar app and how to define a route handler. ```python from litestar import Litestar, get @get("/") def hello_world() -> dict[str, str]: """Keeping the tradition alive with hello world.""" return {"hello": "world"} app = Litestar(route_handlers=[hello_world]) ``` -------------------------------- ### Example JSON Data Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/logs/rest_api_tool_1.txt This is an example of JSON data structure, likely representing a list of posts or similar items. ```json [ { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" }, { "userId": 1, "id": 2, "title": "qui est esse", "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non optio " }, { "userId": 1, "id": 3, "title": "ea molestias quasi exercitationem repellat qui ipsa situtation", "body": "et iusto sed quo iure\nvoluptatem occaecati omne is voluptatem repellendus excepturi exercitationem quasi" }, { "userId": 1, "id": 4, "title": "et perferendis eos autem", "body": "ipsum autem quos voluptatem repellat voluptatem autem" }, { "userId": 1, "id": 5, "title": "dolorem neque autem", "body": "voluptatem autem autem autem" }, { "userId": 1, "id": 6, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 7, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 8, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 9, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 10, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 11, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 12, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 13, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 14, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 15, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 16, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 17, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 18, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 19, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 1, "id": 20, "title": "dolorem autem", "body": "autem autem autem" }, { "userId": 10, "id": 100, "title": "at nam consequatur ea laborum ea harum", "body": "cupiditate quo est a modi nesciunt soluta ipsum voluptas error itaque dicta in autem qui minus magnam et distinctio eum accusamus ratione error aut" } ] ``` -------------------------------- ### Install FastAPI Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_13.txt Install FastAPI and its standard dependencies using pip. Ensure quotes are used for compatibility across terminals. ```bash pip install "fastapi[standard]" ``` -------------------------------- ### Serve Documentation Locally with MkDocs Source: https://github.com/griptape-ai/griptape/blob/main/docs/contributing.md Serve the Griptape documentation locally using MkDocs after installing dependencies. This command watches for changes and rebuilds the documentation. ```bash uv run mkdocs serve ``` -------------------------------- ### Hello World in Vim Script Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/logs/tasks_reflect_on_tool_use.txt A basic 'Hello, World!' program in Vim script. This is a simple example to demonstrate output. ```vimscript " This is the Hello World program in Vim script. echo "Hello, world!" ``` -------------------------------- ### Initialize Email Tool Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/index.md Instantiates the Email Tool for sending emails. ```python from griptape.tools import EmailTool tool = EmailTool() ``` -------------------------------- ### Install ccache for Faster Rebuilds Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/logs/prompt_summary_tool_1.txt Install ccache using Homebrew. This utility can significantly speed up subsequent rebuilds by caching compilation results. ```bash brew install ccache ``` -------------------------------- ### Assistant Task Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/tasks.md Allows Structures to interface with external assistant services. Requires an Assistant Driver to be configured. ```python from griptape.tasks import AssistantTask assistant_task = AssistantTask( prompt="Write a poem about the sea", assistant_driver=my_assistant_driver ) ``` -------------------------------- ### Install Griptape AWS Extension Source: https://github.com/griptape-ai/griptape/blob/main/MIGRATION.md AWS tools are now part of the `griptape-aws` extension. Install this extension with poetry to use tools like `AwsS3Tool`. ```bash poetry add git+https://github.com/griptape-ai/griptape-aws.git ``` -------------------------------- ### Create a Basic Prompt Task Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/index.md This snippet demonstrates how to create and run a basic Prompt Task using Griptape. Ensure you have the necessary API keys set as environment variables. ```python from griptape.tasks import PromptTask from griptape.structures import Agent agent = Agent() agent.add_task(PromptTask("What is the capital of France?")) agent.run() ``` -------------------------------- ### Use Web Search Drivers with Structures Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/web-search-drivers.md Example of integrating Web Search Drivers within Griptape Structures for agent functionality. Ensure the correct Python file is referenced for the driver implementation. ```python from griptape.structures import Agent from griptape.tools import WebSearch agent = Agent(tools=[ WebSearch(driver=GoogleWebSearchDriver(api_key=os.environ.get("GOOGLE_API_KEY"))) ]) agent.run("What is the weather in San Francisco?") ``` -------------------------------- ### Perplexity Web Search Driver Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/web-search-drivers.md Example usage of the Perplexity Web Search Driver. Requires a Perplexity Sonar API key. ```python from griptape.drivers import PerplexityWebSearchDriver web_search_driver = PerplexityWebSearchDriver( api_key="YOUR_PERPLEXITY_API_KEY" ) results = web_search_driver.search("What is Griptape?") ``` -------------------------------- ### Python Pipeline Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/structures/pipelines.md This Python code demonstrates how to define and run a Griptape Pipeline with multiple tasks. Ensure the necessary imports are present. ```python from griptape.structures import Pipeline from griptape.tasks import PromptTask pipeline = Pipeline( tasks=[ PromptTask("Write a short story about a robot learning to love."), PromptTask("Summarize the story in 1 sentence."), ] ) result = pipeline.run() print(result.output) ``` -------------------------------- ### Litestar Class-Based Controller Example Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/logs/index_12.txt Example demonstrating a Litestar controller with multiple route handlers for CRUD operations. Requires User and PartialUserDTO models. ```python from typing import List, Optional from datetime import datetime from litestar import Controller, get, post, put, patch, delete from litestar.dto import DTOData from pydantic import UUID4 from my_app.models import User, PartialUserDTO class UserController(Controller): path = "/users" @post() async def create_user(self, data: User) -> User: ... @get() async def list_users(self) -> List[User]: ... @get(path="/{date:int}") async def list_new_users(self, date: datetime) -> List[User]: ... @patch(path="/{user_id:uuid}", dto=PartialUserDTO) async def partial_update_user( self, user_id: UUID4, data: DTOData[PartialUserDTO] ) -> User: ... @put(path="/{user_id:uuid}") async def update_user(self, user_id: UUID4, data: ``` -------------------------------- ### Initialize Griptape Cloud Assistant Driver Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/assistant-drivers.md Use this driver to run Griptape Cloud Assistants. Ensure you have the necessary Griptape Cloud setup. ```python from griptape.drivers import GriptapeCloudAssistantDriver driver = GriptapeCloudAssistantDriver( api_key="YOUR_API_KEY", api_url="YOUR_API_URL" ) ``` -------------------------------- ### Eval Engine Initialization with Criteria Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/engines/eval-engines.md Initialize an Eval Engine with predefined criteria for evaluation. Griptape will automatically generate evaluation steps from these criteria. ```python eval_engine = EvalEngine(criteria={'test': 'This is a test'}) result = eval_engine.evaluate_output(output='This is a test') print(result.score) print(result.reason) ``` -------------------------------- ### REST API GET Request Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/tools/official-tools/logs/rest_api_tool_1.txt This action represents a GET request to a REST API. It is used to retrieve data from a specific endpoint. Ensure the API endpoint is correctly configured. ```json { "tag": "get_post_1", "name": "RestApiTool", "path": "get", "input": { "values": {} } } ``` -------------------------------- ### Initialize Griptape Cloud Image Generation Driver Source: https://github.com/griptape-ai/griptape/blob/main/docs/griptape-framework/drivers/image-generation-drivers.md Provides access to image generation models hosted by Griptape Cloud, currently supporting 'dall-e-3'. ```python from griptape.drivers import GriptapeCloudImageGenerationDriver image_generation_driver = GriptapeCloudImageGenerationDriver( api_key="MY_API_KEY" ) ```