Skip to content

Commit cc06288

Browse files
authored
Merge pull request #1 from 3coins/persona-manager
Persona manager extension
2 parents eeb585c + 2421593 commit cc06288

17 files changed

+2105
-41
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,6 @@ dmypy.json
123123

124124
# Yarn cache
125125
.yarn/
126+
127+
# Local testing
128+
playground/

README.md

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,113 @@
22

33
[![Github Actions Status](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/workflows/Build/badge.svg)](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/actions/workflows/build.yml)
44

5-
The core manager & registry for AI personas in Jupyter AI
5+
The core manager & registry for AI personas in Jupyter AI.
66

7-
This extension is composed of a Python package named `jupyter_ai_persona_manager`
8-
for the server extension and a NPM package named `@jupyter-ai/persona-manager`
9-
for the frontend extension.
7+
This package provides the foundational infrastructure for managing AI personas in Jupyter AI chat environments. It includes:
108

11-
## QUICK START
9+
- **BasePersona**: Abstract base class for creating custom AI personas
10+
- **PersonaManager**: Registry and lifecycle management for personas
11+
- **PersonaAwareness**: Awareness integration for multi-user chat environments
12+
- **Entry Point Support**: Automatic discovery of personas via Python entry points
1213

13-
Everything that follows after this section was from the extension template. We
14-
will need to revise the rest of this README.
14+
AI personas are analogous to "bots" in other chat applications, allowing different AI assistants to coexist in the same chat environment. Each persona can have unique behavior, models, and capabilities.
15+
16+
## Adding a New Persona via Entry Points
17+
18+
To create and register a custom AI persona:
19+
20+
### 1. Create Your Persona Class
21+
22+
```python
23+
from jupyter_ai_persona_manager import BasePersona, PersonaDefaults
24+
from jupyterlab_chat.models import Message
25+
26+
class MyCustomPersona(BasePersona):
27+
@property
28+
def defaults(self):
29+
return PersonaDefaults(
30+
name="MyPersona",
31+
description="A helpful custom assistant",
32+
avatar_path="/api/ai/static/custom-avatar.svg",
33+
system_prompt="You are a helpful assistant specialized in...",
34+
)
35+
36+
async def process_message(self, message: Message):
37+
# Your custom logic here
38+
response = f"Hello! You said: {message.body}"
39+
self.send_message(response)
40+
```
41+
42+
### 2. Register via Entry Points
43+
44+
Add to your package's `pyproject.toml`:
45+
46+
```toml
47+
[project.entry-points."jupyter_ai.personas"]
48+
my-custom-persona = "my_package.personas:MyCustomPersona"
49+
```
50+
51+
### 3. Install and Restart
52+
53+
```bash
54+
pip install your-package
55+
# Restart JupyterLab to load the new persona
56+
```
57+
58+
Your persona will automatically appear in Jupyter AI chats and can be @-mentioned by name.
59+
60+
## Loading Personas from .jupyter Directory
61+
62+
For development and local customization, personas can be loaded from the `.jupyter/personas/` directory:
63+
64+
### Directory Structure
65+
66+
```
67+
.jupyter/
68+
└── personas/
69+
├── my_custom_persona.py
70+
├── research_assistant.py
71+
└── debug_helper.py
72+
```
73+
74+
### File Requirements
75+
76+
- Place Python files in `.jupyter/personas/` (not directly in `.jupyter/`)
77+
- Filename must contain "persona" (case-insensitive)
78+
- Cannot start with `_` or `.` (treated as private/hidden)
79+
- Must contain a class inheriting from `BasePersona`
80+
81+
### Example Local Persona
82+
83+
**File: `.jupyter/personas/my_persona.py`**
84+
85+
```python
86+
from jupyter_ai_persona_manager import BasePersona, PersonaDefaults
87+
from jupyterlab_chat.models import Message
88+
89+
class MyLocalPersona(BasePersona):
90+
@property
91+
def defaults(self):
92+
return PersonaDefaults(
93+
name="Local Dev Assistant",
94+
description="A persona for local development",
95+
avatar_path="/api/ai/static/jupyternaut.svg",
96+
system_prompt="You help with local development tasks.",
97+
)
98+
99+
async def process_message(self, message: Message):
100+
self.send_message(f"Local persona received: {message.body}")
101+
```
102+
103+
### Refreshing Personas
104+
105+
Use the `/refresh-personas` slash command in any chat to reload personas without restarting JupyterLab:
106+
107+
```
108+
/refresh-personas
109+
```
110+
111+
This allows for iterative development - modify your local persona files and refresh to see changes immediately.
15112

16113
Development install:
17114

jupyter_ai_persona_manager/__init__.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import warnings
88
warnings.warn("Importing 'jupyter_ai_persona_manager' outside a proper installation.")
99
__version__ = "dev"
10-
from .handlers import setup_handlers
10+
11+
from .base_persona import BasePersona, PersonaDefaults
12+
from .persona_manager import PersonaManager
13+
from .persona_awareness import PersonaAwareness
14+
from .extension import PersonaManagerExtension
1115

1216

1317
def _jupyter_labextension_paths():
@@ -18,19 +22,4 @@ def _jupyter_labextension_paths():
1822

1923

2024
def _jupyter_server_extension_points():
21-
return [{
22-
"module": "jupyter_ai_persona_manager"
23-
}]
24-
25-
26-
def _load_jupyter_server_extension(server_app):
27-
"""Registers the API handler to receive HTTP requests from the frontend extension.
28-
29-
Parameters
30-
----------
31-
server_app: jupyterlab.labapp.LabApp
32-
JupyterLab application instance
33-
"""
34-
setup_handlers(server_app.web_app)
35-
name = "jupyter_ai_persona_manager"
36-
server_app.log.info(f"Registered {name} server extension")
25+
return [{"module": "jupyter_ai_persona_manager", "app": PersonaManagerExtension}]

0 commit comments

Comments
 (0)