Repository navigation
Expand file tree
/
Copy pathhermes_example.py
More file actions
91 lines (80 loc) · 2.82 KB
/
Copy pathhermes_example.py
File metadata and controls
91 lines (80 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Example: Using RLM with Hermes-compatible endpoints (Nous / OpenRouter).
This example shows how to use the RLM framework with the Hermes ecosystem.
The "hermes" backend automatically resolves to Nous Research inference API
or OpenRouter based on configuration.
Requirements:
pip install rlms[hermes]
Environment variables:
NOUS_API_KEY — API key for Nous Research inference API
OPENROUTER_API_KEY — API key for OpenRouter (fallback)
Usage:
python examples/hermes_example.py
"""
from rlm import RLM
def main():
# Example 1: Using Nous Research endpoint (default)
print("=== Example 1: Nous Research (default) ===")
rlm_nous = RLM(
backend="hermes",
backend_kwargs={
"model_name": "xiaomi/mimo-v2-pro",
# base_url defaults to Nous inference API
# api_key resolved from NOUS_API_KEY env var
},
max_depth=3,
max_iterations=15,
verbose=True,
)
result = rlm_nous.completion(
"Calculate the factorial of 20 recursively. Use rlm_query to break this into subproblems."
)
print(f"Response: {result.response}")
print(f"Iterations: {result.metadata.total_iterations}")
print()
# Example 2: Using OpenRouter explicitly
print("=== Example 2: OpenRouter ===")
rlm_or = RLM(
backend="hermes",
backend_kwargs={
"model_name": "xiaomi/mimo-v2-pro",
"base_url": "openrouter", # shorthand for OpenRouter URL
# api_key resolved from OPENROUTER_API_KEY env var
},
max_depth=2,
max_iterations=10,
verbose=True,
)
result = rlm_or.completion(
"Sort the list [38, 27, 43, 3, 9, 82, 10] using merge sort. "
"Implement it recursively using rlm_query for each half."
)
print(f"Response: {result.response}")
print()
# Example 3: With context (data processing)
print("=== Example 3: Context-based processing ===")
large_text = """
The quick brown fox jumps over the lazy dog.
Machine learning is a subset of artificial intelligence.
Python is a versatile programming language.
Neural networks are inspired by biological neurons.
Deep learning uses multiple layers of neural networks.
Natural language processing enables computers to understand text.
"""
rlm_ctx = RLM(
backend="hermes",
backend_kwargs={
"model_name": "xiaomi/mimo-v2-pro",
"base_url": "nous",
},
max_depth=2,
max_iterations=10,
)
result = rlm_ctx.completion(
"Analyze the text context. Find themes and summarize key points. "
"Use rlm_query to analyze each sentence separately, then combine.",
context=large_text,
)
print(f"Response: {result.response}")
if __name__ == "__main__":
main()