Enhance Your Applications with Yuan2.0 Text Generation Cognitive Actions

24 Apr 2025
Enhance Your Applications with Yuan2.0 Text Generation Cognitive Actions

In the rapidly evolving world of artificial intelligence, leveraging advanced language models can significantly enhance user experience and application capabilities. The Yuan2.0 Cognitive Actions, developed by IEIT System, offer developers the ability to generate human-like text responses, enabling sophisticated interaction with users through natural language. With capabilities like improved semantic understanding, mathematical reasoning, and coding abilities, these actions are a powerful addition to any application.

Prerequisites

Before you start integrating the Cognitive Actions from Yuan2.0, ensure that you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of how to make API calls and handle JSON data.

To authenticate, you will typically include your API key in the request headers. This allows the service to verify your access to the Cognitive Actions.

Cognitive Actions Overview

Generate Text with Yuan2.0

The Generate Text with Yuan2.0 action utilizes a next-generation Large Language Model to produce coherent and contextually relevant text. This action enables applications to respond intelligently to user queries, provide detailed explanations, or even assist with coding tasks.

Input

The input for this action requires the following fields:

  • prompt (required): The text that guides the model's output. For example, you might ask, "请介绍红烧肉的做法。" (Please introduce the method of making braised pork).
  • topK (optional): Specifies the number of highest probability tokens to consider. Default is 50.
  • topP (optional): Sets a probability threshold for output generation. Default is 1.0.
  • temperature (optional): Adjusts the randomness of predictions. Default is 1.
  • maxNewTokens (optional): Defines the maximum number of tokens to generate. Default is 4096.

Example Input:

{
  "topK": 50,
  "topP": 1,
  "prompt": "请介绍红烧肉的做法。",
  "temperature": 1,
  "maxNewTokens": 4096
}

Output

The action typically returns a text response based on the input prompt. The output is a coherent text that reflects the context and subject matter of the prompt.

Example Output:

红烧肉是一道传统的家常菜,在中国各地都有着广泛的流行。以下是红烧肉的做法:...

This output includes a detailed recipe for braised pork, presenting ingredients and cooking steps.

Conceptual Usage Example (Python)

Here’s how a developer might call the Generate Text with Yuan2.0 action using a hypothetical endpoint:

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 = "25dfbb1e-3d51-4021-9def-808896464c82"  # Action ID for Generate Text with Yuan2.0

# Construct the input payload based on the action's requirements
payload = {
    "topK": 50,
    "topP": 1,
    "prompt": "请介绍红烧肉的做法。",
    "temperature": 1,
    "maxNewTokens": 4096
}

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 Python code snippet, replace the COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your specific credentials. The action_id corresponds to the Generate Text with Yuan2.0 action. The payload is structured to include the necessary inputs as per the action's requirements.

Conclusion

Integrating the Yuan2.0 Cognitive Actions can greatly enhance your application's ability to generate meaningful text responses, making interactions more natural and engaging. Whether you're building chatbots, virtual assistants, or any application that benefits from natural language understanding, these actions provide a robust solution.

Consider exploring other use cases for these actions, such as content generation, user support, and educational tools. By leveraging the power of Yuan2.0, you can take your applications to the next level!