-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add persona runtime demo with multiple personas #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| PROJECT_ROOT = Path(__file__).resolve().parents[1] | ||
| if str(PROJECT_ROOT) not in sys.path: | ||
| sys.path.insert(0, str(PROJECT_ROOT)) | ||
|
|
||
| from pop.persona_loader import load_all_personas | ||
|
|
||
|
|
||
| def run_demo() -> None: | ||
| personas = load_all_personas( | ||
| names=[ | ||
| "design_persona.json", | ||
| "researcher_persona.json", | ||
| "marketing_persona.json", | ||
| ] | ||
| ) | ||
|
|
||
| print("Loaded personas:") | ||
| print("----------------") | ||
|
|
||
| for persona in personas: | ||
| print(persona.summary()) | ||
| print(" skills:", ", ".join(persona.skills)) | ||
| print() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run_demo() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "Marketing Persona", | ||
| "role": "Marketing Manager", | ||
|
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This JSON is placed in Useful? React with 👍 / 👎. |
||
| "description": "Focuses on messaging, positioning, and audience engagement.", | ||
| "skills": [ | ||
| "copywriting", | ||
| "campaign design", | ||
| "product positioning" | ||
| ], | ||
| "preferred_tools": [ | ||
| "analytics", | ||
| "social media" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "Research Persona", | ||
| "role": "Researcher", | ||
| "description": "Specialized in gathering information and producing concise research summaries.", | ||
| "skills": [ | ||
| "literature search", | ||
| "information synthesis", | ||
| "technical explanation" | ||
| ], | ||
| "preferred_tools": [ | ||
| "web search", | ||
| "academic databases" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
|
|
||
| class Persona: | ||
| def __init__(self, data: dict[str, Any]) -> None: | ||
| self.name = data.get("name") | ||
| self.role = data.get("role") | ||
| self.description = data.get("description") | ||
| self.skills = data.get("skills", []) | ||
| self.tools = data.get("preferred_tools", []) | ||
|
|
||
| def summary(self) -> str: | ||
| return f"{self.name} ({self.role})" | ||
|
|
||
|
|
||
| def load_persona(path: str | Path) -> Persona: | ||
| persona_path = Path(path) | ||
| with persona_path.open(encoding="utf-8") as file: | ||
| data = json.load(file) | ||
| return Persona(data) | ||
|
|
||
|
|
||
| def load_all_personas( | ||
| folder: str | Path = "personas", | ||
| names: list[str] | None = None, | ||
| ) -> list[Persona]: | ||
| folder_path = Path(folder) | ||
| persona_paths = sorted(folder_path.glob("*.json")) | ||
| if names is not None: | ||
| persona_paths = [folder_path / name for name in names] | ||
| return [load_persona(path) for path in persona_paths] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run_demo()callsload_all_personas()without afolder, so the loader defaults to relativepersonas/under the current working directory. If the script is launched from outside the repo root (for examplepython /workspace/persona-object-protocol/demos/persona_agent_demo.py), it fails withFileNotFoundErrorforpersonas/design_persona.jsondespite already computingPROJECT_ROOT.Useful? React with 👍 / 👎.