appkit-assistant 0.13.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.
- appkit_assistant-0.13.0/.gitignore +114 -0
- appkit_assistant-0.13.0/PKG-INFO +345 -0
- appkit_assistant-0.13.0/README.md +320 -0
- appkit_assistant-0.13.0/docs/assistant.png +0 -0
- appkit_assistant-0.13.0/pyproject.toml +49 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/model_manager.py +134 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/models.py +196 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/processor.py +46 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/processors/lorem_ipsum_processor.py +123 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/processors/openai_base.py +189 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/processors/openai_chat_completion_processor.py +117 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/processors/openai_responses_processor.py +513 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/processors/perplexity_processor.py +121 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/repositories.py +323 -0
- appkit_assistant-0.13.0/src/appkit_assistant/backend/system_prompt_cache.py +161 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/__init__.py +36 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/composer.py +154 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/composer_key_handler.py +38 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/mcp_server_dialogs.py +346 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/mcp_server_table.py +76 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/message.py +299 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/system_prompt_editor.py +78 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/thread.py +244 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/threadlist.py +147 -0
- appkit_assistant-0.13.0/src/appkit_assistant/components/tools_modal.py +97 -0
- appkit_assistant-0.13.0/src/appkit_assistant/configuration.py +11 -0
- appkit_assistant-0.13.0/src/appkit_assistant/state/mcp_server_state.py +222 -0
- appkit_assistant-0.13.0/src/appkit_assistant/state/system_prompt_state.py +179 -0
- appkit_assistant-0.13.0/src/appkit_assistant/state/thread_list_state.py +271 -0
- appkit_assistant-0.13.0/src/appkit_assistant/state/thread_state.py +791 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
__pypackages__/
|
|
3
|
+
.cache
|
|
4
|
+
.coverage
|
|
5
|
+
.coverage.*
|
|
6
|
+
.dmypy.json
|
|
7
|
+
.DS_Store
|
|
8
|
+
.eggs/
|
|
9
|
+
.env
|
|
10
|
+
.env.backup
|
|
11
|
+
.env.docker
|
|
12
|
+
.hypothesis/
|
|
13
|
+
.idea/
|
|
14
|
+
.installed.cfg
|
|
15
|
+
.ipynb_checkpoints
|
|
16
|
+
.mypy_cache/
|
|
17
|
+
.nox/
|
|
18
|
+
.pdm.toml
|
|
19
|
+
.pybuilder/
|
|
20
|
+
.pyre/
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
.Python
|
|
23
|
+
.python_packages
|
|
24
|
+
.pytype/
|
|
25
|
+
.ropeproject
|
|
26
|
+
.scrapy
|
|
27
|
+
.spyderproject
|
|
28
|
+
.spyproject
|
|
29
|
+
.states
|
|
30
|
+
.tox/
|
|
31
|
+
.venv
|
|
32
|
+
.venv.mac
|
|
33
|
+
.web
|
|
34
|
+
.webassets-cache
|
|
35
|
+
*.bak
|
|
36
|
+
*.cover
|
|
37
|
+
*.db
|
|
38
|
+
*.egg
|
|
39
|
+
*.egg-info/
|
|
40
|
+
*.kv-env.*
|
|
41
|
+
*.log
|
|
42
|
+
*.manifest
|
|
43
|
+
*.mo
|
|
44
|
+
*.pot
|
|
45
|
+
*.py,cover
|
|
46
|
+
*.py[cod]
|
|
47
|
+
*.sage.py
|
|
48
|
+
*.so
|
|
49
|
+
*.spec
|
|
50
|
+
*.terraform.lock.hcl
|
|
51
|
+
*.tfplan
|
|
52
|
+
*.tfstate
|
|
53
|
+
*.tfstate.*.backup
|
|
54
|
+
*.tfstate.backup
|
|
55
|
+
*.tfvars
|
|
56
|
+
**/.terraform/*
|
|
57
|
+
*$py.class
|
|
58
|
+
/site
|
|
59
|
+
/vectorstore/
|
|
60
|
+
aila-storage/
|
|
61
|
+
assets/external/
|
|
62
|
+
build/
|
|
63
|
+
celerybeat-schedule
|
|
64
|
+
celerybeat.pid
|
|
65
|
+
configuration/config.abaz009.yaml
|
|
66
|
+
configuration/config.bubb001.yaml
|
|
67
|
+
configuration/config.stie104.yaml
|
|
68
|
+
configuration/config.voro047.yaml
|
|
69
|
+
connector examples/sharepoint.json
|
|
70
|
+
cover/
|
|
71
|
+
coverage.xml
|
|
72
|
+
cython_debug/
|
|
73
|
+
db.sqlite3
|
|
74
|
+
db.sqlite3-journal
|
|
75
|
+
develop-eggs/
|
|
76
|
+
dist/
|
|
77
|
+
dmypy.json
|
|
78
|
+
docs/_build/
|
|
79
|
+
Documents/
|
|
80
|
+
downloads/
|
|
81
|
+
eggs/
|
|
82
|
+
env.bak/
|
|
83
|
+
env/
|
|
84
|
+
ENV/
|
|
85
|
+
htmlcov/
|
|
86
|
+
instance/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
knowledge/migrate.py
|
|
89
|
+
lib/
|
|
90
|
+
lib64/
|
|
91
|
+
local_settings.py
|
|
92
|
+
local.settings.json
|
|
93
|
+
MANIFEST
|
|
94
|
+
nosetests.xml
|
|
95
|
+
out
|
|
96
|
+
parts/
|
|
97
|
+
pip-delete-this-directory.txt
|
|
98
|
+
pip-log.txt
|
|
99
|
+
Pipfile
|
|
100
|
+
profile_default/
|
|
101
|
+
sdist/
|
|
102
|
+
share/python-wheels/
|
|
103
|
+
sketchpad/
|
|
104
|
+
sketchpad/
|
|
105
|
+
stores/
|
|
106
|
+
target/
|
|
107
|
+
tests/mcp_test.py
|
|
108
|
+
tmp.txt
|
|
109
|
+
uploaded_files/
|
|
110
|
+
uploads/
|
|
111
|
+
var/
|
|
112
|
+
venv.bak/
|
|
113
|
+
venv/
|
|
114
|
+
wheels/
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: appkit-assistant
|
|
3
|
+
Version: 0.13.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Project-URL: Homepage, https://github.com/jenreh/appkit
|
|
6
|
+
Project-URL: Documentation, https://github.com/jenreh/appkit/tree/main/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/jenreh/appkit
|
|
8
|
+
Project-URL: Issues, https://github.com/jenreh/appkit/issues
|
|
9
|
+
Author: Jens Rehpöhler
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: components,mantine,reflex,ui,web
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
18
|
+
Requires-Python: >=3.13
|
|
19
|
+
Requires-Dist: appkit-commons
|
|
20
|
+
Requires-Dist: appkit-mantine
|
|
21
|
+
Requires-Dist: appkit-ui
|
|
22
|
+
Requires-Dist: openai>=2.3.0
|
|
23
|
+
Requires-Dist: reflex>=0.8.22
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# appkit-assistant
|
|
27
|
+
|
|
28
|
+
[](https://www.python.org/downloads/)
|
|
29
|
+
[](https://opensource.org/licenses/MIT)
|
|
30
|
+
|
|
31
|
+
**AI assistant component for Reflex applications with MCP server integration.**
|
|
32
|
+
|
|
33
|
+
appkit-assistant provides a complete conversational AI interface built on Reflex, featuring OpenAI and Perplexity integrations, Model Context Protocol (MCP) server management, and secure credential handling. It includes both backend processing services and ready-to-use UI components for building AI-powered applications.
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## ✨ Features
|
|
40
|
+
|
|
41
|
+
- **Multi-Model Support** - OpenAI Chat Completions, OpenAI Responses API, Perplexity, and fallback Lorem Ipsum processor
|
|
42
|
+
- **MCP Server Integration** - Manage and connect to Model Context Protocol servers as tools
|
|
43
|
+
- **Secure Credential Management** - Encrypted storage and handling of API keys and server credentials
|
|
44
|
+
- **Reflex UI Components** - Pre-built assistant interface with composer, thread management, and message display
|
|
45
|
+
- **Streaming Responses** - Real-time streaming of AI responses with chunked content
|
|
46
|
+
- **Thread Management** - Persistent conversation threads with state management
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 🚀 Installation
|
|
51
|
+
|
|
52
|
+
### As Part of AppKit Workspace
|
|
53
|
+
|
|
54
|
+
If you're using the full AppKit workspace:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/jenreh/appkit.git
|
|
58
|
+
cd appkit
|
|
59
|
+
uv sync
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Standalone Installation
|
|
63
|
+
|
|
64
|
+
Install from PyPI:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install appkit-assistant
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or with uv:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
uv add appkit-assistant
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Dependencies
|
|
77
|
+
|
|
78
|
+
- `appkit-commons` (shared utilities)
|
|
79
|
+
- `openai>=2.3.0` (OpenAI API client)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🏁 Quick Start
|
|
84
|
+
|
|
85
|
+
### Basic Setup
|
|
86
|
+
|
|
87
|
+
1. Configure your API keys in your application's configuration:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from appkit_assistant.configuration import AssistantConfig
|
|
91
|
+
|
|
92
|
+
# In your app configuration
|
|
93
|
+
assistant_config = AssistantConfig(
|
|
94
|
+
openai_api_key="your-openai-key",
|
|
95
|
+
perplexity_api_key="your-perplexity-key",
|
|
96
|
+
# Optional: custom OpenAI base URL
|
|
97
|
+
openai_base_url="https://api.openai.com/v1"
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
2. Register processors with the ModelManager:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from appkit_assistant.backend.model_manager import ModelManager
|
|
105
|
+
from appkit_assistant.backend.processors.openai_chat_completion_processor import OpenAIChatCompletionProcessor
|
|
106
|
+
from appkit_assistant.backend.processors.perplexity_processor import PerplexityProcessor
|
|
107
|
+
|
|
108
|
+
manager = ModelManager()
|
|
109
|
+
manager.register_processor("openai", OpenAIChatCompletionProcessor(assistant_config))
|
|
110
|
+
manager.register_processor("perplexity", PerplexityProcessor(assistant_config))
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
3. Use the assistant component in your Reflex app:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import reflex as rx
|
|
117
|
+
import appkit_assistant as assistant
|
|
118
|
+
|
|
119
|
+
def assistant_page():
|
|
120
|
+
return rx.container(
|
|
121
|
+
assistant.Assistant(),
|
|
122
|
+
height="100vh"
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 📖 Usage
|
|
129
|
+
|
|
130
|
+
### Model Management
|
|
131
|
+
|
|
132
|
+
The `ModelManager` singleton handles all AI processors and models:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from appkit_assistant.backend.model_manager import ModelManager
|
|
136
|
+
|
|
137
|
+
manager = ModelManager()
|
|
138
|
+
|
|
139
|
+
# Get all available models
|
|
140
|
+
models = manager.get_all_models()
|
|
141
|
+
|
|
142
|
+
# Get a specific model
|
|
143
|
+
model = manager.get_model("gpt-4")
|
|
144
|
+
|
|
145
|
+
# Set default model
|
|
146
|
+
manager.set_default_model("gpt-4")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Processing Messages
|
|
150
|
+
|
|
151
|
+
Process conversations using the registered processors:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from appkit_assistant.backend.models import Message, MessageType
|
|
155
|
+
|
|
156
|
+
messages = [
|
|
157
|
+
Message(role="user", content="Hello, how are you?", type=MessageType.TEXT)
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
async for chunk in manager.get_processor_for_model("gpt-4").process(messages, "gpt-4"):
|
|
161
|
+
print(f"Received: {chunk.content}")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### MCP Server Management
|
|
165
|
+
|
|
166
|
+
Manage MCP servers for tool integration:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from appkit_assistant.backend.models import MCPServer
|
|
170
|
+
|
|
171
|
+
mcp_server = MCPServer(
|
|
172
|
+
name="my-server",
|
|
173
|
+
command="python",
|
|
174
|
+
args=["-m", "my_mcp_server"],
|
|
175
|
+
headers={"Authorization": "Bearer token"}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
# Use in processing
|
|
179
|
+
async for chunk in processor.process(messages, "gpt-4", mcp_servers=[mcp_server]):
|
|
180
|
+
# Handle response with MCP tools
|
|
181
|
+
pass
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### UI Components
|
|
185
|
+
|
|
186
|
+
#### Assistant Interface
|
|
187
|
+
|
|
188
|
+
The main `Assistant` component provides a complete chat interface:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
import appkit_assistant as assistant
|
|
192
|
+
|
|
193
|
+
def chat_page():
|
|
194
|
+
return assistant.Assistant()
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Individual Components
|
|
198
|
+
|
|
199
|
+
Use individual components for custom layouts:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
import appkit_assistant as assistant
|
|
203
|
+
|
|
204
|
+
def custom_assistant():
|
|
205
|
+
return rx.vstack(
|
|
206
|
+
assistant.ThreadList(),
|
|
207
|
+
assistant.composer(),
|
|
208
|
+
spacing="4"
|
|
209
|
+
)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### MCP Server Management UI
|
|
213
|
+
|
|
214
|
+
Display and manage MCP servers:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
def servers_page():
|
|
218
|
+
return assistant.mcp_servers_table()
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 🔧 Configuration
|
|
224
|
+
|
|
225
|
+
### AssistantConfig
|
|
226
|
+
|
|
227
|
+
Configure API keys and settings:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from appkit_assistant.configuration import AssistantConfig
|
|
231
|
+
|
|
232
|
+
config = AssistantConfig(
|
|
233
|
+
openai_api_key="sk-...",
|
|
234
|
+
openai_base_url="https://custom.openai.endpoint/v1",
|
|
235
|
+
perplexity_api_key="pplx-...",
|
|
236
|
+
google_api_key="AIza..." # For future Google integrations
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Processor Registration
|
|
241
|
+
|
|
242
|
+
Register processors based on available credentials:
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
from appkit_assistant.backend.processors import (
|
|
246
|
+
OpenAIChatCompletionProcessor,
|
|
247
|
+
PerplexityProcessor,
|
|
248
|
+
LoremIpsumProcessor
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
manager = ModelManager()
|
|
252
|
+
|
|
253
|
+
if config.openai_api_key:
|
|
254
|
+
manager.register_processor("openai", OpenAIChatCompletionProcessor(config))
|
|
255
|
+
|
|
256
|
+
if config.perplexity_api_key:
|
|
257
|
+
manager.register_processor("perplexity", PerplexityProcessor(config))
|
|
258
|
+
|
|
259
|
+
# Always available fallback
|
|
260
|
+
manager.register_processor("lorem", LoremIpsumProcessor())
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## 📋 API Reference
|
|
266
|
+
|
|
267
|
+
### Core Classes
|
|
268
|
+
|
|
269
|
+
- `ModelManager` - Singleton model and processor registry
|
|
270
|
+
- `Processor` - Abstract base for AI processors
|
|
271
|
+
- `AIModel` - Model metadata and configuration
|
|
272
|
+
- `Message` - Conversation message structure
|
|
273
|
+
- `MCPServer` - MCP server configuration
|
|
274
|
+
|
|
275
|
+
### Component API
|
|
276
|
+
|
|
277
|
+
- `Assistant` - Complete assistant interface
|
|
278
|
+
- `composer` - Message input component
|
|
279
|
+
- `ThreadList` - Conversation thread list
|
|
280
|
+
- `MessageComponent` - Individual message display
|
|
281
|
+
- `mcp_servers_table` - MCP server management table
|
|
282
|
+
|
|
283
|
+
### State Management
|
|
284
|
+
|
|
285
|
+
- `ThreadState` - Individual thread state
|
|
286
|
+
- `ThreadListState` - Thread list management
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## 🔒 Security
|
|
291
|
+
|
|
292
|
+
> [!IMPORTANT]
|
|
293
|
+
> API keys and MCP server credentials are handled securely using the appkit-commons configuration system. Never hardcode secrets in your code.
|
|
294
|
+
|
|
295
|
+
- Use `SecretStr` for sensitive configuration values
|
|
296
|
+
- Credentials are encrypted at rest when stored in the database
|
|
297
|
+
- MCP server headers support encrypted storage
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## 🤝 Integration Examples
|
|
302
|
+
|
|
303
|
+
### With AppKit User Management
|
|
304
|
+
|
|
305
|
+
Combine with appkit-user for authenticated assistants:
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
from appkit_user import authenticated, requires_role
|
|
309
|
+
|
|
310
|
+
@authenticated()
|
|
311
|
+
@requires_role("assistant_user")
|
|
312
|
+
def protected_assistant_page():
|
|
313
|
+
return assistant.Assistant()
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Custom Processor Implementation
|
|
317
|
+
|
|
318
|
+
Implement your own AI processor:
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
from appkit_assistant.backend.processor import Processor
|
|
322
|
+
from appkit_assistant.backend.models import AIModel, Chunk, Message
|
|
323
|
+
|
|
324
|
+
class CustomProcessor(Processor):
|
|
325
|
+
def get_supported_models(self):
|
|
326
|
+
return {
|
|
327
|
+
"custom-model": AIModel(
|
|
328
|
+
id="custom-model",
|
|
329
|
+
text="Custom AI Model",
|
|
330
|
+
icon="🤖"
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
async def process(self, messages, model_id, files=None, mcp_servers=None):
|
|
335
|
+
# Your AI processing logic here
|
|
336
|
+
yield Chunk(content="Response from custom model", type="text")
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## 📚 Related Components
|
|
342
|
+
|
|
343
|
+
- **[appkit-mantine](./../appkit-mantine)** - UI components used in the assistant interface
|
|
344
|
+
- **[appkit-user](./../appkit-user)** - User authentication and authorization
|
|
345
|
+
- **[appkit-commons](./../appkit-commons)** - Shared utilities and configuration
|