Page cover image

Mistral AI Prompt and Response

The Mistral Chat Prompt Flow is designed to automatically send a text prompt to the Mistral AI model, receive a response, and store the result for further analysis. This flow is ideal for automating simple chat interactions and capturing AI-generated responses within your system.

This flow is particularly useful in applications such as customer support automation, content generation, and chatbot development.

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

  • AI, Contextual Basics

Watch It In Use

Mistral AI Prompt & Response Template In Use

What's Included

  • 1 Flow

  • 1 Object Type

  • 1 Connection

What You'll Need

  • Access to the Mistral API

  • API Key for the Mistral service

Ideas for Using the Mistral Chat Prompt Flow

Customer Support Automation

Use this flow to automate responses to common customer queries by sending prompts to Mistral AI and storing the responses for review and analysis.

Content Generation

Quickly generate content ideas or short responses by sending various prompts to the Mistral API and capturing the AI-generated outputs.

Chatbot Development

Integrate this flow into a chatbot framework to handle user interactions, storing conversational data for future analysis and model training.

Flow Overview

Flow Start

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

Send Prompt and Receive Response

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

Format Response & Create Record

The response from the Mistral API is formatted into a structured record and stored in the system, including details about the prompt and the AI's response.

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.

Mistral Chat Prompt 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 prompt is prepared and passed to the Mistral API for processing.

Code Example: Prepare Prompt Function

// Prepare the payload for Mistral API request
msg.payload = {
    // Specify the Mistral model to use
    model: "mistral-large-latest",

    // Define the messages to send to Mistral
    messages: [
        {
            // Set the role of the message sender
            role: "user",
            // The actual content of the message
            content: msg.payload.prompt
        }
    ]
};

return msg;

Explanation: This function constructs the payload for the Mistral API, specifying the model to be used and formatting the 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 Mistral Chat, Mistral Chat Response Purpose: The prepared prompt is sent to the Mistral API. The response is logged and passed on for further processing.

Code Example: Mistral Chat Response Log

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

return msg;

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

Format Responses & Create Records

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 prompt and the AI-generated response.

Code Example: Prepare Record Data Function

// Prepare data for Create Object node and assign to msg.payload
let body = {
    // The original prompt sent to Mistral
    prompt: msg.event.prompt,
    
    // The AI-generated response from Mistral
    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 that can be easily stored as a record. It includes the original prompt and the AI-generated response, making the data readily accessible for further use or analysis.

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

  • Flow Start: Initiate the flow with a test prompt.

  • Data Preparation: Prepare the prompt for Mistral AI API interaction.

  • API Interaction: Send the prompt to the Mistral AI API and log the response.

  • Record Creation: Format and store the AI response as a record for analysis.

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

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

Last updated

Was this helpful?