LogoLogo
Visit Contextual.ioSign Up
  • Getting Started
    • Welcome
    • Tour: Hello, AI World!
  • TRAINING
    • Basic Developer Training Course
      • Lesson 1: HTTP Agent Introduction
      • Lesson 2: Logging and Error Handling Basics
      • Lesson 3: Event Processing Agent Introduction
  • Services Catalog
    • What's in the Catalog?
      • Intro Patterns
      • Object Type Bundles
    • Browse by Platform
    • All Intro Patterns
      • Anthropic Claude Image Analysis
      • Mistral AI Prompt and Response
      • xAI Grok Prompt and Response
      • DeepSeek Chat Prompt and Response
      • Qwen Chat Prompt and Response
      • Perplexity AI Search and Response
      • Firecrawl Website Scraper
      • Groq Prompt and Response
      • Nyckel Dog Breed Classification
      • RapidAPI ClassifyAI Text Classification
      • RapidAPI YouTube AI Video Summary
      • UnifyAI Model Comparison
      • WebPilot URL Analysis and Summarization
      • OpenAI Assistants Prompt and Response
      • OpenAI Sync
    • All Prebuilt Solutions
      • Invoice AI
      • Lead Generation Form
    • All Object Type Bundles
      • Work Order Management System ITIL Object Type Bundle
        • Work Order
        • User
        • Role
        • Permission
        • Asset
        • Task
        • Action
        • Attachment
        • Comment
        • Notification
        • Audit Log
        • Service Level Agreement
        • Custom Fields
        • Work Order Template
        • Work Order Transition
        • Escalation Policy
        • Tag
  • Components & Data
    • Object Types
      • Data in Contextual
        • Secrets
        • Validation
        • Versioning
      • Examples
      • Creating an Object Type
      • Object Type Details
        • Definition
        • Data Schema
          • Automatic Record Metadata
          • Generated Values
            • Dates and Times
            • UUIDs
          • Frequently Used Validation
          • Disallowing Null Property Values
          • Disallowing Undefined Properties
          • Secrets
          • AI Assistant
          • ID and PrimaryKey Permanence
        • UI Schemas
        • Features
        • Triggers
        • Actions
        • Audit Trail
        • Versions
        • Templates
        • Records
      • Using Object Types in Flows
      • Records
        • Records and Your Tenant API
        • Record Import
    • Flows
      • Nodes
      • Wires
      • Message Object
      • Flow Editor
        • Basics
        • Saving Changes
        • In-Flow Testing with Debugger
        • Restart Agents to Make Changes Active
        • Config
      • Node Reference
        • Common
          • Log Tap
          • Inject
          • Debug
          • Complete
          • Catch
          • Status
          • Link In
          • Link Call
          • Link Out
          • Comment
        • Event
          • Prepare Event
          • Event Start
          • Event End
          • Event Error
        • Object
          • Search Object
          • Get Object
          • Create Object
          • Patch Object
          • Put Object
          • Delete Object
          • Run Action
        • Request
          • Send to Agent
          • HTTP GET
          • HTTP PATCH
          • HTTP PUT
          • HTTP DELETE
          • HTTP POST
          • GQL
          • Produce Message
        • Function
          • Function
          • Switch
          • Change
          • Range
          • Template
          • Delay
          • Trigger
          • Exec
          • Filter
          • Loop
        • Models
          • ML Predict
        • Network
          • MQTT In
          • MQTT Out
          • HTTP In
          • HTTP Response
          • HTTP Request
          • WebSocket In
          • WebSocket Out
          • TCP In
          • TCP Out
          • TCP Request
          • UDP In
          • UDP Out
        • Sequence
          • Split
          • Join
          • Sort
          • Batch
        • Parser
          • csv
          • html
          • json
          • xml
          • yaml
    • Agents
      • Creating an Agent
      • Types of Agents
        • Event to Flow
        • HTTP to Flow
          • Custom Domains
      • How Agents Work
        • Flow Execution
        • HTTP Load Balancing
        • Event Routing
      • Scale and Performance
        • Flow execution
        • Parallel Instances
        • Event Lag Scaling
        • Compute Threshold Scaling
        • Instance Compute Sizing
      • Agent Details
        • Definition
        • Operations
        • Logs
          • Session Log
          • Message Log
        • Audit Trail
        • Versions
      • Using Agents in Flows
    • Connections
      • Creating a Connection
      • Types of Connections
        • Basic
        • Bearer
        • Client Grant
        • Kafka
        • Password Grant
        • Public
        • Pulsar
      • Using Connections in Flows
    • JWKS Profiles
      • Using JWKS Profiles in Your Solution
  • PATTERNS
    • Solution Architecture
      • Events, Messages, Queues
    • Working with Data
      • Search Object Node & Pagination
      • Message Payload Content - Triggers and Actions
    • Industry Cookbooks
      • Field Services
  • Tenants
    • Tenant Workspace
    • Tenant Logs
      • Contextual Log Query Language (CLQL)
        • String Searches
        • Keyword Searches
        • Advanced Operators
    • Tenant API
      • API Keys
        • API Key Settings
        • API Key Permissions
      • Documentation
  • Release Notes
    • 2024
      • 2024.12.09
