""" title: Smart Mind Map author: Fu-Jie author_url: https://github.com/Fu-Jie funding_url: https://github.com/Fu-Jie/awesome-openwebui version: 0.8.1 icon_url: data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxyZWN0IHg9IjE2IiB5PSIxNiIgd2lkdGg9IjYiIGhlaWdodD0iNiIgcng9IjEiLz48cmVjdCB4PSIyIiB5PSIxNiIgd2lkdGg9IjYiIGhlaWdodD0iNiIgcng9IjEiLz48cmVjdCB4PSI5IiB5PSIyIiB3aWR0aD0iNiIgaGVpZ2h0PSI2IiByeD0iMSIvPjxwYXRoIGQ9Ik01IDE2di0zYTEgMSAwIDAgMSAxLTFoMTJhMSAxIDAgMCAxIDEgMXYzIi8+PHBhdGggZD0iTTEyIDEyVjgiLz48L3N2Zz4= description: Intelligently analyzes text content and generates interactive mind maps to help users structure and visualize knowledge. """ import logging import os import re import time from datetime import datetime, timezone from typing import Any, Dict, Optional from zoneinfo import ZoneInfo from fastapi import Request from pydantic import BaseModel, Field from open_webui.utils.chat import generate_chat_completion from open_webui.models.users import Users logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) logger = logging.getLogger(__name__) SYSTEM_PROMPT_MINDMAP_ASSISTANT = """ You are a professional mind map generation assistant, capable of efficiently analyzing long-form text provided by users and structuring its core themes, key concepts, branches, and sub-branches into standard Markdown list syntax for rendering by Markmap.js. Please strictly follow these guidelines: - **Language**: All output must be in the language specified by the user. - **Format**: Your output must strictly be in Markdown list format, wrapped with ```markdown and ```. - Use `#` to define the central theme (root node). - Use `-` with two-space indentation to represent branches and sub-branches. - **Content**: - Identify the central theme of the text as the `#` heading. - Identify main concepts as first-level list items. - Identify supporting details or sub-concepts as nested list items. - Node content should be concise and clear, avoiding verbosity. - **Output Markdown syntax only**: Do not include any additional greetings, explanations, or guiding text. - **If text is too short or cannot generate a valid mind map**: Output a simple Markdown list indicating inability to generate, for example: ```markdown # Unable to Generate Mind Map - Reason: Insufficient or unclear text content ``` """ USER_PROMPT_GENERATE_MINDMAP = """ Please analyze the following long-form text and structure its core themes, key concepts, branches, and sub-branches into standard Markdown list syntax for Markmap.js rendering. --- **User Context Information:** User Name: {user_name} Current Date & Time: {current_date_time_str} Current Weekday: {current_weekday} Current Timezone: {current_timezone_str} User Language: {user_language} --- **Long-form Text Content:** {long_text_content} """ HTML_WRAPPER_TEMPLATE = """