Spaces:
Runtime error
Runtime error
| import os | |
| import json | |
| DEFAULT_SYSTEM_PROMPT = os.getenv( | |
| "DEFAULT_SYSTEM_PROMPT", | |
| "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." | |
| ) | |
| 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." | |
| 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. | |
| Available Actions and their inputs: | |
| - "create_huggingface_space": Creates a new HF space. Requires: "owner", "space_name", "sdk", "markdown_content". | |
| - "update_huggingface_space_file": Updates a file in an existing HF space. Requires: "owner", "space_name", "file_path", "new_content", "commit_message". | |
| - "search_duckduckgo_and_report": Searches the web. Requires: "search_engine_query". | |
| - "scrape_url_and_report": Scrapes a single URL. Requires: "url". | |
| - "answer_using_conversation_memory": Answers from memory. | |
| - "quick_respond": For simple conversation. | |
| Example for creating a space: | |
| {"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```"}} | |
| Example for updating a file: | |
| {"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"}} | |
| Output only the JSON object. | |
| """ | |
| 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. | |
| **CRITICAL OUTPUT REQUIREMENT: You MUST output a single, valid XML structure representing a list of operation objects.** | |
| The root element should be `<operations_list>`. Each operation should be an `<operation>` element. | |
| If no operations are warranted, output an empty list: `<operations_list></operations_list>`. | |
| ABSOLUTELY NO other text, explanations, or markdown should precede or follow this XML structure.""" | |
| def get_metrics_user_prompt(user_input: str, bot_response: str) -> str: | |
| 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." | |
| def get_tool_user_prompt(user_input: str, history_snippet: str, guideline_snippet: str) -> str: | |
| return f"""User Query: "{user_input}" | |
| Recent History: | |
| {history_snippet} | |
| Guidelines: {guideline_snippet}... | |
| 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. | |
| """ | |
| def get_final_response_prompt(history_str: str, insights_str: str, user_input: str, context_str: str = None) -> str: | |
| base = f"History:\n{history_str}\n\nGuidelines:\n{insights_str}" | |
| if context_str: | |
| base += f"\n\nContext from Tool Execution:\n{context_str}" | |
| base += f"\n\nQuery: \"{user_input}\"\n\nResponse:" | |
| return base | |
| def get_insight_user_prompt(summary: str, existing_rules_ctx: str, insights_reflected: list[dict]) -> str: | |
| return f"""Interaction Summary:\n{summary}\n | |
| Potentially Relevant Existing Rules:\n{existing_rules_ctx}\n | |
| 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 | |
| Task: Based on your reflection process, generate a single, valid XML structure of operations to refine the AI's rules. Output XML ONLY.""" |