ACTIONS
  • Home
  • My Actions
  • My Projects
  • My Packages
Claude AI -> Ask a Question
Function Documentation: Claude AI -> Ask a Question

Action summary

Claude AI -> Ask a Question

Unico Connect

Function Documentation: Claude AI -> Ask a Question

Claude AI API documentation

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

  1. claude_api_key (registry/text) Required

    • Description: The API key used to authenticate requests to the Claude AI API.
    • Example: claude_api_abc123
  2. 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?
  3. max_token (integer) Required

    • Description: The maximum number of tokens to be used for generating the response, Default - 1024.
    • Example: 1024
  4. 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

  1. 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"
        }
      ]
    }
    
  2. Create Variable: response

    • Variable: var: response = var: api_response.response
    • Purpose: Stores the API response, including the message generated by Claude AI.

2 Error Handling (Catch)

  1. 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
Current
2024-10-11T16:53:09.000+00:00

Function Documentation: Claude AI -> Ask a Question

Claude AI API documentation

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

  1. claude_api_key (registry/text) Required

    • Description: The API key used to authenticate requests to the Claude AI API.
    • Example: claude_api_abc123
  2. 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?
  3. max_token (integer) Required

    • Description: The maximum number of tokens to be used for generating the response, Default - 1024.
    • Example: 1024
  4. 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

  1. 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"
        }
      ]
    }
    
  2. Create Variable: response

    • Variable: var: response = var: api_response.response
    • Purpose: Stores the API response, including the message generated by Claude AI.

2 Error Handling (Catch)

  1. 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
    }
}