Skip to main content

A planning agent

The gpt planner is a Python application that demonstrate the planning capabilities of LLMs. When you run it, it will ask the LLM to generate multiple action plans for a goal or a query. It will then ask the LLM to compare and select the best plan, and then rewrite it to answer the user query.

Since the program uses the official OpenAI Python library, we can easily change it to use a Gaia node.

Prerequisites

You will need a Gaia node ready to provide LLM services through a public URL. You can

In this tutorial, we will use a public node.

AttributeValue
API endpoint URLhttps://llama.us.gaianet.network/v1
Model Namellama

Run the agent

First, load the nodebook in colab.

Edit the code to create an OpenAI client. We will pass in the base_url here.

client = openai.OpenAI(base_url="https://llama.us.gaianet.network/v1", api_key=OPENAI_API_KEY)

Next, replace all the gpt-4o-mini model name with the llama model name in the code. Here is an example.

response = client.chat.completions.create(
model="llama",
messages=[
{"role": "system", "content": "You are a helpful assistant. Use the given plan to create a detailed and high-quality response to the user's query."},
{"role": "user", "content": f"User Query: {user_query}\n\nPlan: {best_plan}\n\nGenerate a detailed response based on this plan."}
],
temperature=0.5,
max_tokens=2000
)

Change the query to your own.

user_query = "How do I debug a TLS connection timeout?"

Finally, run the notebook to see the results!