Now that you've got your environment all set up, it's time to actually start moving. In this stage, we'll put together a basic Griptape application and see it in action.
We are going to build a very simple application. It's going to simply take in a prompt, and return the result of that prompt. For example, we will be able to ask: "What's a good place to visit in New Zealand?" and it will give us an answer like "Abel Tasman" or "All of it".
There are multiple ways communicate with LLMs via Griptape, but the one we'll use in this example is an Agent. You can learn more about Agents in documentation, but here's a simple way to understand them:
Agents can do one task.
You give the Agent a prompt, it thinks for a bit, figures things out, and then returns a result. While that sounds relatively simple, it's actually quite cool. You can give the agent tools (WebScraper, Calculator, EmailClient, to name a few), you can give it rules about how to behave, and more. Agents can actually do quite a lot - but they're still one of the more simple ways of interacting with Griptape, which is why we'll use them to start with in this course.
Speaking of interacting with Griptape... we need to install it!
Just like we installed the
python_dotenv library, we need to do the same with Griptape.
Navigate to Terminal in VSCode and use
pip to install
This will take a minute to install. Another chance to enjoy a !
Now comes the moment you've all been waiting for! Actually, it's the moment before the moment. In this moment, we're going to import the Agent from the Griptape library. The moment after that is probably the one you're really waiting for. But we have to do this moment first. Live in the now.
app.py to import the agent
As you can see, we're importing the Agent from
griptape.structures. There are other structures we can work with, but again.. this is just setting up your environment. We'll talk about those in another course.
The fun part
Create the Agent
To create the Agent, we'll instantiate the class.
Run the Agent
Now you get to tell the Agent what to do. Use the Agent's
run method to execute a prompt.
Test the Agent
Let's see if our application works.
- Save your file.
- Use the Run icon in the upper right corner of VS Code, or open your terminal and type
If everything has been set up correctly, you should see the result of the
agent.run() command printed in the terminal. The exact output will depend on the current configuration and performance of the OpenAI API, but it should be a haiku about skateboarding.
Congrats! You've taken the first push and created your first Python script that works with a large language model!
You've successfully set up your development environment, installed the necessary packages, obtained your OpenAI API key, and written and run a simple Griptape application. You've done a great job, so don't forget to celebrate your progress.
Now that you've successfully completed the course, please check out these Helpful Resources to learn more about Griptape!