Enhance Your Application with Multi-Turn Dialogue Using Qwen-14B-Chat Actions

24 Apr 2025
Enhance Your Application with Multi-Turn Dialogue Using Qwen-14B-Chat Actions

In the rapidly evolving landscape of AI and natural language processing, the ability to engage users through conversational interfaces has become paramount. The nomagick/qwen-14b-chat API provides powerful Cognitive Actions designed to enhance dialogue capabilities within your applications. Specifically, the Execute Multi-Turn Dialogue with Qwen-14B-Chat action allows developers to harness the power of a state-of-the-art Transformer-based language model with 14 billion parameters, pretrained on diverse data sources. This action is ideal for creating chatbots that can engage in meaningful and contextually aware conversations.

Prerequisites

Before you can start integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and HTTP requests.

Authentication typically involves passing your API key in the headers of your requests, which is critical for secure access to the action functionalities.

Cognitive Actions Overview

Execute Multi-Turn Dialogue with Qwen-14B-Chat

This action enables you to engage in multi-turn conversations, leveraging the advanced capabilities of the Qwen-14B-Chat model. It is particularly useful for building chatbots that require understanding and maintaining context over multiple exchanges.

Input

The input for this action follows the CompositeRequest schema:

  • prompt: (string, required) The context and instructions for the model in ChatML format.
  • maxTokens: (integer, optional) The maximum number of tokens to generate. Default is 2048, with a range of 1 to 8192.
  • temperature: (number, optional) Controls randomness in responses. Default is 0.75, ranging from 0 to 5.
  • topProbability: (number, optional) The cumulative probability for token selection. Default is 0.8, ranging from 0 to 1.

Example Input:

{
  "prompt": "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>user\n请使用英文重复这段话:\"为了使模型生成最优输出,当使用 Qwen 时需要使用特定的输入格式(chatml),请按照ChatML格式组织输入。\" 之后介绍一下Chat ML格式<|im_end|>\n<|im_start|>assistant\n",
  "maxTokens": 2048,
  "temperature": 0.75,
  "topProbability": 0.8
}

Output

The output consists of a list of strings, which represent the generated response from the model based on the provided prompt. The response typically includes the model's interpretation of the prompt, maintaining the context throughout the dialogue.

Example Output:

[
  "\"To",
  " generate",
  " the",
  " optimal",
  " output",
  " from",
  " the",
  " model",
  ",",
  " when",
  " using",
  " Q",
  "wen",
  ",",
  " it",
  " is",
  " necessary",
  " to",
  " use",
  " a",
  " specific",
  " input",
  " format",
  " called",
  " Chat",
  "ML",
  ".",
  " Please",
  " organize",
  " the",
  " input",
  " according",
  " to",
  " the",
  " Chat",
  "ML",
  " format",
  ".\""
  // Additional output follows...
]

Conceptual Usage Example (Python)

Here’s how you might structure a request to invoke this 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 = "f8850b9e-91c8-4364-ac3e-9f2793fa398a" # Action ID for Execute Multi-Turn Dialogue with Qwen-14B-Chat

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>user\n请使用英文重复这段话:\"为了使模型生成最优输出,当使用 Qwen 时需要使用特定的输入格式(chatml),请按照ChatML格式组织输入。\" 之后介绍一下Chat ML格式<|im_end|>\n<|im_start|>assistant\n",
    "maxTokens": 2048,
    "temperature": 0.75,
    "topProbability": 0.8
}

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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Execute Multi-Turn Dialogue with Qwen-14B-Chat action, and the payload is constructed according to the schema outlined above.

Conclusion

The Execute Multi-Turn Dialogue with Qwen-14B-Chat action provides a robust solution for developers looking to create engaging conversational experiences. By leveraging this powerful API, you can implement chatbots that understand context and maintain coherent dialogues, ultimately enhancing user interaction. Consider exploring further capabilities of the Qwen model to create more sophisticated applications or integrate additional actions to expand your chatbot’s functionality!