Enhance Your Applications with Coding and Mathematical Reasoning Using OpenChat 3.5 Actions

23 Apr 2025
Enhance Your Applications with Coding and Mathematical Reasoning Using OpenChat 3.5 Actions

In the rapidly evolving landscape of AI, the kcaverly/openchat-3.5-1210-gguf API offers powerful tools for developers looking to integrate advanced cognitive capabilities into their applications. Among these tools are Cognitive Actions that leverage the quantized OpenChat 3.5 model, providing pre-built functionalities for tasks ranging from coding assistance to mathematical reasoning. These actions help streamline development processes, enhance user interaction, and significantly improve productivity.

Prerequisites

Before diving into the integration of these Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic familiarity with making HTTP requests and handling JSON data.

Authentication Concept: Generally, you will pass your API key in the request headers to authenticate your API calls, allowing you to access the Cognitive Actions seamlessly.

Cognitive Actions Overview

Perform Coding and Mathematical Reasoning

The Perform Coding and Mathematical Reasoning action utilizes the capabilities of the OpenChat 3.5 model, specifically designed for various tasks including coding, generalization, and mathematical reasoning. This action features two distinct modes tailored for coding and chat tasks or mathematical problem-solving, enhancing both productivity and accuracy.

Category: Text Processing

Input

The input required for this action is structured as follows:

  • prompt (required): A clear and concise directive or question for the model to address.
  • temperature (optional): Controls the creativity of the response, with a default value of 0.7.
  • repetitionPenalty (optional): Influences the likelihood of repeated content, defaulting to 1.1.
  • maxGeneratedTokens (optional): Sets the upper limit on newly generated tokens, defaulting to -1 (no limit).
  • instructionTemplate (optional): A template for the prompt structure, useful for multi-turn dialogues.

Example Input:

{
  "prompt": "Sally (a girl) has 3 brothers. Each brother has 2 sisters. How many sisters does Sally have?",
  "temperature": 0.7,
  "repetitionPenalty": 1.1,
  "maxGeneratedTokens": -1,
  "instructionTemplate": "GPT Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant: "
}

Output

Upon executing this action, you can expect a structured response that effectively answers the prompt. For instance:

Example Output:

Sally is a girl and she has 3 brothers. Since each brother has 2 sisters, that means there are 3 * 2 = 6 sisters in total. Therefore, Sally has 6 - 1 (herself) = 5 sisters.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to use the Perform Coding and Mathematical Reasoning 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 = "aa5a5acb-96f8-473b-8cc0-a1fd1bbeb7d5" # Action ID for Perform Coding and Mathematical Reasoning

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Sally (a girl) has 3 brothers. Each brother has 2 sisters. How many sisters does Sally have?",
    "temperature": 0.7,
    "repetitionPenalty": 1.1,
    "maxGeneratedTokens": -1,
    "instructionTemplate": "GPT Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant: "
}

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 snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id corresponds to the specific action you're invoking.
  • The payload is structured according to the input schema, ensuring that all required fields are included.

Conclusion

By integrating the Perform Coding and Mathematical Reasoning action from the OpenChat 3.5 API, developers can significantly enhance their applications' ability to handle coding queries and mathematical reasoning tasks. The flexibility offered by customizable parameters allows for tailored responses, making this action a powerful addition to any developer's toolkit. As you explore further, consider implementing additional actions to fully leverage the capabilities of the OpenChat model in your applications.