Effortless Text Generation with Yi 34b Cognitive Actions

In the world of AI and machine learning, the ability to generate human-like text has become increasingly valuable. The Yi 34b model, developed by 01.AI, offers powerful Cognitive Actions designed for text generation. With its advanced capabilities, Yi 34b allows developers to create diverse and high-quality outputs based on user-defined prompts. This service not only simplifies the process of text generation but also enhances creativity by providing configurable parameters for fine-tuning results.
Common use cases for Yi 34b include generating engaging content for blogs, creating conversational agents, drafting marketing materials, or even brainstorming ideas for stories and names. By leveraging the power of this model, developers can save time and effort while producing high-quality text that meets their specific needs.
Prerequisites
To get started with Yi 34b Cognitive Actions, you will need an API key for access and a general understanding of how to make API calls.
Generate Text with Yi-34B
The "Generate Text with Yi-34B" action utilizes the capabilities of the Yi-34B model to produce text based on a given prompt. This action is designed to solve the problem of generating coherent and contextually relevant text quickly and efficiently.
Input Requirements: The input for this action must be structured as an object containing the following properties:
- prompt: A string that serves as the starting point for text generation (e.g., "Some great names for dogs are:").
- topK: An integer that specifies the number of highest probability tokens to consider (default is 50).
- topP: A number that sets a probability threshold for output generation (default is 0.95).
- temperature: A number that controls the randomness of the output (default is 0.8).
- maxNewTokens: An integer that defines the maximum number of tokens to generate (default is 512).
- promptTemplate: A string that formats the prompt (default is "{prompt}").
- presencePenalty: A number that adjusts the likelihood of a token being generated based on its presence in the text (default is 0).
- frequencyPenalty: A number that applies a penalty to a token's probability based on its frequency in the text (default is 0).
Expected Output: The output will be an array of strings that represent the generated text based on the provided prompt and configurations. For example, you might receive dog names like "Max", "Bella", and "Lucky" along with brief descriptions.
Use Cases for this specific action:
- Content Creation: Quickly generate blog posts or articles based on specific topics or keywords.
- Creative Writing: Assist authors in brainstorming ideas for characters, plots, or names.
- Marketing: Create catchy taglines or product descriptions by providing a brief prompt.
- Chatbots: Enhance conversational agents by generating responses that are contextually relevant to user inquiries.
```python
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 = "9f3b8f54-a4c2-41b3-bbed-594ab70ee886" # Action ID for: Generate Text with Yi-34B
# 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.95,
"prompt": "Some great names for dogs are:",
"temperature": 0.8,
"maxNewTokens": 128,
"promptTemplate": "{prompt}",
"presencePenalty": 0,
"frequencyPenalty": 0
}
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 model's text generation capabilities empower developers to generate high-quality, contextually relevant text with ease. By customizing parameters such as temperature and token limits, users can create diverse outputs tailored to their specific needs. This makes it an invaluable tool for content creators, marketers, and developers alike. Whether you are looking to automate content creation or enhance user interactions, the Yi 34b Cognitive Actions provide a robust solution. Start exploring the possibilities today and unlock the potential of AI-driven text generation!