Unlocking Zero-Shot Function Calling with Nexus Raven V2 Cognitive Actions

21 Apr 2025
Unlocking Zero-Shot Function Calling with Nexus Raven V2 Cognitive Actions

In today's fast-paced development environment, integrating advanced AI functionalities into applications can significantly enhance user experiences. The kcaverly/nexus-raven-v2-13b-gguf API offers a powerful set of Cognitive Actions designed to leverage a quantized 13B parameter language model. One of the standout features is the ability to perform zero-shot function calling with high accuracy, streamlining complex tasks such as natural language understanding and execution. This blog post will guide you through the integration of the Invoke Zero-Shot Function Calling action, showcasing its capabilities, input requirements, and conceptual usage.

Prerequisites

Before diving into the integration process, ensure you have the following prerequisites:

  • An API key from the Cognitive Actions platform.
  • Basic knowledge of API calls and JSON payloads.
  • Familiarity with Python for testing the integration.

Authentication typically involves passing your API key in the headers of your requests, allowing secure access to the Cognitive Actions.

Cognitive Actions Overview

Invoke Zero-Shot Function Calling

The Invoke Zero-Shot Function Calling action harnesses the power of a high-performance language model to execute functions based on user queries without any prior training on the specific tasks. This capability allows for seamless integration of natural language processing (NLP) tasks into your applications.

Input

The action accepts the following input schema:

  • prompt (required): A string that defines the context and objective for the task. It should clearly outline the functions to be executed and the user query.
  • temperature (optional): A number that controls the creativity of the AI model. The default value is 0.001, which results in more deterministic outputs.
  • maxNewTokens (optional): An integer that specifies the maximum number of new tokens the model is allowed to generate. A value of -1 indicates no limit.

Example Input:

{
  "prompt": "Function:\ndef get_weather_data(coordinates):\n    \"\"\"\n    Fetches weather data from the Open-Meteo API for the given latitude and longitude.\n\n    Args:\n    coordinates (tuple): The latitude of the location.\n\n    Returns:\n    float: The current temperature in the coordinates you've asked for\n    \"\"\"\n\nFunction:\ndef get_coordinates_from_city(city_name):\n    \"\"\"\n    Fetches the latitude and longitude of a given city name using the Maps.co Geocoding API.\n\n    Args:\n    city_name (str): The name of the city.\n\n    Returns:\n    tuple: The latitude and longitude of the city.\n    \"\"\"\n\nUser Query: What is the weather like in Seattle right now?<human_end>",
  "temperature": 0.001,
  "maxNewTokens": -1
}

Output

The action typically returns a structured response detailing the function call made and a breakdown of the process. The output can vary based on the complexity of the user query but generally includes the function calls and their explanations.

Example Output:

[
  " ",
  "\n",
  " ",
  "\n",
  "Call",
  ":",
  " get",
  "_",
  "we",
  "ather",
  "_",
  "data",
  "(",
  "co",
  "ordinates",
  "=",
  "get",
  "_",
  "co",
  "ordinates",
  "_",
  "from",
  "_",
  "city",
  "(",
  "city",
  "_",
  "name",
  "='",
  "Se",
  "attle",
  "'))",
  "",
  " ",
  "\n",
  "Th",
  "ought",
  ":",
  " The",
  " function",
  " call",
  " `",
  "get",
  "_",
  "we",
  "ather",
  "_",
  "data",
  "(",
  "co",
  "ordinates",
  "=",
  "get",
  "_",
  "co",
  "ordinates",
  "_",
  "from",
  "_",
  "city",
  "(",
  "city",
  "_",
  "name",
  "='",
  "Se",
  "attle",
  "'))",
  "`",
  " answers",
  " the",
  " question",
  " \"",
  "What",
  " is",
  " the",
  " weather",
  " like",
  " in",
  " Seattle",
  " right",
  " now",
  "?\"",
  " by",
  " first",
  " fetch",
  "ing",
  " the",
  " latitude",
  " and",
  " longitude",
  " of",
  " Seattle",
  " using",
  " the",
  " Maps",
  ".",
  "co",
  " Ge",
  "oc",
  "oding",
  " API",
  ",",
  " and",
  " then",
  " using",
  " those",
  " coordinates",
  " to",
  " fetch",
  " the",
  " current",
  " temperature",
  " from",
  " the",
  " Open",
  "-",
  "M",
  "ete",
  "o",
  " API",
  "."
]

Conceptual Usage Example (Python)

Here’s how a developer might structure a call to the Invoke Zero-Shot Function Calling action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "ba78ba8c-dcd7-4c94-bb7c-7ba5685d035b"  # Action ID for Invoke Zero-Shot Function Calling

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Function:\ndef get_weather_data(coordinates):\n    \"\"\"\n    Fetches weather data from the Open-Meteo API for the given latitude and longitude.\n\n    Args:\n    coordinates (tuple): The latitude of the location.\n\n    Returns:\n    float: The current temperature in the coordinates you've asked for\n    \"\"\"\n\nFunction:\ndef get_coordinates_from_city(city_name):\n    \"\"\"\n    Fetches the latitude and longitude of a given city name using the Maps.co Geocoding API.\n\n    Args:\n    city_name (str): The name of the city.\n\n    Returns:\n    tuple: The latitude and longitude of the city.\n    \"\"\"\n\nUser Query: What is the weather like in Seattle right now?<human_end>",
    "temperature": 0.001,
    "maxNewTokens": -1
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID is set to target the Invoke Zero-Shot Function Calling action, and the input payload is structured according to the example provided.

Conclusion

The Invoke Zero-Shot Function Calling action from the kcaverly/nexus-raven-v2-13b-gguf API opens up exciting possibilities for developers looking to enhance their applications with advanced NLP capabilities. By leveraging the power of a quantized language model, you can efficiently execute complex functions based on user queries with minimal setup.

Consider exploring other use cases, such as automated customer support or dynamic content generation, to fully utilize the potential of this action in your projects. Happy coding!