|
2 | 2 |
|
3 | 3 | [](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/actions/workflows/build.yml) |
4 | 4 |
|
5 | | -The core manager & registry for AI personas in Jupyter AI |
| 5 | +The core manager & registry for AI personas in Jupyter AI. |
6 | 6 |
|
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: |
10 | 8 |
|
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 |
12 | 13 |
|
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. |
15 | 112 |
|
16 | 113 | Development install: |
17 | 114 |
|
|
0 commit comments