Talk to a PDF

This example demonstrates how to vectorize a PDF of the Attention Is All You Need paper and setup a Griptape agent with rules and the VectorStoreClient tool to use it during conversations.

import os 
import io
import requests
from griptape.engines import VectorQueryEngine
from griptape.loaders import PdfLoader
from griptape.structures import Agent
from griptape.tools import VectorStoreClient
from griptape.utils import Chat
from griptape.drivers import LocalVectorStoreDriver, OpenAiEmbeddingDriver


namespace = "attention"

response = requests.get("https://arxiv.org/pdf/1706.03762.pdf")

engine = VectorQueryEngine(
    vector_store_driver=LocalVectorStoreDriver(
        embedding_driver=OpenAiEmbeddingDriver(
            api_key=os.getenv("OPENAI_API_KEY")
        )
    )
)

engine.vector_store_driver.upsert_text_artifacts(
    {
        namespace: PdfLoader().load(
            io.BytesIO(response.content)
        )
    }
)

vector_store_tool = VectorStoreClient(
    description="Contains information about the Attention Is All You Need paper. "
                "Use it to answer any related questions.",
    query_engine=engine,
    namespace=namespace
)

agent = Agent(
    tools=[vector_store_tool]
)

Chat(agent).start()