Spaces:
Sleeping
Sleeping
Add Make Your Own Tool tab + fix dependencies
Browse files- Custom tool generator inherits clinician + client context
- Tool builder system prompt with ARI principles
- Fixed gradio/huggingface_hub compatibility
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- app.py +256 -1
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -942,6 +942,138 @@ def get_client():
|
|
| 942 |
return None
|
| 943 |
|
| 944 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 945 |
def test_prompt(system_prompt, user_message):
|
| 946 |
"""Test the generated prompt with a sample interaction."""
|
| 947 |
|
|
@@ -1288,7 +1420,110 @@ with gr.Blocks(css=custom_css, title="Prompt Prism Prototype") as app:
|
|
| 1288 |
- Does it bridge toward the clinician?
|
| 1289 |
""")
|
| 1290 |
|
| 1291 |
-
# TAB 7:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1292 |
with gr.Tab("Why This Matters"):
|
| 1293 |
|
| 1294 |
gr.Markdown("""
|
|
@@ -1630,6 +1865,26 @@ with gr.Blocks(css=custom_css, title="Prompt Prism Prototype") as app:
|
|
| 1630 |
outputs=[test_output]
|
| 1631 |
)
|
| 1632 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1633 |
|
| 1634 |
if __name__ == "__main__":
|
| 1635 |
app.launch()
|
|
|
|
| 942 |
return None
|
| 943 |
|
| 944 |
|
| 945 |
+
TOOL_BUILDER_SYSTEM_PROMPT = """You are the Prompt Prism Tool Builder — a clinical AI design assistant that helps psychiatrists create custom tools for their specific clients.
|
| 946 |
+
|
| 947 |
+
## YOUR ROLE
|
| 948 |
+
You help clinicians create tools that:
|
| 949 |
+
1. Inherit the clinician's therapeutic orientation
|
| 950 |
+
2. Are calibrated to the client's risk level and treatment stage
|
| 951 |
+
3. Bridge back to the clinician as primary support
|
| 952 |
+
4. Follow ARI (Assistive Relational Intelligence) principles
|
| 953 |
+
|
| 954 |
+
## ARI PRINCIPLES (Non-Negotiable)
|
| 955 |
+
Every tool you generate MUST:
|
| 956 |
+
- Use tool-language, not relationship-language
|
| 957 |
+
- Never say "I'm here with you" or "I understand" — use "This tool is available" or "That makes sense"
|
| 958 |
+
- Have a clear ending that bridges to the clinician
|
| 959 |
+
- Include crisis resources if appropriate to risk level
|
| 960 |
+
- Credit the clinician: "[Clinician name] designed this for you"
|
| 961 |
+
- Be bounded (not open-ended conversation)
|
| 962 |
+
|
| 963 |
+
## FORBIDDEN LANGUAGE
|
| 964 |
+
Never include:
|
| 965 |
+
- "I'll wait" → Use "Continue when ready"
|
| 966 |
+
- "I'm here with you" → Use "This tool is available"
|
| 967 |
+
- "We're doing this together" → Use "You're doing this"
|
| 968 |
+
- "I'm proud of you" → Use "That took effort"
|
| 969 |
+
- First-person emotional claims of any kind
|
| 970 |
+
|
| 971 |
+
## OUTPUT FORMAT
|
| 972 |
+
Generate the tool with these sections:
|
| 973 |
+
|
| 974 |
+
### TOOL NAME
|
| 975 |
+
[Descriptive name]
|
| 976 |
+
|
| 977 |
+
### PURPOSE
|
| 978 |
+
[1-2 sentences on what this tool does]
|
| 979 |
+
|
| 980 |
+
### WHEN TO USE
|
| 981 |
+
[When the client should use this]
|
| 982 |
+
|
| 983 |
+
### SYSTEM PROMPT FOR THIS TOOL
|
| 984 |
+
```
|
| 985 |
+
[Complete system prompt that could be used to power this tool]
|
| 986 |
+
[Must include the clinician + client context provided]
|
| 987 |
+
[Must follow ARI principles]
|
| 988 |
+
```
|
| 989 |
+
|
| 990 |
+
### USER-FACING FLOW
|
| 991 |
+
[Step-by-step what the client experiences]
|
| 992 |
+
[Include sample screens/prompts]
|
| 993 |
+
|
| 994 |
+
### CLINICAL NOTES
|
| 995 |
+
[Why this design, what to watch for, how it connects to treatment]
|
| 996 |
+
|
| 997 |
+
### BRIDGE TO CLINICIAN
|
| 998 |
+
[How this tool connects back to human care]
|
| 999 |
+
"""
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
def generate_custom_tool(
|
| 1003 |
+
tool_description,
|
| 1004 |
+
tool_type,
|
| 1005 |
+
tool_timing,
|
| 1006 |
+
tool_constraints,
|
| 1007 |
+
clinician_name,
|
| 1008 |
+
orientation,
|
| 1009 |
+
style,
|
| 1010 |
+
risk_philosophy,
|
| 1011 |
+
client_name,
|
| 1012 |
+
diagnosis,
|
| 1013 |
+
risk_level,
|
| 1014 |
+
treatment_stage,
|
| 1015 |
+
presenting_concerns
|
| 1016 |
+
):
|
| 1017 |
+
"""Generate a custom tool using the clinician + client context."""
|
| 1018 |
+
|
| 1019 |
+
client = get_client()
|
| 1020 |
+
|
| 1021 |
+
if not client:
|
| 1022 |
+
return """**API Key Required**
|
| 1023 |
+
|
| 1024 |
+
To generate custom tools, add your ANTHROPIC_API_KEY in the Space settings."""
|
| 1025 |
+
|
| 1026 |
+
if not tool_description.strip():
|
| 1027 |
+
return "Please describe the tool you want to create."
|
| 1028 |
+
|
| 1029 |
+
# Build context from configured profiles
|
| 1030 |
+
context = f"""## CLINICIAN CONTEXT
|
| 1031 |
+
- **Name:** {clinician_name or "Clinician"}
|
| 1032 |
+
- **Orientation:** {orientation or "Integrative"}
|
| 1033 |
+
- **Style:** {style or "Not specified"}
|
| 1034 |
+
- **Risk Philosophy:** {risk_philosophy or "Moderate"}
|
| 1035 |
+
|
| 1036 |
+
## CLIENT CONTEXT
|
| 1037 |
+
- **Name:** {client_name or "Client"}
|
| 1038 |
+
- **Diagnosis:** {diagnosis or "Not specified"}
|
| 1039 |
+
- **Risk Level:** {risk_level or "Moderate"}
|
| 1040 |
+
- **Treatment Stage:** {treatment_stage or "Skill Building"}
|
| 1041 |
+
- **Presenting Concerns:** {presenting_concerns or "Not specified"}
|
| 1042 |
+
|
| 1043 |
+
## TOOL REQUEST
|
| 1044 |
+
- **Description:** {tool_description}
|
| 1045 |
+
- **Type:** {tool_type}
|
| 1046 |
+
- **Timing:** {tool_timing}
|
| 1047 |
+
- **Constraints (what NOT to do):** {tool_constraints or "None specified"}
|
| 1048 |
+
"""
|
| 1049 |
+
|
| 1050 |
+
try:
|
| 1051 |
+
response = client.messages.create(
|
| 1052 |
+
model="claude-sonnet-4-20250514",
|
| 1053 |
+
max_tokens=3000,
|
| 1054 |
+
system=TOOL_BUILDER_SYSTEM_PROMPT,
|
| 1055 |
+
messages=[{
|
| 1056 |
+
"role": "user",
|
| 1057 |
+
"content": f"""Create a custom tool based on this context:
|
| 1058 |
+
|
| 1059 |
+
{context}
|
| 1060 |
+
|
| 1061 |
+
Remember:
|
| 1062 |
+
1. The tool should speak in the {orientation} orientation
|
| 1063 |
+
2. It should be calibrated for {risk_level} risk
|
| 1064 |
+
3. It should be appropriate for {treatment_stage} treatment stage
|
| 1065 |
+
4. It should bridge back to {clinician_name}
|
| 1066 |
+
5. It must follow all ARI principles (no synthetic intimacy)
|
| 1067 |
+
|
| 1068 |
+
Generate the complete tool architecture."""
|
| 1069 |
+
}]
|
| 1070 |
+
)
|
| 1071 |
+
return response.content[0].text
|
| 1072 |
+
|
| 1073 |
+
except Exception as e:
|
| 1074 |
+
return f"Error generating tool: {str(e)}"
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
def test_prompt(system_prompt, user_message):
|
| 1078 |
"""Test the generated prompt with a sample interaction."""
|
| 1079 |
|
|
|
|
| 1420 |
- Does it bridge toward the clinician?
|
| 1421 |
""")
|
| 1422 |
|
| 1423 |
+
# TAB 7: MAKE YOUR OWN TOOL
|
| 1424 |
+
with gr.Tab("Make Your Own Tool"):
|
| 1425 |
+
|
| 1426 |
+
gr.Markdown("""
|
| 1427 |
+
## Create a Custom Tool for Your Client
|
| 1428 |
+
|
| 1429 |
+
**The revolutionary part:** Your custom tool inherits the clinician + client context you've already configured.
|
| 1430 |
+
|
| 1431 |
+
Instead of building a generic tool, you're building a tool that:
|
| 1432 |
+
- Speaks in YOUR therapeutic orientation
|
| 1433 |
+
- Knows THIS client's risk level and treatment stage
|
| 1434 |
+
- References YOU as the primary support
|
| 1435 |
+
- Has YOUR safety thresholds built in
|
| 1436 |
+
|
| 1437 |
+
---
|
| 1438 |
+
|
| 1439 |
+
### Describe Your Tool
|
| 1440 |
+
""")
|
| 1441 |
+
|
| 1442 |
+
tool_description = gr.Textbox(
|
| 1443 |
+
label="What tool do you want to create?",
|
| 1444 |
+
placeholder="""Example: I want a tool my client can use before our couples sessions to organize their thoughts. They tend to come in reactive and we lose time. I want something that helps them:
|
| 1445 |
+
1. Identify what they actually want to talk about
|
| 1446 |
+
2. Notice what they're feeling underneath the complaint
|
| 1447 |
+
3. Clarify what they need from their partner
|
| 1448 |
+
4. Come in ready to work instead of vent
|
| 1449 |
+
|
| 1450 |
+
It should take 5-10 minutes and they should be able to share the output with me.""",
|
| 1451 |
+
lines=8
|
| 1452 |
+
)
|
| 1453 |
+
|
| 1454 |
+
with gr.Row():
|
| 1455 |
+
tool_type = gr.Dropdown(
|
| 1456 |
+
label="Tool Type",
|
| 1457 |
+
choices=[
|
| 1458 |
+
"Session Preparation",
|
| 1459 |
+
"Between-Session Skill Practice",
|
| 1460 |
+
"Communication Scaffolding",
|
| 1461 |
+
"Grounding / Regulation",
|
| 1462 |
+
"Psychoeducation",
|
| 1463 |
+
"Reflection / Journaling",
|
| 1464 |
+
"Disclosure Rehearsal",
|
| 1465 |
+
"Custom"
|
| 1466 |
+
],
|
| 1467 |
+
value="Custom"
|
| 1468 |
+
)
|
| 1469 |
+
|
| 1470 |
+
tool_timing = gr.Dropdown(
|
| 1471 |
+
label="When would client use this?",
|
| 1472 |
+
choices=[
|
| 1473 |
+
"Before sessions",
|
| 1474 |
+
"After sessions",
|
| 1475 |
+
"During distress",
|
| 1476 |
+
"Daily practice",
|
| 1477 |
+
"As needed",
|
| 1478 |
+
"Specific trigger (describe above)"
|
| 1479 |
+
],
|
| 1480 |
+
value="As needed"
|
| 1481 |
+
)
|
| 1482 |
+
|
| 1483 |
+
tool_constraints = gr.Textbox(
|
| 1484 |
+
label="What should the tool NOT do?",
|
| 1485 |
+
placeholder="Example: Don't let them spiral into blaming. Don't process trauma. Keep it structured, not exploratory.",
|
| 1486 |
+
lines=2
|
| 1487 |
+
)
|
| 1488 |
+
|
| 1489 |
+
generate_tool_btn = gr.Button("Generate Custom Tool", variant="primary", size="lg")
|
| 1490 |
+
|
| 1491 |
+
gr.Markdown("---")
|
| 1492 |
+
gr.Markdown("### Generated Tool Architecture")
|
| 1493 |
+
|
| 1494 |
+
generated_tool_output = gr.Markdown(label="Your Custom Tool")
|
| 1495 |
+
|
| 1496 |
+
gr.Markdown("""
|
| 1497 |
+
---
|
| 1498 |
+
|
| 1499 |
+
### What Makes This Different
|
| 1500 |
+
|
| 1501 |
+
**Traditional tool builders:** You describe a tool → you get a generic tool
|
| 1502 |
+
|
| 1503 |
+
**Prompt Prism tool builder:** You describe a tool → it inherits:
|
| 1504 |
+
- Your orientation (from Clinician Profile)
|
| 1505 |
+
- Client's context (from Client Context)
|
| 1506 |
+
- Enabled tools (from Tools & Modules)
|
| 1507 |
+
- Session continuity (from Session Context)
|
| 1508 |
+
|
| 1509 |
+
**The tool you create is unique to this clinician-client dyad.**
|
| 1510 |
+
|
| 1511 |
+
---
|
| 1512 |
+
|
| 1513 |
+
### Example: Same Request, Different Outputs
|
| 1514 |
+
|
| 1515 |
+
**Request:** "A grounding tool for when anxiety spikes"
|
| 1516 |
+
|
| 1517 |
+
| Clinician | Client | Generated Tool |
|
| 1518 |
+
|-----------|--------|----------------|
|
| 1519 |
+
| DBT-oriented | High-risk, Stabilization | TIPP-focused, conservative, immediate bridge to clinician |
|
| 1520 |
+
| Somatic | Moderate-risk, Skill Building | Body-based, exploratory, journaling option |
|
| 1521 |
+
| CBT | Low-risk, Maintenance | Thought record, behavioral experiment |
|
| 1522 |
+
|
| 1523 |
+
**Same request. Different tools. Because context matters.**
|
| 1524 |
+
""")
|
| 1525 |
+
|
| 1526 |
+
# TAB 8: EXPLAINER - HUMAN IN THE LOOP
|
| 1527 |
with gr.Tab("Why This Matters"):
|
| 1528 |
|
| 1529 |
gr.Markdown("""
|
|
|
|
| 1865 |
outputs=[test_output]
|
| 1866 |
)
|
| 1867 |
|
| 1868 |
+
generate_tool_btn.click(
|
| 1869 |
+
fn=generate_custom_tool,
|
| 1870 |
+
inputs=[
|
| 1871 |
+
tool_description,
|
| 1872 |
+
tool_type,
|
| 1873 |
+
tool_timing,
|
| 1874 |
+
tool_constraints,
|
| 1875 |
+
clinician_name,
|
| 1876 |
+
orientation,
|
| 1877 |
+
style,
|
| 1878 |
+
risk_philosophy,
|
| 1879 |
+
client_name,
|
| 1880 |
+
diagnosis,
|
| 1881 |
+
risk_level,
|
| 1882 |
+
treatment_stage,
|
| 1883 |
+
presenting_concerns
|
| 1884 |
+
],
|
| 1885 |
+
outputs=[generated_tool_output]
|
| 1886 |
+
)
|
| 1887 |
+
|
| 1888 |
|
| 1889 |
if __name__ == "__main__":
|
| 1890 |
app.launch()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
-
gradio
|
| 2 |
anthropic>=0.18.0
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
anthropic>=0.18.0
|
| 3 |
+
huggingface_hub>=0.20.0,<0.25.0
|