Unlock Advanced Language Capabilities with Yuan 2.0-2B Mars Cognitive Actions

25 Apr 2025
Unlock Advanced Language Capabilities with Yuan 2.0-2B Mars Cognitive Actions

Integrating advanced language models into applications can significantly enhance user experiences. The Yuan 2.0-2B Mars model, the latest iteration from Inspur, is designed to improve semantic understanding, mathematical reasoning, coding capabilities, and overall knowledge comprehension. This blog post explores how developers can leverage the capabilities of this powerful model through a specific Cognitive Action, providing an easy-to-follow guide for implementation.

Prerequisites

To start using the Yuan 2.0-2B Mars Cognitive Actions, you'll need an API key for the Cognitive Actions platform. This key will authenticate your requests to the service. Generally, this is done by including the API key in the headers of your HTTP requests.

Cognitive Actions Overview

Utilize Yuan 2.0-2B Mars Model

The Utilize Yuan 2.0-2B Mars Model action allows you to deploy the Yuan 2.0-2B Mars model for various natural language processing tasks. It is designed to generate coherent and contextually relevant text based on the input prompt, benefiting from extensive pre-training and fine-tuning.

Input

The input for this action requires a JSON object with the following fields:

  • prompt (required): The input text that the model will respond to.
  • topK (optional): Specifies the number of highest probability tokens to consider during output generation. Default is 50.
  • topP (optional): Defines a probability threshold for output generation. Default is 1.
  • temperature (optional): Controls the randomness of token generation. Default is 1.
  • maxNewTokens (optional): The maximum number of tokens that the model can generate in response. Default is 4096.

Example Input:

{
  "topK": 50,
  "topP": 1,
  "prompt": "请问目前最先进的机器学习算法有哪些?",
  "temperature": 1,
  "maxNewTokens": 4096
}

Output

The output of this action will typically return a generated text response relevant to the provided prompt. For example, if the input is asking about advanced machine learning algorithms, the model might respond with a list of popular algorithms.

Example Output:

目前最先进的机器学习算法包括:卷积神经网络(Convolutional Neural Network,CNN)、循环神经网络(Recurrent Neural Network,RNN)、长短时记忆网络(Long Short-Term Memory,LSTM)、生成对抗网络(Generative Adversarial Networks,GAN)和强化学习(Reinforcement Learning,RL)等。这些算法在不同的任务和应用场景中都取得了优异的表现,被广泛应用于计算机视觉、自然语言处理、语音识别、推荐系统等领域。

Conceptual Usage Example (Python)

Here's how you might call this Cognitive Action using Python. This example demonstrates how to structure your input JSON payload and send a request to 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 = "58b6982f-f099-4ea7-bfa5-457b3c6617f7"  # Action ID for Utilize Yuan 2.0-2B Mars Model

# 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 snippet, you replace the API key and use the action's ID to structure your request correctly. The input payload is constructed based on the required fields, and the response is printed in a readable format.

Conclusion

The Utilize Yuan 2.0-2B Mars Model action provides developers with a powerful tool to generate text that can significantly enhance applications across various domains. By following the steps outlined in this guide, you can easily integrate this advanced language model into your projects and start exploring its capabilities. Consider experimenting with different prompts and parameters to see how the model can best serve your needs!