Action summary
Claude AI -> Ask a Question
Function Documentation: Claude AI -> Ask a Question
Overview
This function sends a message request to the Claude AI API using the provided API key, prompt, and token limit. The function captures the response from the Claude API and returns it.
Inputs
claude_api_key (registry/text) Required
- Description: The API key used to authenticate requests to the Claude AI API.
- Example:
claude_api_abc123
prompt (text) Required
- Description: The prompt or message that you want to send to Claude AI as role user.
- Example:
What is the capital of France?
max_token (integer) Required
- Description: The maximum number of tokens to be used for generating the response, Default - 1024.
- Example:
1024
assistant_prompt (text) Optional
- Description: The prompt or message that you want to send to Claude AI as role assistant. Default - As an enthusiastic assistant, provide clear and understandable responses.
- Example: `As an enthusiastic assistant, provide clear and understandable responses
Function Stack
1. Try / Catch Block
Group: Claude API Request
API Request to
https://api.anthropic.com/v1/messages
- Purpose: Sends the prompt to the Claude AI API with the API key, prompt, assistant prompt, and token limit.
- Return Value: The API response is stored as
api_response
. - Example:
{ "model": "claude", "message": [ { "role": "user", "content": "prompt" }, { "role": "assistant", "content": "assistant_prompt" } ] }
Create Variable:
response
- Variable:
var: response = var: api_response.response
- Purpose: Stores the API response, including the message generated by Claude AI.
- Variable:
2 Error Handling (Catch)
- Create Variable:
response
- Purpose: If the API call fails or returns an error, this block catches the error and provides an error message.
Response
The function returns the result of the Claude AI message generation, including the generated text.
Success Response
{
"id": "msg_01H4x****",
"type": "message",
"role": "{role}",
"content": [
{
"type": "text",
"text": "Neural networks are a type of machine learning algorithm ..."
}
],
"model": "claude-3-opus-20240229",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 23,
"output_tokens": 219
}
}
Error Response
{
"type": "error",
"error": {
"error": "authentication_error",
"message": "invalid x api key."
}
}
Example
Input
{
"prompt": "{prompt}",
"max_tokens": "{max_token}",
"assistant_prompt": "{assistant_prompt}"
}
Output
{
"id": "msg_01H4x****",
"type": "message",
"role": "{role}",
"content": [
{
"type": "text",
"text": "Neural networks are a type of machine learning algorithm ..."
}
],
"model": "claude-3-opus-20240229",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 23,
"output_tokens": 219
}
}
Version notes
2024-10-11 22:23:04
Function Documentation: Claude AI -> Ask a Question
Overview
This function sends a message request to the Claude AI API using the provided API key, prompt, and token limit. The function captures the response from the Claude API and returns it.
Inputs
claude_api_key (registry/text) Required
- Description: The API key used to authenticate requests to the Claude AI API.
- Example:
claude_api_abc123
prompt (text) Required
- Description: The prompt or message that you want to send to Claude AI as role user.
- Example:
What is the capital of France?
max_token (integer) Required
- Description: The maximum number of tokens to be used for generating the response, Default - 1024.
- Example:
1024
assistant_prompt (text) Optional
- Description: The prompt or message that you want to send to Claude AI as role assistant. Default - As an enthusiastic assistant, provide clear and understandable responses.
- Example: `As an enthusiastic assistant, provide clear and understandable responses
Function Stack
1. Try / Catch Block
Group: Claude API Request
API Request to
https://api.anthropic.com/v1/messages
- Purpose: Sends the prompt to the Claude AI API with the API key, prompt, assistant prompt, and token limit.
- Return Value: The API response is stored as
api_response
. - Example:
{ "model": "claude", "message": [ { "role": "user", "content": "prompt" }, { "role": "assistant", "content": "assistant_prompt" } ] }
Create Variable:
response
- Variable:
var: response = var: api_response.response
- Purpose: Stores the API response, including the message generated by Claude AI.
- Variable:
2 Error Handling (Catch)
- Create Variable:
response
- Purpose: If the API call fails or returns an error, this block catches the error and provides an error message.
Response
The function returns the result of the Claude AI message generation, including the generated text.
Success Response
{
"id": "msg_01H4x****",
"type": "message",
"role": "{role}",
"content": [
{
"type": "text",
"text": "Neural networks are a type of machine learning algorithm ..."
}
],
"model": "claude-3-opus-20240229",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 23,
"output_tokens": 219
}
}
Error Response
{
"type": "error",
"error": {
"error": "authentication_error",
"message": "invalid x api key."
}
}
Example
Input
{
"prompt": "{prompt}",
"max_tokens": "{max_token}",
"assistant_prompt": "{assistant_prompt}"
}
Output
{
"id": "msg_01H4x****",
"type": "message",
"role": "{role}",
"content": [
{
"type": "text",
"text": "Neural networks are a type of machine learning algorithm ..."
}
],
"model": "claude-3-opus-20240229",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 23,
"output_tokens": 219
}
}