hebbrix 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hebbrix-2.0.0/MANIFEST.in +5 -0
- hebbrix-2.0.0/PKG-INFO +125 -0
- hebbrix-2.0.0/README.md +82 -0
- hebbrix-2.0.0/hebbrix/__init__.py +69 -0
- hebbrix-2.0.0/hebbrix/chat.py +349 -0
- hebbrix-2.0.0/hebbrix/client.py +226 -0
- hebbrix-2.0.0/hebbrix/exceptions.py +48 -0
- hebbrix-2.0.0/hebbrix/resources.py +978 -0
- hebbrix-2.0.0/hebbrix.egg-info/PKG-INFO +125 -0
- hebbrix-2.0.0/hebbrix.egg-info/SOURCES.txt +14 -0
- hebbrix-2.0.0/hebbrix.egg-info/dependency_links.txt +1 -0
- hebbrix-2.0.0/hebbrix.egg-info/requires.txt +9 -0
- hebbrix-2.0.0/hebbrix.egg-info/top_level.txt +1 -0
- hebbrix-2.0.0/pyproject.toml +75 -0
- hebbrix-2.0.0/setup.cfg +4 -0
- hebbrix-2.0.0/setup.py +57 -0
hebbrix-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hebbrix
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Advanced Memory API for AI Agents with Reinforcement Learning - 3-line integration
|
|
5
|
+
Home-page: https://github.com/hebbrix/hebbrix-python
|
|
6
|
+
Author: Hebbrix Team
|
|
7
|
+
Author-email: Hebbrix Team <support@hebbrix.com>
|
|
8
|
+
Maintainer-email: Hebbrix Team <support@hebbrix.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Homepage, https://hebbrix.com
|
|
11
|
+
Project-URL: Documentation, https://docs.hebbrix.com
|
|
12
|
+
Project-URL: Repository, https://github.com/hebbrix/hebbrix-python
|
|
13
|
+
Project-URL: Bug Tracker, https://github.com/hebbrix/hebbrix-python/issues
|
|
14
|
+
Project-URL: API Reference, https://memory-api.livelystone-78e9a45c.centralus.azurecontainerapps.io/docs
|
|
15
|
+
Keywords: ai,memory,agents,llm,chatbot,assistant,ml,reinforcement-learning,knowledge-graph,vector-search,rag,temporal,procedural-memory,working-memory
|
|
16
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Operating System :: OS Independent
|
|
29
|
+
Classifier: Framework :: AsyncIO
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
Requires-Dist: httpx>=0.25.0
|
|
33
|
+
Requires-Dist: requests>=2.31.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
37
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
40
|
+
Dynamic: author
|
|
41
|
+
Dynamic: home-page
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
|
|
44
|
+
# Hebbrix Python SDK
|
|
45
|
+
|
|
46
|
+
[](https://pypi.org/project/hebbrix/)
|
|
47
|
+
[](https://pypi.org/project/hebbrix/)
|
|
48
|
+
[](LICENSE)
|
|
49
|
+
|
|
50
|
+
Official Python SDK for the Hebbrix api - **the only memory API with Reinforcement Learning**.
|
|
51
|
+
|
|
52
|
+
## 🚀 Features
|
|
53
|
+
|
|
54
|
+
- ✅ **Complete API Coverage** - All 50+ endpoints supported
|
|
55
|
+
- ✅ **Reinforcement Learning** - Train AI agents to optimize memory operations
|
|
56
|
+
- ✅ **Temporal Knowledge Graphs** - Track facts over time with bi-temporal model
|
|
57
|
+
- ✅ **Procedural Memory** - Store and execute learned skills
|
|
58
|
+
- ✅ **Working Memory** - Short-term context buffer for conversations
|
|
59
|
+
- ✅ **Memory Consolidation** - Automatic compression of episodic memories
|
|
60
|
+
- ✅ **Async/Await** - Full async support with httpx
|
|
61
|
+
- ✅ **Type Hints** - Complete type annotations
|
|
62
|
+
- ✅ **Clean API** - Pythonic, intuitive interface
|
|
63
|
+
|
|
64
|
+
## 📦 Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install hebbrix
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🔥 Quick Start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import asyncio
|
|
74
|
+
from hebbrix import MemoryClient
|
|
75
|
+
|
|
76
|
+
async def main():
|
|
77
|
+
# Initialize client
|
|
78
|
+
client = MemoryClient(api_key="mem_sk_your_api_key")
|
|
79
|
+
|
|
80
|
+
# Create a collection
|
|
81
|
+
collection = await client.collections.create(
|
|
82
|
+
name="My AI Agent",
|
|
83
|
+
description="Personal memory for my chatbot"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Store a memory
|
|
87
|
+
memory = await client.memories.create(
|
|
88
|
+
collection_id=collection["id"],
|
|
89
|
+
content="User prefers dark mode and loves Python",
|
|
90
|
+
importance=0.9
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# Search memories
|
|
94
|
+
results = await client.search(
|
|
95
|
+
query="What programming language does user like?",
|
|
96
|
+
collection_id=collection["id"],
|
|
97
|
+
limit=5
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
print(results)
|
|
101
|
+
|
|
102
|
+
# Close client
|
|
103
|
+
await client.close()
|
|
104
|
+
|
|
105
|
+
asyncio.run(main())
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 📚 Complete Documentation
|
|
109
|
+
|
|
110
|
+
Visit https://docs.hebbrix.com for full documentation.
|
|
111
|
+
|
|
112
|
+
## 🔗 Links
|
|
113
|
+
|
|
114
|
+
- **Documentation**: https://docs.hebbrix.com
|
|
115
|
+
- **API Reference**: https://api.hebbrix.com/docs
|
|
116
|
+
- **GitHub**: https://github.com/hebbrix/hebbrix
|
|
117
|
+
- **Examples**: https://github.com/hebbrix/examples
|
|
118
|
+
|
|
119
|
+
## 📄 License
|
|
120
|
+
|
|
121
|
+
MIT License - see [LICENSE](LICENSE) for details
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
**Built with ❤️ by the Hebbrix team**
|
hebbrix-2.0.0/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Hebbrix Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/hebbrix/)
|
|
4
|
+
[](https://pypi.org/project/hebbrix/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Official Python SDK for the Hebbrix api - **the only memory API with Reinforcement Learning**.
|
|
8
|
+
|
|
9
|
+
## 🚀 Features
|
|
10
|
+
|
|
11
|
+
- ✅ **Complete API Coverage** - All 50+ endpoints supported
|
|
12
|
+
- ✅ **Reinforcement Learning** - Train AI agents to optimize memory operations
|
|
13
|
+
- ✅ **Temporal Knowledge Graphs** - Track facts over time with bi-temporal model
|
|
14
|
+
- ✅ **Procedural Memory** - Store and execute learned skills
|
|
15
|
+
- ✅ **Working Memory** - Short-term context buffer for conversations
|
|
16
|
+
- ✅ **Memory Consolidation** - Automatic compression of episodic memories
|
|
17
|
+
- ✅ **Async/Await** - Full async support with httpx
|
|
18
|
+
- ✅ **Type Hints** - Complete type annotations
|
|
19
|
+
- ✅ **Clean API** - Pythonic, intuitive interface
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install hebbrix
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🔥 Quick Start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import asyncio
|
|
31
|
+
from hebbrix import MemoryClient
|
|
32
|
+
|
|
33
|
+
async def main():
|
|
34
|
+
# Initialize client
|
|
35
|
+
client = MemoryClient(api_key="mem_sk_your_api_key")
|
|
36
|
+
|
|
37
|
+
# Create a collection
|
|
38
|
+
collection = await client.collections.create(
|
|
39
|
+
name="My AI Agent",
|
|
40
|
+
description="Personal memory for my chatbot"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Store a memory
|
|
44
|
+
memory = await client.memories.create(
|
|
45
|
+
collection_id=collection["id"],
|
|
46
|
+
content="User prefers dark mode and loves Python",
|
|
47
|
+
importance=0.9
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Search memories
|
|
51
|
+
results = await client.search(
|
|
52
|
+
query="What programming language does user like?",
|
|
53
|
+
collection_id=collection["id"],
|
|
54
|
+
limit=5
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
print(results)
|
|
58
|
+
|
|
59
|
+
# Close client
|
|
60
|
+
await client.close()
|
|
61
|
+
|
|
62
|
+
asyncio.run(main())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 📚 Complete Documentation
|
|
66
|
+
|
|
67
|
+
Visit https://docs.hebbrix.com for full documentation.
|
|
68
|
+
|
|
69
|
+
## 🔗 Links
|
|
70
|
+
|
|
71
|
+
- **Documentation**: https://docs.hebbrix.com
|
|
72
|
+
- **API Reference**: https://api.hebbrix.com/docs
|
|
73
|
+
- **GitHub**: https://github.com/hebbrix/hebbrix
|
|
74
|
+
- **Examples**: https://github.com/hebbrix/examples
|
|
75
|
+
|
|
76
|
+
## 📄 License
|
|
77
|
+
|
|
78
|
+
MIT License - see [LICENSE](LICENSE) for details
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
**Built with ❤️ by the Hebbrix team**
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hebbrix Python SDK - Advanced Memory API for AI Agents
|
|
3
|
+
|
|
4
|
+
A modern, async-first Python SDK for the Hebbrix Memory API.
|
|
5
|
+
The only memory API with Reinforcement Learning for AI agents.
|
|
6
|
+
|
|
7
|
+
Quick Start:
|
|
8
|
+
|
|
9
|
+
from hebbrix import MemoryClient, MemoryChat
|
|
10
|
+
|
|
11
|
+
# Option 1: Simple 3-line chat integration
|
|
12
|
+
chat = MemoryChat(api_key="hbx_...")
|
|
13
|
+
response = chat.send("Remember I love Python!", "user_123")
|
|
14
|
+
response = chat.send("What language do I like?", "user_123")
|
|
15
|
+
|
|
16
|
+
# Option 2: Full async API client
|
|
17
|
+
async with MemoryClient(api_key="hbx_...") as client:
|
|
18
|
+
# Create collection
|
|
19
|
+
collection = await client.collections.create(name="My Agent")
|
|
20
|
+
|
|
21
|
+
# Store memory
|
|
22
|
+
memory = await client.memories.create(
|
|
23
|
+
collection_id=collection["id"],
|
|
24
|
+
content="Important information"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Search with hybrid vector + BM25 + graph
|
|
28
|
+
results = await client.search(query="What was important?", limit=5)
|
|
29
|
+
|
|
30
|
+
# AI-powered reasoning over memories
|
|
31
|
+
answer = await client.reason(query="Explain what I learned")
|
|
32
|
+
|
|
33
|
+
Features:
|
|
34
|
+
- ✅ Reinforcement Learning for memory optimization
|
|
35
|
+
- ✅ Temporal Knowledge Graphs with bi-temporal model
|
|
36
|
+
- ✅ Procedural Memory (skills and learned behaviors)
|
|
37
|
+
- ✅ Working Memory (short-term context buffer)
|
|
38
|
+
- ✅ Memory Consolidation (automatic compression)
|
|
39
|
+
- ✅ 6-layer Hybrid Search (Vector + BM25 + KG + Decay + AI + RL)
|
|
40
|
+
- ✅ Complete async/await support
|
|
41
|
+
- ✅ Type hints throughout
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
__version__ = "2.0.0"
|
|
45
|
+
__author__ = "Hebbrix Team"
|
|
46
|
+
__license__ = "MIT"
|
|
47
|
+
|
|
48
|
+
from hebbrix.client import MemoryClient
|
|
49
|
+
from hebbrix.chat import MemoryChat
|
|
50
|
+
from hebbrix.exceptions import (
|
|
51
|
+
HebbrixError,
|
|
52
|
+
AuthenticationError,
|
|
53
|
+
ValidationError,
|
|
54
|
+
NotFoundError,
|
|
55
|
+
RateLimitError,
|
|
56
|
+
ServerError,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
__all__ = [
|
|
61
|
+
"MemoryClient",
|
|
62
|
+
"MemoryChat",
|
|
63
|
+
"HebbrixError",
|
|
64
|
+
"AuthenticationError",
|
|
65
|
+
"ValidationError",
|
|
66
|
+
"NotFoundError",
|
|
67
|
+
"RateLimitError",
|
|
68
|
+
"ServerError",
|
|
69
|
+
]
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hebbrix Chat Wrapper - 3-Line Integration
|
|
3
|
+
|
|
4
|
+
The easiest way to add memory-powered conversations to your application.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
from hebbrix import MemoryChat
|
|
8
|
+
|
|
9
|
+
chat = MemoryChat(api_key="mem_sk_...")
|
|
10
|
+
response = chat.send("What's my favorite food?", session_id="user_123")
|
|
11
|
+
"""
|
|
12
|
+
from typing import Optional, Dict, Any, List
|
|
13
|
+
import requests
|
|
14
|
+
|
|
15
|
+
from hebbrix.client import MemoryClient
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MemoryChat:
|
|
19
|
+
"""
|
|
20
|
+
Simple chat interface with automatic memory integration.
|
|
21
|
+
|
|
22
|
+
This is the easiest way to use Hebbrix - just 3 lines of code!
|
|
23
|
+
|
|
24
|
+
Features:
|
|
25
|
+
- Automatic memory retrieval
|
|
26
|
+
- User profile injection
|
|
27
|
+
- Session management
|
|
28
|
+
- RL-powered personalization
|
|
29
|
+
- OpenAI-compatible responses
|
|
30
|
+
|
|
31
|
+
Example:
|
|
32
|
+
```python
|
|
33
|
+
from hebbrix import MemoryChat
|
|
34
|
+
|
|
35
|
+
# Line 1: Initialize
|
|
36
|
+
chat = MemoryChat(api_key="mem_sk_...")
|
|
37
|
+
|
|
38
|
+
# Line 2: Send message
|
|
39
|
+
response = chat.send("Hi, remember that I love pizza?", "user_123")
|
|
40
|
+
|
|
41
|
+
# Line 3: Get response with memory
|
|
42
|
+
response = chat.send("What's my favorite food?", "user_123")
|
|
43
|
+
print(response) # "Your favorite food is pizza!"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
api_key: Hebbrix API key
|
|
48
|
+
base_url: API base URL (default: https://api.hebbrix.com)
|
|
49
|
+
model: LLM model to use (default: gpt-4o-mini)
|
|
50
|
+
auto_memory: Enable automatic memory retrieval (default: True)
|
|
51
|
+
auto_profile: Enable user profile injection (default: True)
|
|
52
|
+
personalization: Enable RL-powered personalization (default: True)
|
|
53
|
+
learning: Enable RL trajectory logging (default: True)
|
|
54
|
+
prompt_strategy: Prompt template strategy (default: "default")
|
|
55
|
+
memory_limit: Max memories to retrieve per message (default: 10)
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
api_key: str,
|
|
61
|
+
base_url: str = "http://localhost:8000",
|
|
62
|
+
model: str = "gpt-4o-mini",
|
|
63
|
+
auto_memory: bool = True,
|
|
64
|
+
auto_profile: bool = True,
|
|
65
|
+
personalization: bool = True,
|
|
66
|
+
learning: bool = True,
|
|
67
|
+
prompt_strategy: str = "default",
|
|
68
|
+
memory_limit: int = 10,
|
|
69
|
+
):
|
|
70
|
+
self.api_key = api_key
|
|
71
|
+
self.base_url = base_url.rstrip("/")
|
|
72
|
+
self.model = model
|
|
73
|
+
self.prompt_strategy = prompt_strategy
|
|
74
|
+
self.memory_limit = memory_limit
|
|
75
|
+
|
|
76
|
+
# Feature configuration
|
|
77
|
+
self.features = {
|
|
78
|
+
"memory": auto_memory,
|
|
79
|
+
"user_profile": auto_profile,
|
|
80
|
+
"personalization": personalization,
|
|
81
|
+
"learning": learning,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Also create full client for advanced operations
|
|
85
|
+
self.client = MemoryClient(api_key=api_key, base_url=base_url)
|
|
86
|
+
|
|
87
|
+
def send(
|
|
88
|
+
self,
|
|
89
|
+
message: str,
|
|
90
|
+
session_id: str,
|
|
91
|
+
temperature: float = 0.7,
|
|
92
|
+
max_tokens: Optional[int] = None,
|
|
93
|
+
) -> str:
|
|
94
|
+
"""
|
|
95
|
+
Send a message and get a response with automatic memory integration.
|
|
96
|
+
|
|
97
|
+
This is the main method - just call it and Hebbrix handles everything!
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
message: Your message
|
|
101
|
+
session_id: Session identifier (user ID or conversation ID)
|
|
102
|
+
temperature: Response randomness (0-2, default: 0.7)
|
|
103
|
+
max_tokens: Maximum response length (default: None)
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
Assistant's response as a string
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
response = chat.send("What did I tell you earlier?", "user_123")
|
|
110
|
+
"""
|
|
111
|
+
url = f"{self.base_url}/v1/chat/completions"
|
|
112
|
+
|
|
113
|
+
payload = {
|
|
114
|
+
"model": self.model,
|
|
115
|
+
"messages": [{"role": "user", "content": message}],
|
|
116
|
+
"session_id": session_id,
|
|
117
|
+
"features": self.features,
|
|
118
|
+
"prompt_strategy": self.prompt_strategy,
|
|
119
|
+
"memory_limit": self.memory_limit,
|
|
120
|
+
"temperature": temperature,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if max_tokens:
|
|
124
|
+
payload["max_tokens"] = max_tokens
|
|
125
|
+
|
|
126
|
+
headers = {
|
|
127
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
132
|
+
response.raise_for_status()
|
|
133
|
+
|
|
134
|
+
data = response.json()
|
|
135
|
+
return data["choices"][0]["message"]["content"]
|
|
136
|
+
|
|
137
|
+
def send_with_context(
|
|
138
|
+
self,
|
|
139
|
+
message: str,
|
|
140
|
+
session_id: str,
|
|
141
|
+
temperature: float = 0.7,
|
|
142
|
+
max_tokens: Optional[int] = None,
|
|
143
|
+
) -> Dict[str, Any]:
|
|
144
|
+
"""
|
|
145
|
+
Send a message and get full response with memory context.
|
|
146
|
+
|
|
147
|
+
Use this when you want to see which memories were used.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
message: Your message
|
|
151
|
+
session_id: Session identifier
|
|
152
|
+
temperature: Response randomness (0-2, default: 0.7)
|
|
153
|
+
max_tokens: Maximum response length (default: None)
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
Full response dict with memory context
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
result = chat.send_with_context("What's my name?", "user_123")
|
|
160
|
+
print(result["message"]) # Assistant's response
|
|
161
|
+
print(result["memory_context"]) # Which memories were used
|
|
162
|
+
"""
|
|
163
|
+
url = f"{self.base_url}/v1/chat/completions"
|
|
164
|
+
|
|
165
|
+
payload = {
|
|
166
|
+
"model": self.model,
|
|
167
|
+
"messages": [{"role": "user", "content": message}],
|
|
168
|
+
"session_id": session_id,
|
|
169
|
+
"features": self.features,
|
|
170
|
+
"prompt_strategy": self.prompt_strategy,
|
|
171
|
+
"memory_limit": self.memory_limit,
|
|
172
|
+
"temperature": temperature,
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if max_tokens:
|
|
176
|
+
payload["max_tokens"] = max_tokens
|
|
177
|
+
|
|
178
|
+
headers = {
|
|
179
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
180
|
+
"Content-Type": "application/json",
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
184
|
+
response.raise_for_status()
|
|
185
|
+
|
|
186
|
+
data = response.json()
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
"message": data["choices"][0]["message"]["content"],
|
|
190
|
+
"memory_context": data["memory_context"],
|
|
191
|
+
"usage": data["usage"],
|
|
192
|
+
"model": data["model"],
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
def configure_features(
|
|
196
|
+
self,
|
|
197
|
+
auto_memory: Optional[bool] = None,
|
|
198
|
+
auto_profile: Optional[bool] = None,
|
|
199
|
+
personalization: Optional[bool] = None,
|
|
200
|
+
learning: Optional[bool] = None,
|
|
201
|
+
) -> None:
|
|
202
|
+
"""
|
|
203
|
+
Configure features on the fly.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
auto_memory: Enable/disable automatic memory retrieval
|
|
207
|
+
auto_profile: Enable/disable user profile injection
|
|
208
|
+
personalization: Enable/disable RL personalization
|
|
209
|
+
learning: Enable/disable RL learning
|
|
210
|
+
"""
|
|
211
|
+
if auto_memory is not None:
|
|
212
|
+
self.features["memory"] = auto_memory
|
|
213
|
+
if auto_profile is not None:
|
|
214
|
+
self.features["user_profile"] = auto_profile
|
|
215
|
+
if personalization is not None:
|
|
216
|
+
self.features["personalization"] = personalization
|
|
217
|
+
if learning is not None:
|
|
218
|
+
self.features["learning"] = learning
|
|
219
|
+
|
|
220
|
+
def set_model(self, model: str) -> None:
|
|
221
|
+
"""
|
|
222
|
+
Change the LLM model.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
model: Model name (e.g., "gpt-4o-mini", "claude-3-sonnet")
|
|
226
|
+
"""
|
|
227
|
+
self.model = model
|
|
228
|
+
|
|
229
|
+
def set_strategy(self, strategy: str) -> None:
|
|
230
|
+
"""
|
|
231
|
+
Change the prompt strategy.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
strategy: Strategy name ("default", "concise", "detailed")
|
|
235
|
+
"""
|
|
236
|
+
self.prompt_strategy = strategy
|
|
237
|
+
|
|
238
|
+
def list_sessions(self, active_only: bool = True) -> List[Dict[str, Any]]:
|
|
239
|
+
"""
|
|
240
|
+
List all chat sessions.
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
active_only: Only return active sessions
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
List of session dicts
|
|
247
|
+
"""
|
|
248
|
+
url = f"{self.base_url}/v1/chat/sessions"
|
|
249
|
+
params = {"active_only": active_only}
|
|
250
|
+
headers = {"Authorization": f"Bearer {self.api_key}"}
|
|
251
|
+
|
|
252
|
+
response = requests.get(url, params=params, headers=headers)
|
|
253
|
+
response.raise_for_status()
|
|
254
|
+
|
|
255
|
+
return response.json()["sessions"]
|
|
256
|
+
|
|
257
|
+
def get_session_info(self, session_id: str) -> Dict[str, Any]:
|
|
258
|
+
"""
|
|
259
|
+
Get information about a specific session.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
session_id: Session identifier
|
|
263
|
+
|
|
264
|
+
Returns:
|
|
265
|
+
Session info and statistics
|
|
266
|
+
"""
|
|
267
|
+
url = f"{self.base_url}/v1/chat/sessions/{session_id}"
|
|
268
|
+
headers = {"Authorization": f"Bearer {self.api_key}"}
|
|
269
|
+
|
|
270
|
+
response = requests.get(url, headers=headers)
|
|
271
|
+
response.raise_for_status()
|
|
272
|
+
|
|
273
|
+
return response.json()
|
|
274
|
+
|
|
275
|
+
def delete_session(self, session_id: str) -> None:
|
|
276
|
+
"""
|
|
277
|
+
Delete a chat session.
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
session_id: Session identifier
|
|
281
|
+
"""
|
|
282
|
+
url = f"{self.base_url}/v1/chat/sessions/{session_id}"
|
|
283
|
+
headers = {"Authorization": f"Bearer {self.api_key}"}
|
|
284
|
+
|
|
285
|
+
response = requests.delete(url, headers=headers)
|
|
286
|
+
response.raise_for_status()
|
|
287
|
+
|
|
288
|
+
# Convenience methods for memory operations
|
|
289
|
+
def add_memory(self, content: str, collection_id: str, importance: float = 0.5) -> Dict[str, Any]:
|
|
290
|
+
"""
|
|
291
|
+
Add a memory manually.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
content: Memory content
|
|
295
|
+
collection_id: Collection ID
|
|
296
|
+
importance: Memory importance (0-1)
|
|
297
|
+
|
|
298
|
+
Returns:
|
|
299
|
+
Created memory dict
|
|
300
|
+
"""
|
|
301
|
+
return self.client.memories.create(
|
|
302
|
+
content=content,
|
|
303
|
+
collection_id=collection_id,
|
|
304
|
+
importance=importance,
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
def search_memories(self, query: str, collection_id: Optional[str] = None, limit: int = 10) -> List[Dict[str, Any]]:
|
|
308
|
+
"""
|
|
309
|
+
Search memories manually.
|
|
310
|
+
|
|
311
|
+
Args:
|
|
312
|
+
query: Search query
|
|
313
|
+
collection_id: Optional collection filter
|
|
314
|
+
limit: Number of results
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
List of memory dicts
|
|
318
|
+
"""
|
|
319
|
+
return self.client.memories.search(
|
|
320
|
+
query=query,
|
|
321
|
+
collection_id=collection_id,
|
|
322
|
+
limit=limit,
|
|
323
|
+
)["results"]
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
# Convenience function for even simpler usage
|
|
327
|
+
def quick_chat(api_key: str, message: str, session_id: str) -> str:
|
|
328
|
+
"""
|
|
329
|
+
The absolute simplest way to use Hebbrix - single function call.
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
api_key: Hebbrix API key
|
|
333
|
+
message: Your message
|
|
334
|
+
session_id: Session identifier
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
Assistant's response
|
|
338
|
+
|
|
339
|
+
Example:
|
|
340
|
+
from hebbrix.chat import quick_chat
|
|
341
|
+
|
|
342
|
+
response = quick_chat(
|
|
343
|
+
api_key="mem_sk_...",
|
|
344
|
+
message="What's my favorite color?",
|
|
345
|
+
session_id="user_123"
|
|
346
|
+
)
|
|
347
|
+
"""
|
|
348
|
+
chat = MemoryChat(api_key=api_key)
|
|
349
|
+
return chat.send(message, session_id)
|