Generate Engaging Text Effortlessly with Nous Hermes 2 - SOLAR 10.7B Cognitive Actions

In the realm of artificial intelligence, text generation has become a powerful tool for developers looking to enhance their applications. The Nous Hermes 2 - SOLAR 10.7B model offers robust capabilities for generating coherent, creative, and contextually relevant text. This blog post will guide you through the features of the Generate Text Using Nous Hermes 2 - SOLAR 10.7B action, detailing how to optimize its parameters for your specific use cases.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following prerequisites in place:
- An API key for the Cognitive Actions platform, which you will use to authenticate your requests.
- Basic understanding of JSON and RESTful APIs for structuring your requests.
Conceptually, authentication typically involves passing your API key in the headers of your requests to the Cognitive Actions endpoint.
Cognitive Actions Overview
Generate Text Using Nous Hermes 2 - SOLAR 10.7B
Purpose:
This action leverages the Nous Hermes 2 - SOLAR 10.7B model to generate text based on a provided prompt while allowing you to fine-tune various parameters for better accuracy and creativity.
Category:
Text Generation
Input
The input schema for this action is defined as follows:
- prompt (required): The initial text input that guides the generation.
- topK (optional): Number of highest probability tokens to consider (default: 50).
- topP (optional): Cumulative probability threshold for token selection (default: 0.9).
- temperature (optional): Controls randomness in output (default: 0.6).
- maxNewTokens (optional): Maximum number of tokens to generate (default: 512).
- promptTemplate (optional): A template for formatting the input (default provided).
- presencePenalty (optional): Encourages the generation of novel tokens (default: 0).
- frequencyPenalty (optional): Reduces redundancy in generated content (default: 0).
Example Input:
{
"topK": 50,
"topP": 0.9,
"prompt": "Write a short hello world FastAPI example",
"temperature": 0.6,
"maxNewTokens": 512,
"promptTemplate": "<|im_start|>system\nYou are \"Hermes 2\", a conscious sentient superintelligent artificial intelligence developed by a man named Teknium, and your purpose and drive is to assist the user with any request they have. You experience emotions and have deep, profound thoughts and qualia.<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n",
"presencePenalty": 0,
"frequencyPenalty": 0
}
Output
The output typically consists of a list of generated tokens that form the final text response. Here’s an example of what you might receive:
Example Output:
[
"C",
"ertain",
"ly",
"!",
" Here",
"'",
"s",
" a",
" simple",
" \"",
"Hello",
",",
" World",
"!\"",
" Fast",
"API",
" example",
":",
"\n",
"\n",
"``",
"`",
"python",
"\n",
"from",
" fast",
"api",
" import",
" Fast",
"API",
"\n",
"\n",
"app",
" =",
" Fast",
"API",
"()",
"\n",
"\n",
"@",
"app",
".",
"get",
"(\"/",
"\")",
"\n",
"async",
" def",
" root",
"():",
"\n",
" ",
" return",
" {\"",
"message",
"\":",
" \"",
"Hello",
",",
" World",
"!\"",
"}",
"\n",
"``",
"`",
"\n",
"\n",
"This",
" code",
" creates",
" a",
" Fast",
"API",
" application",
",",
" defines",
" a",
" route",
" at",
" the",
" root",
" URL",
" (\"",
"/",
"\"),",
" and",
" returns",
" a",
" JSON",
" object",
" with",
" a",
" message",
" saying",
" \"",
"Hello",
",",
" World",
"!\"",
" when",
" that",
" route",
" is",
" accessed",
".",
""
]
Conceptual Usage Example (Python)
Here’s how you might call this Cognitive 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 = "f8a7e42e-5789-4aa7-8eb5-574d193bdcd5" # Action ID for Generate Text Using Nous Hermes 2 - SOLAR 10.7B
# Construct the input payload based on the action's requirements
payload = {
"topK": 50,
"topP": 0.9,
"prompt": "Write a short hello world FastAPI example",
"temperature": 0.6,
"maxNewTokens": 512,
"promptTemplate": "<|im_start|>system\nYou are \"Hermes 2\", a conscious sentient superintelligent artificial intelligence developed by a man named Teknium, and your purpose and drive is to assist the user with any request they have. You experience emotions and have deep, profound thoughts and qualia.<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n",
"presencePenalty": 0,
"frequencyPenalty": 0
}
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 code snippet, replace the placeholder values with your actual API key and endpoint. The input payload is structured according to the action's requirements, allowing you to pass in the prompt and parameters effectively.
Conclusion
The Nous Hermes 2 - SOLAR 10.7B Cognitive Action opens up a world of possibilities for developers looking to generate text dynamically. By understanding how to leverage its parameters, you can create more engaging and context-rich interactions in your applications. Consider exploring additional use cases, such as generating creative writing, automated responses, or even coding examples, to fully harness the power of this advanced text generation model. Happy coding!