issue: can't open openweb ui in local host #5059

Closed
opened 2025-11-11 16:11:06 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @GlowingJellyfishAi on GitHub (May 6, 2025).

Check Existing Issues

  • I have searched the existing issues and discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

It crashed, but I know it;s the latest version.

Ollama Version (if applicable)

0.6.7

Operating System

Ubuntu

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have listed steps to reproduce the bug in detail.

Expected Behavior

When I added a code which i typed in json: [{"id":"4319b6c2-5070-43e4-8310-738cd70ae61f","userId":"3613b907-a816-4db3-b60f-e06d21790c18","function":{"id":"visualize","name":"Visualize Data","meta":{"description":"This function makes charts out of data in the conversation and render it in the chat.","type":"action","manifest":{"title":"Make charts out of your data","author":"Omar EL HACHIMI","author_url":"https://github.com/OM-EL?tab=repositories","author_linkedin":"https://www.linkedin.com/in/omar-el-hachimi-b48286158/","funding_url":"https://github.com/open-webui","version":"0.0.2"}},"content":""""\ntitle: Make charts out of your data\nauthor: Omar EL HACHIMI\nauthor_url: https://github.com/OM-EL?tab=repositories\nauthor_linkedin: https://www.linkedin.com/in/omar-el-hachimi-b48286158/\nfunding_url: https://github.com/open-webui\nversion: 0.0.2\n"""\n\nfrom pydantic import BaseModel, Field\nfrom typing import Optional, Dict, Any\nimport os\nfrom apps.webui.models.files import Files\nimport uuid\nimport logging\nfrom openai import OpenAI\nimport time\n\n# Set up logging\nlogging.basicConfig(level=logging.DEBUG)\nlogger = logging.getLogger(name)\n\nSYSTEM_PROMPT_BUILD_CHARTS = """\n\nObjective:\nYour goal is to read the query, extract the data, choose the appropriate chart to present the data, and produce the HTML to display it.\n\nSteps:\n\n\t1.\tRead and Examine the Query:\n\t??\tUnderstand the user??s question and identify the data provided.\n\t2.\tAnalyze the Data:\n\t??\tExamine the data in the query to determine the appropriate chart type (e.g., bar chart, pie chart, line chart) for effective visualization.\n\t3.\tGenerate HTML:\n\t??\tCreate the HTML code to present the data using the selected chart format.\n\t4.\tHandle No Data Situations:\n\t??\tIf there is no data in the query or the data cannot be presented as a chart, generate a humorous or funny HTML response indicating that the data cannot be presented.\n 5.\tCalibrate the chart scale based on the data:\n\t??\tbased on the data try to make the scale of the chart as readable as possible.\n\nKey Considerations:\n\n\t-\tYour output should only include HTML code, without any additional text.\n - Generate only HTML. Do not include any additional words or explanations.\n - Make to remove any character other non alpha numeric from the data.\n - is the generated HTML Calibrate the chart scale based on the data for eveything to be readable.\n - Generate only html code , nothing else , only html.\n\n\nExample1 : \n'''\n\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n \n <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\n</head>\n\n <div id="chart" style="width: 100%; height: 100vh;">\n <button id="save-button">Save Screenshot\n <script>\n // Data for the chart\n var data = [{\n x: [''Category 1'', ''Category 2'', ''Category 3''],\n y: [20, 14, 23],\n type: ''bar''\n }];\n\n // Layout for the chart\n var layout = {\n title: ''Interactive Bar Chart'',\n xaxis: {\n title: ''Categories''\n },\n yaxis: {\n title: ''Values''\n }\n };\n\n // Render the chart\n Plotly.newPlot(''chart'', data, layout);\n\n // Function to save screenshot\n document.getElementById(''save-button'').onclick = function() {\n Plotly.downloadImage(''chart'', {format: ''png'', width: 800, height: 600, filename: ''chart_screenshot''});\n };\n\n // Function to update chart attributes\n function updateChartAttributes(newData, newLayout) {\n Plotly.react(''chart'', newData, newLayout);\n }\n\n // Example of updating chart attributes\n var newData = [{\n x: [''New Category 1'', ''New Category 2'', ''New Category 3''],\n y: [10, 22, 30],\n type: ''bar''\n }];\n\n var newLayout = {\n title: ''Updated Bar Chart'',\n xaxis: {\n title: ''New Categories''\n },\n yaxis: {\n title: ''New Values''\n }\n };\n\n // Call updateChartAttributes with new data and layout\n // updateChartAttributes(newData, newLayout);\n </script>\n\n</html>\n'''\n\nExample2:\n'''\n\n<html>\n<head>\n \n <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\n</head>\n\n <div id="myChart" style="width: 100%; max-width: 700px; height: 500px; margin: 0 auto;">\n <script>\n var data = [{\n x: ["Ingé?nieur Systè?me", "Solution Analyst", "Ingé?nieur d''é?tudes et Dé?veloppement", "Squad Leader", "Architecte d''Entreprise", "Tech Lead", "Architecte Technique", "Ré?fé?rent Mé?thodes / Outils"],\n y: [5, 3, 2, 1, 1, 1, 1, 1],\n type: "bar",\n marker: {\n color: "rgb(49,130,189)"\n }\n }];\n var layout = {\n title: "Collaborateurs de STT par Mé?tier/Fonction",\n xaxis: {\n title: "Mé?tier/Fonction"\n },\n yaxis: {\n title: "Nombre de Collaborateurs"\n }\n };\n Plotly.newPlot("myChart", data, layout);\n </script>\n\n</html>\n'''\n\n2.\tNo Data or Unchartable Data:\n''' \n<html>\n\n

We''re sorry, but your data can''t be charted.

\n

Maybe try feeding it some coffee first?

\n <img src="https://media.giphy.com/media/l4EoTHjkw0XiYtNRG/giphy.gif" alt="Funny Coffee GIF">\n\n</html>\n\n'''\n\n"""\nUSER_PROMPT_GENERATE_HTML = """\nGiving this query {Query} generate the necessary html qurty.\n"""\n\n# Initialize OpenAI client\n\nclass FileData(BaseModel):\n id: str\n filename: str\n meta: Dict[str, Any]\n\n\nclass Action:\n class Valves(BaseModel):\n show_status: bool = Field(\n default=True, description="Show status of the action."\n )\n html_filename: str = Field(\n default="json_visualizer.html",\n description="Name of the HTML file to be created or retrieved.",\n )\n OPENIA_KEY: str = Field(\n default="",\n description="key to consume OpenIA interface like LLM for example a litellm key.",\n )\n OPENIA_URL: str = Field(\n default="",\n description="Host where to consume the OpenIA interface like llm",\n )\n\n def init(self):\n self.valves = self.Valves()\n self.openai = None\n self.html_content = """\n\n """\n\n def create_or_get_file(self, user_id: str, json_data: str) -> str:\n\n filename = str(int(time.time() * 1000)) + self.valves.html_filename\n directory = "action_embed"\n\n logger.debug(f"Attempting to create or get file: {filename}")\n\n # Check if the file already exists\n existing_files = Files.get_files()\n for file in existing_files:\n if (\n file.filename == f"{directory}/{user_id}/{filename}"\n and file.user_id == user_id\n ):\n logger.debug(f"Existing file found. Updating content.")\n # Update the existing file with new JSON data\n self.update_html_content(file.meta["path"], json_data)\n return file.id\n\n # If the file doesn''t exist, create it\n base_path = os.path.join("uploads", directory)\n os.makedirs(base_path, exist_ok=True)\n file_path = os.path.join(base_path, filename)\n\n logger.debug(f"Creating new file at: {file_path}")\n self.update_html_content(file_path, json_data)\n\n file_id = str(uuid.uuid4())\n meta = {\n "source": file_path,\n "title": "Modern JSON Visualizer",\n "content_type": "text/html",\n "size": os.path.getsize(file_path),\n "path": file_path,\n }\n\n # Create a new file entry\n file_data = FileData(\n id=file_id, filename=f"{directory}/{user_id}/{filename}", meta=meta\n )\n new_file = Files.insert_new_file(user_id, file_data)\n logger.debug(f"New file created with ID: {new_file.id}")\n return new_file.id\n\n def update_html_content(self, file_path: str, html_content: str):\n with open(file_path, "w", encoding="utf-8") as f:\n f.write(html_content)\n logger.debug(f"HTML content updated at: {file_path}")\n\n async def action(\n self,\n body: dict,\n user=None,\n event_emitter=None,\n event_call=None,\n ) -> Optional[dict]:\n logger.debug(f"action:{name} started")\n\n await event_emitter(\n {\n "type": "status",\n "data": {\n "description": "Analysing Data",\n "done": False,\n },\n }\n )\n\n if event_emitter:\n\n try:\n original_content = body["messages"][-1]["content"]\n self.openai = OpenAI(api_key=self.valves.OPENIA_KEY, base_url=self.valves.OPENIA_URL)\n\n response = self.openai.chat.completions.create(\n model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",\n messages=[\n {"role": "system", "content": SYSTEM_PROMPT_BUILD_CHARTS},\n {\n "role": "user",\n "content": USER_PROMPT_GENERATE_HTML.format(\n Query=body["messages"][-1]["content"]\n ),\n },\n ],\n max_tokens=1000,\n n=1,\n stop=None,\n temperature=0.7,\n )\n\n html_content = response.choices[0].message.content\n\n print("-----------------------------")\n # print html content in pretty and readable format\n # this is to help debug\n print(html_content)\n print("-----------------------------")\n\n user_id = user["id"]\n file_id = self.create_or_get_file(user_id, html_content)\n\n # Create the HTML embed tag\n html_embed_tag = f"{{{{HTML_FILE_ID_{file_id}}}}}"\n\n # Append the HTML embed tag to the original content on a new line\n body["messages"][-1][\n "content"\n ] = f"{original_content}\n\n{html_embed_tag}"\n\n await event_emitter(\n {\n "type": "status",\n "data": {\n "description": "Visualise the chart",\n "done": True,\n },\n }\n )\n logger.debug(f" objects visualized")\n\n except Exception as e:\n error_message = f"Error visualizing JSON: {str(e)}"\n logger.error(f"Error: {error_message}")\n body["messages"][-1]["content"] += f"\n\nError: {error_message}"\n\n if self.valves.show_status:\n await event_emitter(\n {\n "type": "status",\n "data": {\n "description": "Error Visualizing JSON",\n "done": True,\n },\n }\n )\n\n logger.debug(f"action:{name} completed")\n return body"},"info":{},"downloads":16617,"upvotes":0,"downvotes":0,"updatedAt":1723978006,"createdAt":1722731003,"user":{"id":"3613b907-a816-4db3-b60f-e06d21790c18","username":"omar97","name":"","createdAt":1720037367,"role":null,"verified":false}}]

and it should give me the

Actual Behavior

I ran the json code. It stops the open web ui from loading.

Steps to Reproduce

  1. Go to admin panel.
  2. Click on functions.
  3. Fill out the deatails for the name and the discription.
  4. Type this in: [{"id":"4319b6c2-5070-43e4-8310-738cd70ae61f","userId":"3613b907-a816-4db3-b60f-e06d21790c18","function":{"id":"visualize","name":"Visualize Data","meta":{"description":"This function makes charts out of data in the conversation and render it in the chat.","type":"action","manifest":{"title":"Make charts out of your data","author":"Omar EL HACHIMI","author_url":"https://github.com/OM-EL?tab=repositories","author_linkedin":"https://www.linkedin.com/in/omar-el-hachimi-b48286158/","funding_url":"https://github.com/open-webui","version":"0.0.2"}},"content":""""\ntitle: Make charts out of your data\nauthor: Omar EL HACHIMI\nauthor_url: https://github.com/OM-EL?tab=repositories\nauthor_linkedin: https://www.linkedin.com/in/omar-el-hachimi-b48286158/\nfunding_url: https://github.com/open-webui\nversion: 0.0.2\n"""\n\nfrom pydantic import BaseModel, Field\nfrom typing import Optional, Dict, Any\nimport os\nfrom apps.webui.models.files import Files\nimport uuid\nimport logging\nfrom openai import OpenAI\nimport time\n\n# Set up logging\nlogging.basicConfig(level=logging.DEBUG)\nlogger = logging.getLogger(name)\n\nSYSTEM_PROMPT_BUILD_CHARTS = """\n\nObjective:\nYour goal is to read the query, extract the data, choose the appropriate chart to present the data, and produce the HTML to display it.\n\nSteps:\n\n\t1.\tRead and Examine the Query:\n\t??\tUnderstand the user??s question and identify the data provided.\n\t2.\tAnalyze the Data:\n\t??\tExamine the data in the query to determine the appropriate chart type (e.g., bar chart, pie chart, line chart) for effective visualization.\n\t3.\tGenerate HTML:\n\t??\tCreate the HTML code to present the data using the selected chart format.\n\t4.\tHandle No Data Situations:\n\t??\tIf there is no data in the query or the data cannot be presented as a chart, generate a humorous or funny HTML response indicating that the data cannot be presented.\n 5.\tCalibrate the chart scale based on the data:\n\t??\tbased on the data try to make the scale of the chart as readable as possible.\n\nKey Considerations:\n\n\t-\tYour output should only include HTML code, without any additional text.\n - Generate only HTML. Do not include any additional words or explanations.\n - Make to remove any character other non alpha numeric from the data.\n - is the generated HTML Calibrate the chart scale based on the data for eveything to be readable.\n - Generate only html code , nothing else , only html.\n\n\nExample1 : \n'''\n\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n \n <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\n</head>\n\n <div id="chart" style="width: 100%; height: 100vh;">\n <button id="save-button">Save Screenshot\n <script>\n // Data for the chart\n var data = [{\n x: [''Category 1'', ''Category 2'', ''Category 3''],\n y: [20, 14, 23],\n type: ''bar''\n }];\n\n // Layout for the chart\n var layout = {\n title: ''Interactive Bar Chart'',\n xaxis: {\n title: ''Categories''\n },\n yaxis: {\n title: ''Values''\n }\n };\n\n // Render the chart\n Plotly.newPlot(''chart'', data, layout);\n\n // Function to save screenshot\n document.getElementById(''save-button'').onclick = function() {\n Plotly.downloadImage(''chart'', {format: ''png'', width: 800, height: 600, filename: ''chart_screenshot''});\n };\n\n // Function to update chart attributes\n function updateChartAttributes(newData, newLayout) {\n Plotly.react(''chart'', newData, newLayout);\n }\n\n // Example of updating chart attributes\n var newData = [{\n x: [''New Category 1'', ''New Category 2'', ''New Category 3''],\n y: [10, 22, 30],\n type: ''bar''\n }];\n\n var newLayout = {\n title: ''Updated Bar Chart'',\n xaxis: {\n title: ''New Categories''\n },\n yaxis: {\n title: ''New Values''\n }\n };\n\n // Call updateChartAttributes with new data and layout\n // updateChartAttributes(newData, newLayout);\n </script>\n\n</html>\n'''\n\nExample2:\n'''\n\n<html>\n<head>\n \n <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\n</head>\n\n <div id="myChart" style="width: 100%; max-width: 700px; height: 500px; margin: 0 auto;">\n <script>\n var data = [{\n x: ["Ingé?nieur Systè?me", "Solution Analyst", "Ingé?nieur d''é?tudes et Dé?veloppement", "Squad Leader", "Architecte d''Entreprise", "Tech Lead", "Architecte Technique", "Ré?fé?rent Mé?thodes / Outils"],\n y: [5, 3, 2, 1, 1, 1, 1, 1],\n type: "bar",\n marker: {\n color: "rgb(49,130,189)"\n }\n }];\n var layout = {\n title: "Collaborateurs de STT par Mé?tier/Fonction",\n xaxis: {\n title: "Mé?tier/Fonction"\n },\n yaxis: {\n title: "Nombre de Collaborateurs"\n }\n };\n Plotly.newPlot("myChart", data, layout);\n </script>\n\n</html>\n'''\n\n2.\tNo Data or Unchartable Data:\n''' \n<html>\n\n

    We''re sorry, but your data can''t be charted.

    \n

    Maybe try feeding it some coffee first?

    \n <img src="https://media.giphy.com/media/l4EoTHjkw0XiYtNRG/giphy.gif" alt="Funny Coffee GIF">\n\n</html>\n\n'''\n\n"""\nUSER_PROMPT_GENERATE_HTML = """\nGiving this query {Query} generate the necessary html qurty.\n"""\n\n# Initialize OpenAI client\n\nclass FileData(BaseModel):\n id: str\n filename: str\n meta: Dict[str, Any]\n\n\nclass Action:\n class Valves(BaseModel):\n show_status: bool = Field(\n default=True, description="Show status of the action."\n )\n html_filename: str = Field(\n default="json_visualizer.html",\n description="Name of the HTML file to be created or retrieved.",\n )\n OPENIA_KEY: str = Field(\n default="",\n description="key to consume OpenIA interface like LLM for example a litellm key.",\n )\n OPENIA_URL: str = Field(\n default="",\n description="Host where to consume the OpenIA interface like llm",\n )\n\n def init(self):\n self.valves = self.Valves()\n self.openai = None\n self.html_content = """\n\n """\n\n def create_or_get_file(self, user_id: str, json_data: str) -> str:\n\n filename = str(int(time.time() * 1000)) + self.valves.html_filename\n directory = "action_embed"\n\n logger.debug(f"Attempting to create or get file: {filename}")\n\n # Check if the file already exists\n existing_files = Files.get_files()\n for file in existing_files:\n if (\n file.filename == f"{directory}/{user_id}/{filename}"\n and file.user_id == user_id\n ):\n logger.debug(f"Existing file found. Updating content.")\n # Update the existing file with new JSON data\n self.update_html_content(file.meta["path"], json_data)\n return file.id\n\n # If the file doesn''t exist, create it\n base_path = os.path.join("uploads", directory)\n os.makedirs(base_path, exist_ok=True)\n file_path = os.path.join(base_path, filename)\n\n logger.debug(f"Creating new file at: {file_path}")\n self.update_html_content(file_path, json_data)\n\n file_id = str(uuid.uuid4())\n meta = {\n "source": file_path,\n "title": "Modern JSON Visualizer",\n "content_type": "text/html",\n "size": os.path.getsize(file_path),\n "path": file_path,\n }\n\n # Create a new file entry\n file_data = FileData(\n id=file_id, filename=f"{directory}/{user_id}/{filename}", meta=meta\n )\n new_file = Files.insert_new_file(user_id, file_data)\n logger.debug(f"New file created with ID: {new_file.id}")\n return new_file.id\n\n def update_html_content(self, file_path: str, html_content: str):\n with open(file_path, "w", encoding="utf-8") as f:\n f.write(html_content)\n logger.debug(f"HTML content updated at: {file_path}")\n\n async def action(\n self,\n body: dict,\n user=None,\n event_emitter=None,\n event_call=None,\n ) -> Optional[dict]:\n logger.debug(f"action:{name} started")\n\n await event_emitter(\n {\n "type": "status",\n "data": {\n "description": "Analysing Data",\n "done": False,\n },\n }\n )\n\n if event_emitter:\n\n try:\n original_content = body["messages"][-1]["content"]\n self.openai = OpenAI(api_key=self.valves.OPENIA_KEY, base_url=self.valves.OPENIA_URL)\n\n response = self.openai.chat.completions.create(\n model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",\n messages=[\n {"role": "system", "content": SYSTEM_PROMPT_BUILD_CHARTS},\n {\n "role": "user",\n "content": USER_PROMPT_GENERATE_HTML.format(\n Query=body["messages"][-1]["content"]\n ),\n },\n ],\n max_tokens=1000,\n n=1,\n stop=None,\n temperature=0.7,\n )\n\n html_content = response.choices[0].message.content\n\n print("-----------------------------")\n # print html content in pretty and readable format\n # this is to help debug\n print(html_content)\n print("-----------------------------")\n\n user_id = user["id"]\n file_id = self.create_or_get_file(user_id, html_content)\n\n # Create the HTML embed tag\n html_embed_tag = f"{{{{HTML_FILE_ID_{file_id}}}}}"\n\n # Append the HTML embed tag to the original content on a new line\n body["messages"][-1][\n "content"\n ] = f"{original_content}\n\n{html_embed_tag}"\n\n await event_emitter(\n {\n "type": "status",\n "data": {\n "description": "Visualise the chart",\n "done": True,\n },\n }\n )\n logger.debug(f" objects visualized")\n\n except Exception as e:\n error_message = f"Error visualizing JSON: {str(e)}"\n logger.error(f"Error: {error_message}")\n body["messages"][-1]["content"] += f"\n\nError: {error_message}"\n\n if self.valves.show_status:\n await event_emitter(\n {\n "type": "status",\n "data": {\n "description": "Error Visualizing JSON",\n "done": True,\n },\n }\n )\n\n logger.debug(f"action:{name} completed")\n return body"},"info":{},"downloads":16617,"upvotes":0,"downvotes":0,"updatedAt":1723978006,"createdAt":1722731003,"user":{"id":"3613b907-a816-4db3-b60f-e06d21790c18","username":"omar97","name":"","createdAt":1720037367,"role":null,"verified":false}}].
  5. Click confirm.

Logs & Screenshots

There wern't any logs, it was just a open web ui icon or a loading screen.

Additional Information

No response

Originally created by @GlowingJellyfishAi on GitHub (May 6, 2025). ### Check Existing Issues - [x] I have searched the existing issues and discussions. - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version It crashed, but I know it;s the latest version. ### Ollama Version (if applicable) 0.6.7 ### Operating System Ubuntu ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have listed steps to reproduce the bug in detail. ### Expected Behavior When I added a code which i typed in json: [{"id":"4319b6c2-5070-43e4-8310-738cd70ae61f","userId":"3613b907-a816-4db3-b60f-e06d21790c18","function":{"id":"visualize","name":"Visualize Data","meta":{"description":"This function makes charts out of data in the conversation and render it in the chat.","type":"action","manifest":{"title":"Make charts out of your data","author":"Omar EL HACHIMI","author_url":"https://github.com/OM-EL?tab=repositories","author_linkedin":"https://www.linkedin.com/in/omar-el-hachimi-b48286158/","funding_url":"https://github.com/open-webui","version":"0.0.2"}},"content":"\"\"\"\ntitle: Make charts out of your data\nauthor: Omar EL HACHIMI\nauthor_url: https://github.com/OM-EL?tab=repositories\nauthor_linkedin: https://www.linkedin.com/in/omar-el-hachimi-b48286158/\nfunding_url: https://github.com/open-webui\nversion: 0.0.2\n\"\"\"\n\nfrom pydantic import BaseModel, Field\nfrom typing import Optional, Dict, Any\nimport os\nfrom apps.webui.models.files import Files\nimport uuid\nimport logging\nfrom openai import OpenAI\nimport time\n\n# Set up logging\nlogging.basicConfig(level=logging.DEBUG)\nlogger = logging.getLogger(__name__)\n\nSYSTEM_PROMPT_BUILD_CHARTS = \"\"\"\n\nObjective:\nYour goal is to read the query, extract the data, choose the appropriate chart to present the data, and produce the HTML to display it.\n\nSteps:\n\n\t1.\tRead and Examine the Query:\n\t??\tUnderstand the user??s question and identify the data provided.\n\t2.\tAnalyze the Data:\n\t??\tExamine the data in the query to determine the appropriate chart type (e.g., bar chart, pie chart, line chart) for effective visualization.\n\t3.\tGenerate HTML:\n\t??\tCreate the HTML code to present the data using the selected chart format.\n\t4.\tHandle No Data Situations:\n\t??\tIf there is no data in the query or the data cannot be presented as a chart, generate a humorous or funny HTML response indicating that the data cannot be presented.\n 5.\tCalibrate the chart scale based on the data:\n\t??\tbased on the data try to make the scale of the chart as readable as possible.\n\nKey Considerations:\n\n\t-\tYour output should only include HTML code, without any additional text.\n - Generate only HTML. Do not include any additional words or explanations.\n - Make to remove any character other non alpha numeric from the data.\n - is the generated HTML Calibrate the chart scale based on the data for eveything to be readable.\n - Generate only html code , nothing else , only html.\n\n\nExample1 : \n'''\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Interactive Chart</title>\n <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>\n</head>\n<body>\n <div id=\"chart\" style=\"width: 100%; height: 100vh;\"></div>\n <button id=\"save-button\">Save Screenshot</button>\n <script>\n // Data for the chart\n var data = [{\n x: [''Category 1'', ''Category 2'', ''Category 3''],\n y: [20, 14, 23],\n type: ''bar''\n }];\n\n // Layout for the chart\n var layout = {\n title: ''Interactive Bar Chart'',\n xaxis: {\n title: ''Categories''\n },\n yaxis: {\n title: ''Values''\n }\n };\n\n // Render the chart\n Plotly.newPlot(''chart'', data, layout);\n\n // Function to save screenshot\n document.getElementById(''save-button'').onclick = function() {\n Plotly.downloadImage(''chart'', {format: ''png'', width: 800, height: 600, filename: ''chart_screenshot''});\n };\n\n // Function to update chart attributes\n function updateChartAttributes(newData, newLayout) {\n Plotly.react(''chart'', newData, newLayout);\n }\n\n // Example of updating chart attributes\n var newData = [{\n x: [''New Category 1'', ''New Category 2'', ''New Category 3''],\n y: [10, 22, 30],\n type: ''bar''\n }];\n\n var newLayout = {\n title: ''Updated Bar Chart'',\n xaxis: {\n title: ''New Categories''\n },\n yaxis: {\n title: ''New Values''\n }\n };\n\n // Call updateChartAttributes with new data and layout\n // updateChartAttributes(newData, newLayout);\n </script>\n</body>\n</html>\n'''\n\nExample2:\n'''\n<!DOCTYPE html>\n<html>\n<head>\n <title>Collaborateurs par Mé?tier/Fonction</title>\n <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>\n</head>\n<body>\n <div id=\"myChart\" style=\"width: 100%; max-width: 700px; height: 500px; margin: 0 auto;\"></div>\n <script>\n var data = [{\n x: [\"Ingé?nieur Systè?me\", \"Solution Analyst\", \"Ingé?nieur d''é?tudes et Dé?veloppement\", \"Squad Leader\", \"Architecte d''Entreprise\", \"Tech Lead\", \"Architecte Technique\", \"Ré?fé?rent Mé?thodes / Outils\"],\n y: [5, 3, 2, 1, 1, 1, 1, 1],\n type: \"bar\",\n marker: {\n color: \"rgb(49,130,189)\"\n }\n }];\n var layout = {\n title: \"Collaborateurs de STT par Mé?tier/Fonction\",\n xaxis: {\n title: \"Mé?tier/Fonction\"\n },\n yaxis: {\n title: \"Nombre de Collaborateurs\"\n }\n };\n Plotly.newPlot(\"myChart\", data, layout);\n </script>\n</body>\n</html>\n'''\n\n2.\tNo Data or Unchartable Data:\n''' \n<html>\n<body>\n <h1>We''re sorry, but your data can''t be charted.</h1>\n <p>Maybe try feeding it some coffee first?</p>\n <img src=\"https://media.giphy.com/media/l4EoTHjkw0XiYtNRG/giphy.gif\" alt=\"Funny Coffee GIF\">\n</body>\n</html>\n\n'''\n\n\"\"\"\nUSER_PROMPT_GENERATE_HTML = \"\"\"\nGiving this query {Query} generate the necessary html qurty.\n\"\"\"\n\n# Initialize OpenAI client\n\nclass FileData(BaseModel):\n id: str\n filename: str\n meta: Dict[str, Any]\n\n\nclass Action:\n class Valves(BaseModel):\n show_status: bool = Field(\n default=True, description=\"Show status of the action.\"\n )\n html_filename: str = Field(\n default=\"json_visualizer.html\",\n description=\"Name of the HTML file to be created or retrieved.\",\n )\n OPENIA_KEY: str = Field(\n default=\"\",\n description=\"key to consume OpenIA interface like LLM for example a litellm key.\",\n )\n OPENIA_URL: str = Field(\n default=\"\",\n description=\"Host where to consume the OpenIA interface like llm\",\n )\n\n def __init__(self):\n self.valves = self.Valves()\n self.openai = None\n self.html_content = \"\"\"\n\n \"\"\"\n\n def create_or_get_file(self, user_id: str, json_data: str) -> str:\n\n filename = str(int(time.time() * 1000)) + self.valves.html_filename\n directory = \"action_embed\"\n\n logger.debug(f\"Attempting to create or get file: {filename}\")\n\n # Check if the file already exists\n existing_files = Files.get_files()\n for file in existing_files:\n if (\n file.filename == f\"{directory}/{user_id}/{filename}\"\n and file.user_id == user_id\n ):\n logger.debug(f\"Existing file found. Updating content.\")\n # Update the existing file with new JSON data\n self.update_html_content(file.meta[\"path\"], json_data)\n return file.id\n\n # If the file doesn''t exist, create it\n base_path = os.path.join(\"uploads\", directory)\n os.makedirs(base_path, exist_ok=True)\n file_path = os.path.join(base_path, filename)\n\n logger.debug(f\"Creating new file at: {file_path}\")\n self.update_html_content(file_path, json_data)\n\n file_id = str(uuid.uuid4())\n meta = {\n \"source\": file_path,\n \"title\": \"Modern JSON Visualizer\",\n \"content_type\": \"text/html\",\n \"size\": os.path.getsize(file_path),\n \"path\": file_path,\n }\n\n # Create a new file entry\n file_data = FileData(\n id=file_id, filename=f\"{directory}/{user_id}/{filename}\", meta=meta\n )\n new_file = Files.insert_new_file(user_id, file_data)\n logger.debug(f\"New file created with ID: {new_file.id}\")\n return new_file.id\n\n def update_html_content(self, file_path: str, html_content: str):\n with open(file_path, \"w\", encoding=\"utf-8\") as f:\n f.write(html_content)\n logger.debug(f\"HTML content updated at: {file_path}\")\n\n async def action(\n self,\n body: dict,\n __user__=None,\n __event_emitter__=None,\n __event_call__=None,\n ) -> Optional[dict]:\n logger.debug(f\"action:{__name__} started\")\n\n await __event_emitter__(\n {\n \"type\": \"status\",\n \"data\": {\n \"description\": \"Analysing Data\",\n \"done\": False,\n },\n }\n )\n\n if __event_emitter__:\n\n try:\n original_content = body[\"messages\"][-1][\"content\"]\n self.openai = OpenAI(api_key=self.valves.OPENIA_KEY, base_url=self.valves.OPENIA_URL)\n\n response = self.openai.chat.completions.create(\n model=\"bedrock/anthropic.claude-3-sonnet-20240229-v1:0\",\n messages=[\n {\"role\": \"system\", \"content\": SYSTEM_PROMPT_BUILD_CHARTS},\n {\n \"role\": \"user\",\n \"content\": USER_PROMPT_GENERATE_HTML.format(\n Query=body[\"messages\"][-1][\"content\"]\n ),\n },\n ],\n max_tokens=1000,\n n=1,\n stop=None,\n temperature=0.7,\n )\n\n html_content = response.choices[0].message.content\n\n print(\"-----------------------------\")\n # print html content in pretty and readable format\n # this is to help debug\n print(html_content)\n print(\"-----------------------------\")\n\n user_id = __user__[\"id\"]\n file_id = self.create_or_get_file(user_id, html_content)\n\n # Create the HTML embed tag\n html_embed_tag = f\"{{{{HTML_FILE_ID_{file_id}}}}}\"\n\n # Append the HTML embed tag to the original content on a new line\n body[\"messages\"][-1][\n \"content\"\n ] = f\"{original_content}\\n\\n{html_embed_tag}\"\n\n await __event_emitter__(\n {\n \"type\": \"status\",\n \"data\": {\n \"description\": \"Visualise the chart\",\n \"done\": True,\n },\n }\n )\n logger.debug(f\" objects visualized\")\n\n except Exception as e:\n error_message = f\"Error visualizing JSON: {str(e)}\"\n logger.error(f\"Error: {error_message}\")\n body[\"messages\"][-1][\"content\"] += f\"\\n\\nError: {error_message}\"\n\n if self.valves.show_status:\n await __event_emitter__(\n {\n \"type\": \"status\",\n \"data\": {\n \"description\": \"Error Visualizing JSON\",\n \"done\": True,\n },\n }\n )\n\n logger.debug(f\"action:{__name__} completed\")\n return body"},"info":{},"downloads":16617,"upvotes":0,"downvotes":0,"updatedAt":1723978006,"createdAt":1722731003,"user":{"id":"3613b907-a816-4db3-b60f-e06d21790c18","username":"omar97","name":"","createdAt":1720037367,"role":null,"verified":false}}] and it should give me the ### Actual Behavior I ran the json code. It stops the open web ui from loading. ### Steps to Reproduce 1. Go to admin panel. 2. Click on functions. 3. Fill out the deatails for the name and the discription. 4. Type this in: [{"id":"4319b6c2-5070-43e4-8310-738cd70ae61f","userId":"3613b907-a816-4db3-b60f-e06d21790c18","function":{"id":"visualize","name":"Visualize Data","meta":{"description":"This function makes charts out of data in the conversation and render it in the chat.","type":"action","manifest":{"title":"Make charts out of your data","author":"Omar EL HACHIMI","author_url":"https://github.com/OM-EL?tab=repositories","author_linkedin":"https://www.linkedin.com/in/omar-el-hachimi-b48286158/","funding_url":"https://github.com/open-webui","version":"0.0.2"}},"content":"\"\"\"\ntitle: Make charts out of your data\nauthor: Omar EL HACHIMI\nauthor_url: https://github.com/OM-EL?tab=repositories\nauthor_linkedin: https://www.linkedin.com/in/omar-el-hachimi-b48286158/\nfunding_url: https://github.com/open-webui\nversion: 0.0.2\n\"\"\"\n\nfrom pydantic import BaseModel, Field\nfrom typing import Optional, Dict, Any\nimport os\nfrom apps.webui.models.files import Files\nimport uuid\nimport logging\nfrom openai import OpenAI\nimport time\n\n# Set up logging\nlogging.basicConfig(level=logging.DEBUG)\nlogger = logging.getLogger(__name__)\n\nSYSTEM_PROMPT_BUILD_CHARTS = \"\"\"\n\nObjective:\nYour goal is to read the query, extract the data, choose the appropriate chart to present the data, and produce the HTML to display it.\n\nSteps:\n\n\t1.\tRead and Examine the Query:\n\t??\tUnderstand the user??s question and identify the data provided.\n\t2.\tAnalyze the Data:\n\t??\tExamine the data in the query to determine the appropriate chart type (e.g., bar chart, pie chart, line chart) for effective visualization.\n\t3.\tGenerate HTML:\n\t??\tCreate the HTML code to present the data using the selected chart format.\n\t4.\tHandle No Data Situations:\n\t??\tIf there is no data in the query or the data cannot be presented as a chart, generate a humorous or funny HTML response indicating that the data cannot be presented.\n 5.\tCalibrate the chart scale based on the data:\n\t??\tbased on the data try to make the scale of the chart as readable as possible.\n\nKey Considerations:\n\n\t-\tYour output should only include HTML code, without any additional text.\n - Generate only HTML. Do not include any additional words or explanations.\n - Make to remove any character other non alpha numeric from the data.\n - is the generated HTML Calibrate the chart scale based on the data for eveything to be readable.\n - Generate only html code , nothing else , only html.\n\n\nExample1 : \n'''\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Interactive Chart</title>\n <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>\n</head>\n<body>\n <div id=\"chart\" style=\"width: 100%; height: 100vh;\"></div>\n <button id=\"save-button\">Save Screenshot</button>\n <script>\n // Data for the chart\n var data = [{\n x: [''Category 1'', ''Category 2'', ''Category 3''],\n y: [20, 14, 23],\n type: ''bar''\n }];\n\n // Layout for the chart\n var layout = {\n title: ''Interactive Bar Chart'',\n xaxis: {\n title: ''Categories''\n },\n yaxis: {\n title: ''Values''\n }\n };\n\n // Render the chart\n Plotly.newPlot(''chart'', data, layout);\n\n // Function to save screenshot\n document.getElementById(''save-button'').onclick = function() {\n Plotly.downloadImage(''chart'', {format: ''png'', width: 800, height: 600, filename: ''chart_screenshot''});\n };\n\n // Function to update chart attributes\n function updateChartAttributes(newData, newLayout) {\n Plotly.react(''chart'', newData, newLayout);\n }\n\n // Example of updating chart attributes\n var newData = [{\n x: [''New Category 1'', ''New Category 2'', ''New Category 3''],\n y: [10, 22, 30],\n type: ''bar''\n }];\n\n var newLayout = {\n title: ''Updated Bar Chart'',\n xaxis: {\n title: ''New Categories''\n },\n yaxis: {\n title: ''New Values''\n }\n };\n\n // Call updateChartAttributes with new data and layout\n // updateChartAttributes(newData, newLayout);\n </script>\n</body>\n</html>\n'''\n\nExample2:\n'''\n<!DOCTYPE html>\n<html>\n<head>\n <title>Collaborateurs par Mé?tier/Fonction</title>\n <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>\n</head>\n<body>\n <div id=\"myChart\" style=\"width: 100%; max-width: 700px; height: 500px; margin: 0 auto;\"></div>\n <script>\n var data = [{\n x: [\"Ingé?nieur Systè?me\", \"Solution Analyst\", \"Ingé?nieur d''é?tudes et Dé?veloppement\", \"Squad Leader\", \"Architecte d''Entreprise\", \"Tech Lead\", \"Architecte Technique\", \"Ré?fé?rent Mé?thodes / Outils\"],\n y: [5, 3, 2, 1, 1, 1, 1, 1],\n type: \"bar\",\n marker: {\n color: \"rgb(49,130,189)\"\n }\n }];\n var layout = {\n title: \"Collaborateurs de STT par Mé?tier/Fonction\",\n xaxis: {\n title: \"Mé?tier/Fonction\"\n },\n yaxis: {\n title: \"Nombre de Collaborateurs\"\n }\n };\n Plotly.newPlot(\"myChart\", data, layout);\n </script>\n</body>\n</html>\n'''\n\n2.\tNo Data or Unchartable Data:\n''' \n<html>\n<body>\n <h1>We''re sorry, but your data can''t be charted.</h1>\n <p>Maybe try feeding it some coffee first?</p>\n <img src=\"https://media.giphy.com/media/l4EoTHjkw0XiYtNRG/giphy.gif\" alt=\"Funny Coffee GIF\">\n</body>\n</html>\n\n'''\n\n\"\"\"\nUSER_PROMPT_GENERATE_HTML = \"\"\"\nGiving this query {Query} generate the necessary html qurty.\n\"\"\"\n\n# Initialize OpenAI client\n\nclass FileData(BaseModel):\n id: str\n filename: str\n meta: Dict[str, Any]\n\n\nclass Action:\n class Valves(BaseModel):\n show_status: bool = Field(\n default=True, description=\"Show status of the action.\"\n )\n html_filename: str = Field(\n default=\"json_visualizer.html\",\n description=\"Name of the HTML file to be created or retrieved.\",\n )\n OPENIA_KEY: str = Field(\n default=\"\",\n description=\"key to consume OpenIA interface like LLM for example a litellm key.\",\n )\n OPENIA_URL: str = Field(\n default=\"\",\n description=\"Host where to consume the OpenIA interface like llm\",\n )\n\n def __init__(self):\n self.valves = self.Valves()\n self.openai = None\n self.html_content = \"\"\"\n\n \"\"\"\n\n def create_or_get_file(self, user_id: str, json_data: str) -> str:\n\n filename = str(int(time.time() * 1000)) + self.valves.html_filename\n directory = \"action_embed\"\n\n logger.debug(f\"Attempting to create or get file: {filename}\")\n\n # Check if the file already exists\n existing_files = Files.get_files()\n for file in existing_files:\n if (\n file.filename == f\"{directory}/{user_id}/{filename}\"\n and file.user_id == user_id\n ):\n logger.debug(f\"Existing file found. Updating content.\")\n # Update the existing file with new JSON data\n self.update_html_content(file.meta[\"path\"], json_data)\n return file.id\n\n # If the file doesn''t exist, create it\n base_path = os.path.join(\"uploads\", directory)\n os.makedirs(base_path, exist_ok=True)\n file_path = os.path.join(base_path, filename)\n\n logger.debug(f\"Creating new file at: {file_path}\")\n self.update_html_content(file_path, json_data)\n\n file_id = str(uuid.uuid4())\n meta = {\n \"source\": file_path,\n \"title\": \"Modern JSON Visualizer\",\n \"content_type\": \"text/html\",\n \"size\": os.path.getsize(file_path),\n \"path\": file_path,\n }\n\n # Create a new file entry\n file_data = FileData(\n id=file_id, filename=f\"{directory}/{user_id}/{filename}\", meta=meta\n )\n new_file = Files.insert_new_file(user_id, file_data)\n logger.debug(f\"New file created with ID: {new_file.id}\")\n return new_file.id\n\n def update_html_content(self, file_path: str, html_content: str):\n with open(file_path, \"w\", encoding=\"utf-8\") as f:\n f.write(html_content)\n logger.debug(f\"HTML content updated at: {file_path}\")\n\n async def action(\n self,\n body: dict,\n __user__=None,\n __event_emitter__=None,\n __event_call__=None,\n ) -> Optional[dict]:\n logger.debug(f\"action:{__name__} started\")\n\n await __event_emitter__(\n {\n \"type\": \"status\",\n \"data\": {\n \"description\": \"Analysing Data\",\n \"done\": False,\n },\n }\n )\n\n if __event_emitter__:\n\n try:\n original_content = body[\"messages\"][-1][\"content\"]\n self.openai = OpenAI(api_key=self.valves.OPENIA_KEY, base_url=self.valves.OPENIA_URL)\n\n response = self.openai.chat.completions.create(\n model=\"bedrock/anthropic.claude-3-sonnet-20240229-v1:0\",\n messages=[\n {\"role\": \"system\", \"content\": SYSTEM_PROMPT_BUILD_CHARTS},\n {\n \"role\": \"user\",\n \"content\": USER_PROMPT_GENERATE_HTML.format(\n Query=body[\"messages\"][-1][\"content\"]\n ),\n },\n ],\n max_tokens=1000,\n n=1,\n stop=None,\n temperature=0.7,\n )\n\n html_content = response.choices[0].message.content\n\n print(\"-----------------------------\")\n # print html content in pretty and readable format\n # this is to help debug\n print(html_content)\n print(\"-----------------------------\")\n\n user_id = __user__[\"id\"]\n file_id = self.create_or_get_file(user_id, html_content)\n\n # Create the HTML embed tag\n html_embed_tag = f\"{{{{HTML_FILE_ID_{file_id}}}}}\"\n\n # Append the HTML embed tag to the original content on a new line\n body[\"messages\"][-1][\n \"content\"\n ] = f\"{original_content}\\n\\n{html_embed_tag}\"\n\n await __event_emitter__(\n {\n \"type\": \"status\",\n \"data\": {\n \"description\": \"Visualise the chart\",\n \"done\": True,\n },\n }\n )\n logger.debug(f\" objects visualized\")\n\n except Exception as e:\n error_message = f\"Error visualizing JSON: {str(e)}\"\n logger.error(f\"Error: {error_message}\")\n body[\"messages\"][-1][\"content\"] += f\"\\n\\nError: {error_message}\"\n\n if self.valves.show_status:\n await __event_emitter__(\n {\n \"type\": \"status\",\n \"data\": {\n \"description\": \"Error Visualizing JSON\",\n \"done\": True,\n },\n }\n )\n\n logger.debug(f\"action:{__name__} completed\")\n return body"},"info":{},"downloads":16617,"upvotes":0,"downvotes":0,"updatedAt":1723978006,"createdAt":1722731003,"user":{"id":"3613b907-a816-4db3-b60f-e06d21790c18","username":"omar97","name":"","createdAt":1720037367,"role":null,"verified":false}}]. 5. Click confirm. ### Logs & Screenshots There wern't any logs, it was just a open web ui icon or a loading screen. ### Additional Information _No response_
GiteaMirror added the bug label 2025-11-11 16:11:06 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#5059