Powered by GitBook
On this page

Was this helpful?

  1. Services Catalog
  2. All Intro Patterns

xAI Grok Prompt and Response

PreviousMistral AI Prompt and ResponseNextDeepSeek Chat Prompt and Response

Last updated 6 months ago

Was this helpful?

The xAI Grok Chat Prompt Example flow demonstrates how to interact with the xAI Grok API to send chat prompts and receive AI-generated responses. The flow facilitates the entire process, from sending a prompt to the xAI Grok API, receiving the response, formatting it, and creating a record for further use. It provides robust testing and error-handling capabilities, making it a comprehensive tool for integrating AI-driven chat functionalities into various applications.

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

  • AI, Contextual Basics

Watch It In Use

What's Included:

  • 1 Flow

  • 1 Object Type

  • 1 Connection

What You'll Need:

  • Access to the xAI Grok API

  • API Key for the xAI Grok service

Ideas for Using the xAI Grok Chat Prompt Flow:

  • Conversational AI: Use the flow to automate AI-driven chat responses for customer service, virtual assistants, or other conversational agents.

  • Decision Support: Leverage the flow to process complex user queries and retrieve insights from the xAI Grok API, enabling faster and more informed decision-making.

  • Content Generation: Automate the creation of content by sending tailored prompts to the xAI Grok API, with responses stored for easy retrieval and further use.


Flow Overview:

Flow Start

The flow begins with an optional testing phase where a test prompt is injected directly within the editor. This is designed for easy testing and modification.

Send Prompt and Receive Response

The flow sends the user-defined prompt to the xAI Grok API. The response from the API is logged for review and passed on for further processing and formatting.

Format Response & Create Record

The received response is formatted into a structured record, including the original prompt and AI-generated content. This data is stored in the system for further analysis.

Error Handling

The flow includes error-catching capabilities, where any issues that occur during processing are captured, logged, and stored, ensuring efficient debugging and troubleshooting.

Flow End

The flow concludes by either successfully creating records or logging any errors that occurred during the process.


xAI Grok Chat Prompt Flow Details:

Inbound Send to Agent Events

  • Nodes: contextual-start

  • Purpose: Initiates the flow, triggered by an external agent or another flow.

In-Editor Testing

  • Nodes: Test Prompt, Prepare Prompt

  • Purpose: Allows for testing the flow directly in the editor. The user prompt is passed to the xAI Grok API for processing.

Code Example: Prepare Prompt Function

// Prepare the payload for xAI Grok API request
msg.payload = {
    model: "grok-beta",
    messages: [
        { role: "user", content: msg.payload.prompt }
    ],
    stream: false,
    temperature: 0
};
return msg;

Explanation: This function constructs the payload for the xAI Grok API, specifying the model and structuring the user’s prompt for processing.

Send Prompt and Receive Response

  • Nodes: Prompt xAI Grok Chat, xAI Grok Chat Response

  • Purpose: Sends the prompt to the xAI Grok API. The response is logged and passed on for further formatting.

Code Example: xAI Grok Chat Response Log

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

Explanation: This function logs the AI-generated response from the xAI Grok API for further processing and storage.

Format Response & Create Record

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

  • Purpose: Formats the AI response into a structured record and stores it, including the original prompt and AI response.

Code Example: Prepare Record Data Function

// Prepare data for the Create Object node
let body = {
    prompt: msg.payload.messages[0].content,
    aiResponse: msg.payload.response.choices[0].message.content
};
msg.payload = body;
return msg;

Explanation: This function formats the data received from the API, readying it for storage as a record in the system.

Error Handling

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

  • Purpose: Catches any errors encountered during the flow and logs them for troubleshooting.

Flow End

  • Nodes: contextual-end

  • Purpose: The flow finishes once the records have been created or any errors have been logged.


Summary of Flow:

  • Flow Start: Test with a sample prompt or trigger the flow externally.

  • Data Preparation: Format the user’s prompt for sending to the xAI Grok API.

  • API Interaction: Submit the prompt and receive the AI-generated response.

  • Record Creation: Format the response and store it for further use.

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

  • Flow End: Complete the process after records are created or errors are logged.

Page cover image
xAI Grok Prompt & Response Template In Use