AI Search Engine
This example shows how to build a simple Perplexity-like answer engine that uses the Pine Context API and OpenAI to generate up-to-date natural responses.
How It Works
-
User Question The assistant receives a natural language question like “What happened to Bitcoin today?
-
Get Knowledge Context The Pine Context API analyzes the question and returns relevant information formatted as LLM-ready context.
-
Combine with LLM The relevant context is passed along with the original question to OpenAI’s API, which generates a natural language response.
Step 1: Set API Keys
For this example you will need both a Pine API Key and an OpenAI API Key. After getting the keys, put them into environment variables or directly into your python code.
Step 2: Install Dependencies
For this example we will need openai
and requests
package.
Step 3: Get Context and Sources from Pine
We write a function which calles the Pine Context API, and returns the context:
Step 4: Ask OpenAI with Context
We write a function which promps OpenAI to answer our query with Pine’s context:
Step 5: Putting Together
We now combine our functions,
Final Script
The script should look like,
You can now run the script via:
Sample Responses
“How much does it cost to enter the Encinitas Turky Trot tomorrow?”
“How’s the surf in Santa Curz today?”