Page cover image

Perplexity AI Search and Response

The Perplexity AI Search Service Flow is designed to send a search prompt to the Perplexity AI model, retrieve relevant information, and store the results for further analysis. This flow is perfect for automating search-driven interactions, allowing you to capture and analyze AI-generated responses in a structured manner. It can be particularly useful for applications such as research automation, content generation, and decision support systems.

You can find this template in the Services Catalog under these categories:

  • AI, Contextual Basics

What's Included:

  • 1 Flow

  • 1 Object Type

  • 1 Connection

What You'll Need:

  • Access to the Perplexity API

  • API Key for the Perplexity service

Ideas for Using the Perplexity AI Search and Response Flow:

  • Research Automation: Use this flow to automate search queries on specific topics such as market trends, cryptocurrencies, or investment opportunities.

  • Content Generation: Quickly generate research-backed content by sending various prompts to the Perplexity API and capturing the AI-generated insights.

  • Decision Support: Implement this flow to assist with decision-making by retrieving data-driven responses to complex queries.


Flow Overview

Flow Start

The flow begins by injecting a test search prompt, which can be modified to suit specific search needs.

Send Prompt and Receive Response

The flow sends the search prompt to the Perplexity API. The API processes the prompt and returns a response, which is then logged and passed on for further formatting.

Format Response & Create Record

The response from the Perplexity API is structured into a record format that includes both the original prompt and the AI-generated response, then stored in the system.

Error Handling

Any errors encountered during the flow are captured and logged for troubleshooting, ensuring that issues can be quickly identified and resolved.

Flow End

The flow concludes once the records have been successfully created or any errors have been logged.


Perplexity AI Search and Response Flow Details

Inbound Send to Agent Events

  • Nodes: contextual-start

  • Purpose: The flow begins by receiving a start signal, typically initiated by an external event or agent.

In-Editor Testing

  • Nodes: Test Prompt, Prepare Prompt

  • Purpose: Allows for testing the flow directly within the editor. The search prompt is prepared and passed to the Perplexity API for processing.

Code Example: Prepare Prompt Function

// Prepare the payload for Perplexity API request
msg.payload = {
    // Specify the Perplexity model to use
    model: "llama-3.1-sonar-large-128k-online", // Parameter Count: 70B, Context Length: 127,072

    // Define the messages to send to Perplexity
    messages: [
        {
            role: "system",
            content: `You are Ken, a highly skilled quantitative financial analyst specializing in market research.`
        },
        {
            role: "user",
            content: msg.payload.prompt // The actual content of the user’s search prompt
        }
    ],
    return_citations: true,
    return_related_questions: true,
    return_images: true
};
return msg;

Explanation: This function constructs the payload for the Perplexity API, specifying the model and formatting the search prompt in the required structure. The payload is then passed to the next node in the flow, where it will be sent to the API.


Send Prompt and Receive Response

  • Nodes: Prompt Perplexity Chat, Perplexity Chat Response

  • Purpose: The prepared search prompt is sent to the Perplexity API. The response is logged and passed on for further formatting and processing.

Code Example: Perplexity Chat Response Log

// Log the response from the Perplexity API
msg.payload.response = {
    aiResponse: msg.payload.response.choices[0].message.content
};
return msg;

Explanation: This function logs the response received from the Perplexity API, capturing the AI-generated content for further processing and storage.


Format Response & Create Record

  • Nodes: Prepare Record Data, Create AI Response Record, Create AI Response Record Log

  • Purpose: The AI response is formatted into a structured record and stored in the system, including the original search prompt and the AI-generated response.

Code Example: Prepare Record Data Function

javascriptCopy code// Prepare data for Create Object node and assign to msg.payload
let body = {
    // The original prompt sent to Perplexity
    prompt: msg.payload.messages[1].content,

    // The AI-generated response from Perplexity
    aiResponse: msg.payload.response.choices[0].message.content
};

// The Create Object node will use the content of msg.payload to create a new record
msg.payload = body;
return msg;

Explanation: This function formats the API response into a structured object, which includes the original search prompt and the AI-generated response. This data is then ready to be stored as a record.


Error Handling

  • Nodes: catch, Error Catch Log, contextual-error

  • Purpose: Catches any errors that occur during the flow and logs them for review, ensuring that issues can be identified and resolved.


Flow End

  • Nodes: contextual-end

  • Purpose: The flow completes its process, either after successfully creating records or after logging any errors that occurred.


Summary of Flow:

  1. Flow Start: Initiate the flow with a test search prompt.

  2. Data Preparation: Prepare the search prompt for interaction with the Perplexity API.

  3. API Interaction: Send the search prompt to the Perplexity AI API and log the response.

  4. Record Creation: Format and store the AI-generated response as a record for analysis.

  5. Error Handling: Capture and log any errors that occur during the process.

  6. Flow End: Conclude the flow after records are created or errors are logged.

Last updated

Was this helpful?