-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
56 lines (43 loc) · 1.52 KB
/
basic_usage.py
File metadata and controls
56 lines (43 loc) · 1.52 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
#!/usr/bin/env python3
"""Basic usage example for RLM-REPL.
This example demonstrates how to use the RLM-REPL library to load a document
and ask questions about it.
"""
from rlm_repl import RLMREPL, RLMConfig
def main():
# Create configuration
# For Ollama (local):
config = RLMConfig(
base_url="http://localhost:11434/v1",
api_key="ollama", # Ollama doesn't require a real key
model="qwen3-coder", # or any model you have installed
verbose=True,
max_iterations=6,
)
# For OpenAI:
# config = RLMConfig(
# base_url="https://api.openai.com/v1",
# api_key="your-api-key",
# model="gpt-4",
# )
# Create REPL instance
with RLMREPL(config) as repl:
# Load a document
# repl.load_document("path/to/your/document.txt")
# Or load text directly
sample_text = open("examples/library.txt", "r").read()
repl.load_text(sample_text, "ml_intro")
# Ask questions
print("\n" + "=" * 70)
print("Asking: how many books are in the library?")
print("=" * 70)
result = repl.ask("what are the titles of the books in the library?")
# Access the result
print(f"\nAnswer: {result.answer}")
print(f"\nStatistics:")
print(f" Iterations: {result.iterations}")
print(f" Lines read: {result.unique_lines}")
print(f" Words read: {result.total_words}")
print(f" Time: {result.elapsed_time:.2f}s")
if __name__ == "__main__":
main()