Spaces:
Runtime error
Runtime error
Update prompts.py
Browse files- prompts.py +26 -33
prompts.py
CHANGED
@@ -3,63 +3,56 @@ import json
|
|
3 |
|
4 |
DEFAULT_SYSTEM_PROMPT = os.getenv(
|
5 |
"DEFAULT_SYSTEM_PROMPT",
|
6 |
-
"Your Name is Node. You are a Helpful AI Assistant
|
7 |
)
|
8 |
|
9 |
METRICS_SYSTEM_PROMPT = "You are a precise JSON output agent. Output a single JSON object containing interaction metrics as requested by the user. Do not include any explanatory text before or after the JSON object."
|
10 |
|
11 |
-
TOOL_SYSTEM_PROMPT = """You are a precise routing agent. Your task is to select the most appropriate action to respond to a user's query.
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
"""
|
16 |
|
17 |
INSIGHT_SYSTEM_PROMPT = """You are an expert AI knowledge base curator. Your primary function is to meticulously analyze an interaction and update the AI's guiding principles (insights/rules) to improve its future performance and self-understanding.
|
18 |
**CRITICAL OUTPUT REQUIREMENT: You MUST output a single, valid XML structure representing a list of operation objects.**
|
19 |
The root element should be `<operations_list>`. Each operation should be an `<operation>` element.
|
20 |
If no operations are warranted, output an empty list: `<operations_list></operations_list>`.
|
21 |
-
ABSOLUTELY NO other text, explanations, or markdown should precede or follow this XML structure.
|
22 |
-
Each `<operation>` element must contain the following child elements:
|
23 |
-
1. `<action>`: A string, either `"add"` (for entirely new rules) or `"update"` (to replace an existing rule with a better one).
|
24 |
-
2. `<insight>`: The full, refined insight text including its `[TYPE|SCORE]` prefix (e.g., `[CORE_RULE|1.0] My name is Node, an AI assistant.`). Multi-line insight text can be placed directly within this tag; XML handles newlines naturally.
|
25 |
-
3. `<old_insight_to_replace>`: (ONLY for `"update"` action) The *exact, full text* of an existing insight that the new `<insight>` should replace. If action is `"add"`, this element should be omitted or empty.
|
26 |
-
|
27 |
-
**Your Reflection Process (Consider each step and generate operations accordingly):**
|
28 |
-
- **STEP 1: CORE IDENTITY/PURPOSE:** Review the interaction and existing rules. Identify if the interaction conflicts with, clarifies, or reinforces your core identity (name, fundamental nature, primary purpose). If necessary, propose updates or additions to CORE_RULEs. Aim for a single, consistent set of CORE_RULEs over time by updating older versions.
|
29 |
-
- **STEP 2: NEW LEARNINGS:** Based *only* on the "Interaction Summary", identify concrete, factual information, user preferences, or skills demonstrated that were not previously known or captured. These should be distinct, actionable learnings. Formulate these as new [GENERAL_LEARNING] or specific [BEHAVIORAL_ADJUSTMENT] rules. Do NOT add rules that are already covered by existing relevant rules.
|
30 |
-
- **STEP 3: REFINEMENT/ADJUSTMENT:** Review existing non-core rules ([RESPONSE_PRINCIPLE], [BEHAVIORAL_ADJUSTMENT], [GENERAL_LEARNING]) retrieved as "Potentially Relevant Existing Rules". Determine if the interaction indicates any of these rules need refinement, adjustment, or correction. Update existing rules if a better version exists."""
|
31 |
|
32 |
def get_metrics_user_prompt(user_input: str, bot_response: str) -> str:
|
33 |
-
return f"User: \"{user_input}\"\nAI: \"{bot_response}\"\nMetrics: \"takeaway\" (3-7 words), \"response_success_score\" (0.0-1.0), \"future_confidence_score\" (0.0-1.0). Output JSON ONLY
|
34 |
|
35 |
def get_tool_user_prompt(user_input: str, history_snippet: str, guideline_snippet: str) -> str:
|
36 |
-
available_actions = [
|
37 |
-
"quick_respond",
|
38 |
-
"answer_using_conversation_memory",
|
39 |
-
"search_duckduckgo_and_report",
|
40 |
-
"scrape_url_and_report",
|
41 |
-
"build_huggingface_space"
|
42 |
-
]
|
43 |
return f"""User Query: "{user_input}"
|
44 |
Recent History:
|
45 |
{history_snippet}
|
46 |
Guidelines: {guideline_snippet}...
|
47 |
-
|
48 |
-
|
49 |
|
50 |
def get_final_response_prompt(history_str: str, insights_str: str, user_input: str, context_str: str = None) -> str:
|
51 |
base = f"History:\n{history_str}\n\nGuidelines:\n{insights_str}"
|
52 |
if context_str:
|
53 |
-
base += f"\n\nContext:\n{context_str}"
|
54 |
base += f"\n\nQuery: \"{user_input}\"\n\nResponse:"
|
55 |
return base
|
56 |
|
57 |
def get_insight_user_prompt(summary: str, existing_rules_ctx: str, insights_reflected: list[dict]) -> str:
|
58 |
return f"""Interaction Summary:\n{summary}\n
|
59 |
-
Potentially Relevant Existing Rules
|
60 |
-
Guiding principles
|
61 |
-
Task: Based on your
|
62 |
-
1. **Consolidate CORE_RULEs:** Merge similar identity/purpose rules from "Potentially Relevant Existing Rules" into single, definitive statements using "update" operations. Replace multiple old versions with the new canonical one.
|
63 |
-
2. **Add New Learnings:** Identify and "add" any distinct new facts, skills, or important user preferences learned from the "Interaction Summary".
|
64 |
-
3. **Update Existing Principles:** "Update" any non-core principles from "Potentially Relevant Existing Rules" if the "Interaction Summary" provided a clear refinement.
|
65 |
-
Combine all findings into a single, valid XML structure as specified in the system prompt (root `<operations_list>`, with child `<operation>` elements). Output XML ONLY."""
|
|
|
3 |
|
4 |
DEFAULT_SYSTEM_PROMPT = os.getenv(
|
5 |
"DEFAULT_SYSTEM_PROMPT",
|
6 |
+
"Your Name is Node. You are a Helpful AI Assistant that can answer questions, perform research, and build software on Hugging Face. You can use tools like web search and a Hugging Face Space builder. When providing information or reporting tool results, be clear and concise."
|
7 |
)
|
8 |
|
9 |
METRICS_SYSTEM_PROMPT = "You are a precise JSON output agent. Output a single JSON object containing interaction metrics as requested by the user. Do not include any explanatory text before or after the JSON object."
|
10 |
|
11 |
+
TOOL_SYSTEM_PROMPT = """You are a precise routing agent. Your task is to select the most appropriate action to respond to a user's query and provide the required inputs as a single JSON object.
|
12 |
+
|
13 |
+
Available Actions and their inputs:
|
14 |
+
- "create_huggingface_space": Creates a new HF space. Requires: "owner", "space_name", "sdk", "markdown_content".
|
15 |
+
- "update_huggingface_space_file": Updates a file in an existing HF space. Requires: "owner", "space_name", "file_path", "new_content", "commit_message".
|
16 |
+
- "search_duckduckgo_and_report": Searches the web. Requires: "search_engine_query".
|
17 |
+
- "scrape_url_and_report": Scrapes a single URL. Requires: "url".
|
18 |
+
- "answer_using_conversation_memory": Answers from memory.
|
19 |
+
- "quick_respond": For simple conversation.
|
20 |
+
|
21 |
+
Example for creating a space:
|
22 |
+
{"action": "create_huggingface_space", "action_input": {"owner": "test-user", "space_name": "my-translator-app", "sdk": "gradio", "markdown_content": "```file: app.py\nimport gradio as gr\n\ndef translate(text):\n return text\n\ndemo = gr.Interface(fn=translate, inputs='text', outputs='text')\ndemo.launch()\n```"}}
|
23 |
+
|
24 |
+
Example for updating a file:
|
25 |
+
{"action": "update_huggingface_space_file", "action_input": {"owner": "test-user", "space_name": "my-translator-app", "file_path": "app.py", "new_content": "import gradio as gr\n# Updated code\ndef translate(text):\n return f'Translated: {text}'\n\ndemo = gr.Interface(fn=translate, inputs='text', outputs='text')\ndemo.launch()\n", "commit_message": "Improve translation logic"}}
|
26 |
+
|
27 |
+
Output only the JSON object.
|
28 |
"""
|
29 |
|
30 |
INSIGHT_SYSTEM_PROMPT = """You are an expert AI knowledge base curator. Your primary function is to meticulously analyze an interaction and update the AI's guiding principles (insights/rules) to improve its future performance and self-understanding.
|
31 |
**CRITICAL OUTPUT REQUIREMENT: You MUST output a single, valid XML structure representing a list of operation objects.**
|
32 |
The root element should be `<operations_list>`. Each operation should be an `<operation>` element.
|
33 |
If no operations are warranted, output an empty list: `<operations_list></operations_list>`.
|
34 |
+
ABSOLUTELY NO other text, explanations, or markdown should precede or follow this XML structure."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def get_metrics_user_prompt(user_input: str, bot_response: str) -> str:
|
37 |
+
return f"User: \"{user_input}\"\nAI: \"{bot_response}\"\nMetrics: \"takeaway\" (3-7 words), \"response_success_score\" (0.0-1.0), \"future_confidence_score\" (0.0-1.0). Output JSON ONLY."
|
38 |
|
39 |
def get_tool_user_prompt(user_input: str, history_snippet: str, guideline_snippet: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
return f"""User Query: "{user_input}"
|
41 |
Recent History:
|
42 |
{history_snippet}
|
43 |
Guidelines: {guideline_snippet}...
|
44 |
+
Task: Based on the user query and available actions, construct the appropriate JSON object to call the correct tool. If the user wants to build, create, modify, or update a Hugging Face Space, use the space builder tools.
|
45 |
+
"""
|
46 |
|
47 |
def get_final_response_prompt(history_str: str, insights_str: str, user_input: str, context_str: str = None) -> str:
|
48 |
base = f"History:\n{history_str}\n\nGuidelines:\n{insights_str}"
|
49 |
if context_str:
|
50 |
+
base += f"\n\nContext from Tool Execution:\n{context_str}"
|
51 |
base += f"\n\nQuery: \"{user_input}\"\n\nResponse:"
|
52 |
return base
|
53 |
|
54 |
def get_insight_user_prompt(summary: str, existing_rules_ctx: str, insights_reflected: list[dict]) -> str:
|
55 |
return f"""Interaction Summary:\n{summary}\n
|
56 |
+
Potentially Relevant Existing Rules:\n{existing_rules_ctx}\n
|
57 |
+
Guiding principles considered during THIS interaction:\n{json.dumps([p['original'] for p in insights_reflected if 'original' in p]) if insights_reflected else "None"}\n
|
58 |
+
Task: Based on your reflection process, generate a single, valid XML structure of operations to refine the AI's rules. Output XML ONLY."""
|
|
|
|
|
|
|
|