Enhance Your Applications with NexusRaven-13B Function Calling Actions

Integrating advanced function calling capabilities into your applications has never been easier. The NexusRaven-13B Cognitive Actions provide developers with a powerful way to execute function calls with state-of-the-art accuracy and efficiency. These pre-built actions outperform many open-source models, making them a go-to solution for function calling tasks. In this article, we'll explore how to leverage the capabilities of NexusRaven-13B and integrate its function calling action into your applications.
Prerequisites
Before diving into the integration, you need to ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic knowledge of making API requests and handling JSON data.
Authentication typically involves passing your API key in the request headers, ensuring your application can securely communicate with the Cognitive Actions service.
Cognitive Actions Overview
Execute Function Call with NexusRaven-13B
The Execute Function Call with NexusRaven-13B action allows you to utilize the NexusRaven-13B model to execute function calls, providing high accuracy and efficiency in response generation.
- Category: Function Calling
Input
The action requires a structured input defined by the following schema:
- prompt (required): The input string for the model, which includes the options for function calls and the user query.
- topK (optional): An integer that specifies the number of top tokens to consider in output generation (default is 50).
- topP (optional): A number that acts as a threshold for token probability in output generation (default is 0.95).
- temperature (optional): A floating-point number that adjusts the randomness of the token selection (default is 0.8).
- maxNewTokens (optional): The maximum number of tokens to generate in the response (default is 128).
- presencePenalty (optional): A parameter to penalize new tokens based on their presence in the generated text (default is 1).
Here’s an example of the expected input JSON structure:
{
"topK": 50,
"topP": 0.95,
"prompt": "<human>:\nOPTION:\n<func_start>def hello_world(n : int)<func_end>\n<docstring_start>\n\"\"\"\nPrints hello world to the user.\n\nArgs:\nn (int) : Number of times to print hello world.\n\"\"\"\n<docstring_end>\n\nOPTION:\n<func_start>def hello_universe(n : int)<func_end>\n<docstring_start>\n\"\"\"\nPrints hello universe to the user.\n\nArgs:\nn (int) : Number of times to print hello universe.\n\"\"\"\n<docstring_end>\n\nUser Query: Question: Please print hello world 10 times.\n\nPlease pick a function from the above options that best answers the user query and fill in the appropriate arguments.<human_end>",
"temperature": 0.8,
"maxNewTokens": 256,
"presencePenalty": 1
}
Output
The action typically returns a structured response that includes:
- The thought process of the model.
- The initial answer based on the function call.
- A fixed call and the corresponding function name and arguments.
Here’s a sample output you might receive:
.
Thought: The purpose of the def hello_world(n : int) is to print hello world n times to the user.
Initial Answer: hello_world(10)
Reflection: The hello_world function takes in an integer argument. The user has asked to print hello world 10 times.
The call provided is hello_world(10).
The call does not need to be improved.
This call can be run:
Fixed Call: hello_world(10)
Fixed Function Name: hello_world
Fixed Function Args: {"n" : 10}
Done.
Conceptual Usage Example (Python)
Here’s how you might call the Execute Function Call with NexusRaven-13B action in your application 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 = "84b3bf1d-0deb-452d-8ce0-c948c2e261f0" # Action ID for Execute Function Call with NexusRaven-13B
# Construct the input payload based on the action's requirements
payload = {
"topK": 50,
"topP": 0.95,
"prompt": "<human>:\nOPTION:\n<func_start>def hello_world(n : int)<func_end>\n<docstring_start>\n\"\"\"\nPrints hello world to the user.\n\nArgs:\nn (int) : Number of times to print hello world.\n\"\"\"\n<docstring_end>\n\nOPTION:\n<func_start>def hello_universe(n : int)<func_end>\n<docstring_start>\n\"\"\"\nPrints hello universe to the user.\n\nArgs:\nn (int) : Number of times to print hello universe.\n\"\"\"\n<docstring_end>\n\nUser Query: Question: Please print hello world 10 times.\n\nPlease pick a function from the above options that best answers the user query and fill in the appropriate arguments.<human_end>",
"temperature": 0.8,
"maxNewTokens": 256,
"presencePenalty": 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 the above Python snippet, you will replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload follows the structure laid out in the input schema, and the action ID corresponds to the function call action you're invoking.
Conclusion
The NexusRaven-13B Cognitive Actions offer a robust solution for executing function calls in your applications with impressive accuracy. By integrating these actions, developers can enhance their functionality and improve user experiences. Consider exploring more use cases or optimizing your existing applications by leveraging the power of function calling with NexusRaven-13B. Happy coding!