Effortlessly Generate Text with Yi 34b Chat Actions

The Yi 34b Chat service offers powerful Cognitive Actions designed for seamless text generation. Utilizing advanced large language models developed by 01.AI, these actions provide developers with the ability to create high-quality textual content based on user-defined prompts. This service not only streamlines content generation but also allows for customization through various parameters, such as temperature and filtering options.
Imagine needing to generate creative scripts, write articles, or even create engaging social media posts. The Yi 34b Chat service can significantly reduce the time and effort required to produce such content, making it an invaluable tool for developers looking to enhance their applications with intelligent text generation capabilities.
Prerequisites
To get started with Yi 34b Chat, you will need an API key for the Cognitive Actions service, along with a basic understanding of making API calls.
Generate Text with Yi Series Model
The "Generate Text with Yi Series Model" action allows you to harness the power of the Yi series models to produce text based on a specified prompt. This action is categorized under text generation, and it aims to facilitate the creation of diverse content with flexibility in output style.
Input Requirements
The action requires a structured input object, which includes:
- prompt: The text prompt that guides the generation (e.g., "Write a script to download the images for the top 10 posts of all time from /r/pics using the PRAW library").
- topK: An integer defining the number of highest probability tokens to consider (default is 50).
- topP: A float determining the cumulative probability threshold for generated output (default is 0.8).
- temperature: A float controlling the randomness of the output (default is 0.3).
- maxNewTokens: An integer setting the maximum number of new tokens to generate (default is 1024).
- promptTemplate: A string that defines the formatting template for the prompt (default is a predefined system-user format).
- repetitionPenalty: A float that applies a penalty for repetitive tokens in the output (default is 1.2).
Expected Output
The output will consist of an array of strings, representing the generated text based on the input prompt. This can range from complete sentences to code snippets, depending on the prompt provided.
Use Cases for this specific action
- Content Creation: Quickly generate articles, blog posts, or social media updates based on trending topics.
- Coding Assistance: Produce code snippets or scripts that help developers automate tasks or solve programming challenges.
- Creative Writing: Assist writers in brainstorming ideas or drafting stories by providing creative suggestions based on initial prompts.
- Educational Tools: Develop applications that generate quizzes, explanations, or summaries based on educational content.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "23477011-5381-4e01-b7ac-dea59d99f439" # Action ID for: Generate Text with Yi Series Model
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"topK": 50,
"topP": 0.8,
"prompt": "Write a script to download the images for the top 10 posts of all time from /r/pics using the PRAW library",
"temperature": 0.3,
"maxNewTokens": 1024,
"promptTemplate": "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n",
"repetitionPenalty": 1.2
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
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 (non-JSON): {e.response.text}")
print("------------------------------------------------")
Conclusion
The Yi 34b Chat Cognitive Actions empower developers to effortlessly generate text, saving time and enhancing productivity. From content creation to coding assistance, the versatility of the "Generate Text with Yi Series Model" action opens up numerous possibilities for applications across various domains.
As a next step, consider integrating this action into your projects to automate text generation and deliver dynamic, engaging content tailored to your users' needs.