标签 函数配置 下的文章

用了 openwebui 大半年了。从一开始的毛胚房到现在的精装修。踩了很多坑,也一步步的看着 openwebui 更强大更好用。我把我理解的各项功能的好用配置分享给大家交流一下

安装

我是在群晖上通过 docker 方式安装的

docker image prune
docker pull ghcr.io/open-webui/open-webui:main
docker pull ghcr.io/open-webui/mcpo:main

除了端口设置外就只有一个文件夹挂载,这是所有用户数据了。我更新的方式都是通过重置这个容器来升级。

本来是没有第一行的。直到我 200G 系统盘因此被占满 ……

添加模型服务器

通过管理员设置 - 外部链接 - 加号 - 把供应商的域名和 apikey 填进来就可以了

他默认会把所有的模型都以私有的方式给你添加到 owu 来。你可以选择禁用某些用不到的模型,让他们不在可选列表里面出现(比如 rag 相关的重拍、向量化模型),也可以用过将私有转公开的方式让其他用户可以使用该模型。最简单也可以通过环境变量 BYPASS_MODEL_ACCESS_CONTROL=True 来放开所有模型,不用单独设置。

我比较喜欢我的小房子 我去 cherrystudio 偷了一些图标美化我的小房子~

可以在管理员设置 - 模型 - 编辑单个模型去上传图标。

函数

我本地的函数比较简单。就配置了联网搜索以及本地事件的补充,告诉 ai 当前时间

当前时间的话如下。

Message Date And Time 函数代码
"""
title: Message Date And Time
author: benasraudys
author_url: https://github.com/benasraudys
funding_url: https://github.com/benasraudys
description: Gives model current date and time context for each message. Don't forget to adjust the timezone in the settings.
version: 0.1.1
required_open_webui_version: 0.6.4
"""

import datetime
import os
from pydantic import BaseModel, Field
from typing import Callable, Awaitable, Any, Optional


class Filter:
    class Valves(BaseModel):
        timezone_hours: int = Field(
            default=0,
            description="Timezone offset hours (e.g., 5 for UTC+5:30, -4 for UTC-4:00)",
        )
        timezone_minutes: int = Field(
            default=0,
            description="Timezone offset minutes (e.g., 30 for UTC+5:30, 45 for UTC-4:45)",
        )
        southern_hemisphere: bool = Field(
            default=False,
            description="Enable if you're in the Southern Hemisphere (Australia, South America, etc.)",
        )

    def __init__(self):
        self.valves = self.Valves(
            **{
                "timezone_hours": int(os.getenv("DATETIME_TIMEZONE_HOURS", "0")),
                "timezone_minutes": int(os.getenv("DATETIME_TIMEZONE_MINUTES", "0")),
                "southern_hemisphere": os.getenv(
                    "DATETIME_SOUTHERN_HEMISPHERE", "false"
                ).lower()
                == "true",
            }
        )

    def get_season(self, month, southern_hemisphere=False):
        if not southern_hemisphere:
            if 3 <= month <= 5:
                return "Spring"
            elif 6 <= month <= 8:
                return "Summer"
            elif 9 <= month <= 11:
                return "Autumn"
            else:
                return "Winter"
        else:
            if 3 <= month <= 5:
                return "Autumn"
            elif 6 <= month <= 8:
                return "Winter"
            elif 9 <= month <= 11:
                return "Spring"
            else:
                return "Summer"

    def get_time_of_day(self, hour):
        if 5 <= hour < 12:
            return "Morning"
        elif 12 <= hour < 17:
            return "Afternoon"
        elif 17 <= hour < 21:
            return "Evening"
        else:
            return "Night"

    async def inlet(
        self,
        body: dict,
        __event_emitter__: Callable[[Any], Awaitable[None]],
        __request__: Any,
        __user__: Optional[dict] = None,
        __model__: Optional[dict] = None,
    ) -> dict:
        now_utc = datetime.datetime.utcnow()

        timezone_hours = self.valves.timezone_hours
        timezone_minutes = self.valves.timezone_minutes
        total_offset_minutes = (timezone_hours * 60) + timezone_minutes

        now = now_utc + datetime.timedelta(minutes=total_offset_minutes)

        month = now.month
        hour = now.hour

        formatted_date = now.strftime("%B %d, %Y")
        formatted_time = now.strftime("%H:%M:%S")
        day_of_week = now.strftime("%A")

        hours_offset = abs(total_offset_minutes) // 60
        minutes_offset = abs(total_offset_minutes) % 60

        if minutes_offset == 0:
            if total_offset_minutes >= 0:
                timezone_str = f"UTC+{hours_offset}"
            else:
                timezone_str = f"UTC-{hours_offset}"
        else:
            if total_offset_minutes >= 0:
                timezone_str = f"UTC+{hours_offset}:{minutes_offset:02d}"
            else:
                timezone_str = f"UTC-{hours_offset}:{minutes_offset:02d}"

        season = self.get_season(month, self.valves.southern_hemisphere)
        time_of_day = self.get_time_of_day(hour)

        context = f"Current date is {day_of_week}, {formatted_date}, {season}, {time_of_day}, the user time is {formatted_time} {timezone_str}"

        datetime_message = {
            "role": "system",
            "content": f"Time context: {context}. ",
        }

        if "messages" in body and isinstance(body["messages"], list):
            body["messages"].insert(0, datetime_message)
        else:
            body["messages"] = [datetime_message]

        return body

