Unlocking Functionality with NexusRaven Cognitive Actions: A Developer's Guide

In the realm of API management, the NexusRaven Cognitive Actions present a powerful toolset designed to enhance the capabilities of applications through intelligent function invocation. The Invoke Function with NexusRaven action enables developers to leverage advanced function call generation, providing enhanced success rates for complex queries while delivering fully explainable outputs. This guide will walk you through the capabilities of this action, how to integrate it into your applications, and the benefits it offers.
Prerequisites
Before diving into the integration of NexusRaven Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform to authenticate your requests.
- Familiarity with JSON structure, as the input and output will be in this format.
- Basic knowledge of Python for implementing the conceptual usage examples provided.
To authenticate your requests, you'll typically include your API key in the headers of your HTTP requests.
Cognitive Actions Overview
Invoke Function with NexusRaven
The Invoke Function with NexusRaven action allows you to generate and explain function calls with superior success rates, especially for nested and composite functions. This action is categorized under API Management and is designed for developers looking to automate and enhance function invocation in their applications.
Input
The input for this action requires two main fields:
- functions: A string representing the definitions of one or more functions available for processing user queries. This includes details about the function arguments and return types.
- userQuery: A string that holds the specific query entered by the user to request information or actions.
Example Input:
{
"functions": "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 \"\"\"",
"userQuery": "What is the weather like in Seattle right now?"
}
Output
The output of this action will typically return a generated text that includes the function definitions along with an explanation of how those functions relate to the user query. This includes the results of the function call and can clarify the steps taken to arrive at the conclusion.
Example Output:
[
{
"generated_text": "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\n User Query: What is the weather like in Seattle right now?<human_end>\n \nCall: get_weather_data(coordinates=get_coordinates_from_city(city_name='Seattle'))"
}
]
Conceptual Usage Example (Python)
Here’s a conceptual Python code snippet demonstrating how you might invoke the Invoke Function with NexusRaven action:
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 = "bff8b64d-dbe6-4f91-aba6-87f1d84ce863" # Action ID for Invoke Function with NexusRaven
# Construct the input payload based on the action's requirements
payload = {
"functions": "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 \"\"\"",
"userQuery": "What is the weather like in Seattle right now?"
}
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 the COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your actual API key and endpoint. Note how the input payload is structured to match the action's requirements.
Conclusion
The Invoke Function with NexusRaven action offers a robust solution for developers looking to enhance their applications with advanced function calling capabilities. By simplifying the process of generating and explaining function calls, it allows for improved interaction with users and more reliable outputs. As you integrate this action into your projects, consider exploring its potential for creating sophisticated applications that respond intelligently to user queries. Happy coding!