xAI -> Create a Chat Completion
Action summary
xAI -> Create a Chat Completion
Function Documentation: xAI -> Create a Chat Completion
Overview
This function generates a completion using the xAI API based on a user-provided request. It requires parameters such as the model & prompt text. The function validates environment variables and conditions before making an API request and processing the response.
Inputs
- xai_api_key (registry|text) Required Sensitive data
- Description: The API key for your xAI account.
- model (enum) Required
- Description: Specifies the model to be used for generating the completion.
- Options:
- Available models will be specified by xAI
- message (text) Required
- Description: The input prompt that will be sent to the xAI API for generating the completion.
- system (text) Required
- Description: Initial instructions that shape the AI's behavior, role, and response style. Sets the context and guidelines for how the AI should interact throughout the conversation on task.
Function Stack
1. xAI API Request
- API Request to
https://api.x.ai/v1/completions
- Purpose: Sends a request to the xAI API using the specified model and prompt.
- Precondition:
xai_api_response.status == 200
- Purpose: Confirms that the API request was successful (HTTP status code 200).
2. xAI API Response
- Create Variable:
response
- Purpose: Stores the response from the xAI API.
Response
- The function returns the generated completion in a structured format
Success Response
Response provided as a string.
Error Response
{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error"
}
}
Example
Input
{
"model": "grok-beta",
"prompt": "What is Obama's height?"
}
Response
"Barack Obama is 6 feet 1 inch tall (185 cm)."
Version notes
2024-11-05 16:05:11
Current