联网搜索的话主要是基于各家模型自己的能力(大概也就是在消息接口参数里面注入模型对应的工具,但是一般都要额外付费,所以我现在基本不用了) 我了解到的,gemini 有这样的函数配置,以及 openai 流式接口也有。这个可以站内查对应工具直接使用。函数认准方块佬就对了。加个方块,搜索更快!

两个工具结合就能达到以下示例的效果

外部工具

这里主要是提供 mcp 的能力 说实话挺难用的。但是我刚好联网搜索走其他方式都有些不好用。我目前是通过 mcp 的方式来实现的。

部署 mcpo

我通过在本地 docker 部署 mcpo,镜像地址在一开始应该已经准备好了。

我群晖这边的部署操作主要是配置了端口为 38000 以及启动命令

mcpo --config /app/mcp-config.json --hot-reload

然后通过文件挂载 /app/mcp-config.json 这个配置文件

文件内容可以参考下面这个

{
    "mcpServers": {
      "grok-search": {
	      "type": "stdio",
	      "command": "npx",
	      "args": ["-y", "grok-search-mcp"],
	      "env": {
	        "GROK_API_URL": "https://-----/v1",
	        "GROK_API_KEY": "-----",
	        "GROK_MODEL": "grok-4-fast",
	        "DEBUG": "true"
	      }
      }
    }
  }

然后我们就可以直接访问 38000 这个端口就可以看到 json 返回了 也能知道你哪些工具启动成功了。

我们就能去管理员设置 - 外部工具 - 加号 新增工具服务器了

在配置完成之后我们可以在对话界面去勾选这个工具 对他进行一些询问。示例如下

当然你可能觉得每一次点都好费劲,当然我们也可以到 管理员设置 - 模型 - 对应模型去默认启动某些工具或其他功能

知识库

知识库我用的其实不多。但是我觉得效果还是不错的。就是遇到这个坑导致 rag 检索不符合预期

内容提取

首先提取引擎我推荐 mistral (主要可以白嫖) 效果也不错 我用过自部署的 tika。有些中文 pdf 会乱码 这个挺好的。但是我还是建议如果可以自己转 md 把

嵌入和检索

这一块我也是跟着 ai 配的。效果还是不错的。

上传合适的文档,结果也能够图文并茂

辅助功能

在管理员设置 - 界面 - 任务这边可以配置一些异步的小任务是否使用 ai 生成

我就开了这个标题自动生成(效果图如左上角),openai 每天免费的 nano 用不完就来这边干点活吧。有标题了也方便你到时候快速查询历史的对话。

图片生成

目前我觉得 owu 做的这个功能比较死板(主要问题是只能填入一个模型)

我有个朋友部署好了 comfy,等给我之后这边估计Pro 就要从对话模型里面选了。

通过这种方式配置好的话 体验和 openai 就很像了。对话勾选一下画图。描述需求就好了


画图也踩过一些坑,比如分享一个 openwebui 中生图模型 chunk too big 问题的解决办法 。里面也有其他佬遇到的其他坑和他们的解决方式。L 站真的是我见过 ai 相关信息最快的一个站了。在站内搜不到,我估计谷歌也搜不到

结语

以上就是我的配置心得。希望我的分享能给你一些启发,也欢迎大家交流各自的 “装修方案”。


📌 转载信息
原作者:
lie5860
转载时间:
2026/1/14 10:56:16