跳到主要内容
警告

本教程由社区贡献,不获得 Open WebUI 团队的支持。它仅作为演示,说明如何根据您的特定用例定制 Open WebUI。想要贡献?请查看贡献教程。

💡 特殊参数

当开发您自己的工具 (Tools)函数 (Functions)过滤器 (Filters)管道 (Pipes)动作 (Actions))、流程 (Pipelines) 等时,您可以使用特殊参数来探索 Open-WebUI 提供的全部功能。

本页面旨在详细介绍每个特殊参数的类型和结构,并提供示例。

body

一个字典 (dict),通常几乎直接发送给模型。虽然它不严格是一个特殊参数,但为了方便参考此处包含它,因为它本身包含一些特殊参数。

示例

{
"stream": true,
"model": "my-cool-model",
# lowercase string with - separated words: this is the ID of the model
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this picture?"
},
{
"type": "image_url",
"image_url": {
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdYAAAGcCAYAAABk2YF[REDACTED]"
# Images are passed as base64 encoded data
}
}
]
},
{
"role": "assistant",
"content": "The image appears to be [REDACTED]"
},
],
"features": {
"image_generation": false,
"code_interpreter": false,
"web_search": false
},
"stream_options": {
"include_usage": true
},
"metadata": "[The exact same dict as __metadata__]",
"files": "[The exact same list as __files__]"
}


__user__

一个包含用户信息字典 (dict)

请注意,如果定义了UserValves类,则必须通过__user__["valves"]访问其实例。否则,valves键值将完全从__user__中缺失。

示例
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"email": "cheesy_dude@openwebui.com",
"name": "Patrick",
"role": "user",
# role can be either `user` or `admin`
"valves": "[the UserValve instance]"
}

__metadata__

一个包含关于聊天、模型、文件等广泛信息的字典 (dict)

示例
{
"user_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"chat_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"message_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"session_id": "xxxxxxxxxxxxxxxxxxxx",
"tool_ids": null,
# tool_ids is a list of str.
"tool_servers": [],
"files": "[Same as in body['files']]",
# If no files are given, the files key exists in __metadata__ and its value is []
"features": {
"image_generation": false,
"code_interpreter": false,
"web_search": false
},
"variables": {
"{{USER_NAME}}": "cheesy_username",
"{{USER_LOCATION}}": "Unknown",
"{{CURRENT_DATETIME}}": "2025-02-02 XX:XX:XX",
"{{CURRENT_DATE}}": "2025-02-02",
"{{CURRENT_TIME}}": "XX:XX:XX",
"{{CURRENT_WEEKDAY}}": "Monday",
"{{CURRENT_TIMEZONE}}": "Europe/Berlin",
"{{USER_LANGUAGE}}": "en-US"
},
"model": "[The exact same dict as __model__]",
"direct": false,
"function_calling": "native",
"type": "user_response",
"interface": "open-webui"
}

__model__

一个包含模型信息的字典 (dict)

示例
{
"id": "my-cool-model",
"name": "My Cool Model",
"object": "model",
"created": 1746000000,
"owned_by": "openai",
# either openai or ollama
"info": {
"id": "my-cool-model",
"user_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"base_model_id": "gpt-4o",
# this is the name of model that the model endpoint serves
"name": "My Cool Model",
"params": {
"system": "You are my best assistant. You answer [REDACTED]",
"function_calling": "native"
# custom options appear here, for example "Top K"
},
"meta": {
"profile_image_url": "/static/favicon.png",
"description": "Description of my-cool-model",
"capabilities": {
"vision": true,
"usage": true,
"citations": true
},
"position": 17,
"tags": [
{
"name": "for_friends"
},
{
"name": "vision_enabled"
}
],
"suggestion_prompts": null
},
"access_control": {
"read": {
"group_ids": [],
"user_ids": []
},
"write": {
"group_ids": [],
"user_ids": []
}
},
"is_active": true,
"updated_at": 1740000000,
"created_at": 1740000000
},
"preset": true,
"actions": [],
"tags": [
{
"name": "for_friends"
},
{
"name": "vision_enabled"
}
]
}

__messages__

一个包含先前消息的列表 (list)

请参阅上面body["messages"]的值。

__chat_id__

chat_id字符串 (str)表示。

请参阅上面__metadata__["chat_id"]的值。

__session_id__

session_id字符串 (str)表示。

请参阅上面__metadata__["session_id"]的值。

__message_id__

message_id字符串 (str)表示。

请参阅上面__metadata__["message_id"]的值。

__event_emitter__

一个用于向用户显示事件信息的可调用对象 (Callable)

__event_call__

一个用于动作 (Actions)可调用对象 (Callable)

__files__

通过聊天发送的文件列表 (list)。请注意,图像不被视为文件,而是作为body["messages"]列表的一部分直接发送到模型。

出于性能原因,文件的实际二进制内容不作为参数的一部分,但如有需要,文件仍可通过其路径访问。例如,使用docker时,路径的 Python 语法可以是

from pathlib import Path

the_file = Path(f"/app/backend/data/uploads/{__files__[0]["files"]["id"]}_{__files__[0]["files"]["filename"]}")
assert the_file.exists()

请注意,同一文件字典也可通过__metadata__["files"]访问(如果未发送文件,其值为[]),或通过body["files"]访问(但如果未发送文件,files键将完全从body中缺失)。

示例

[
{
"type": "file",
"file": {
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"filename": "Napoleon - Wikipedia.pdf",
"user_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"data": {
"content": "Napoleon - Wikipedia\n\n\nNapoleon I\n\nThe Emperor Napoleon in His Study at the\nTuileries, 1812\n\nEmperor of the French\n\n1st reign 18 May 1804 – 6 April 1814\n\nSuccessor Louis XVIII[a]\n\n2nd reign 20 March 1815 – 22 June 1815\n\nSuccessor Louis XVIII[a]\n\nFirst Consul of the French Republic\n\nIn office\n13 December 1799 – 18 May 1804\n\nBorn Napoleone Buonaparte\n15 August 1769\nAjaccio, Corsica, Kingdom of\nFrance\n\nDied 5 May 1821 (aged 51)\nLongwood, Saint Helena\n\nBurial 15 December 1840\nLes Invalides, Paris\n\nNapoleon\nNapoleon Bonaparte[b] (born Napoleone\nBuonaparte;[1][c] 15 August 1769 – 5 May 1821), later\nknown [REDACTED]",
# The content value is the output of the document parser, the above example is with Tika as a document parser
},
"meta": {
"name": "Napoleon - Wikipedia.pdf",
"content_type": "application/pdf",
"size": 10486578,
# in bytes, here about 10Mb
"data": {},
"collection_name": "file-96xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# always begins by 'file'
},
"created_at": 1740000000,
"updated_at": 1740000000
},
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"url": "/api/v1/files/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"name": "Napoleon - Wikipedia.pdf",
"collection_name": "file-96xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
"status": "uploaded",
"size": 10486578,
"error": "",
"itemId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# itemId is not the same as file["id"]
}
]


__request__

fastapi.Request的一个实例。您可以在迁移页面fastapi 的文档中了解更多信息。

__task__

表示任务类型的字符串 (str)。如果存在,其值只是__metadata__["task"]的简写;否则为None

可能的值

[
"title_generation",
"tags_generation",
"emoji_generation",
"query_generation",
"image_prompt_generation",
"autocomplete_generation",
"function_calling",
"moa_response_generation"
]

__task_body__

一个字典 (dict),包含完成给定__task__所需的body。如果存在,其值只是__metadata__["task_body"]的简写;否则为None

其结构与上面的body相同,但会根据需要进行修改,例如使用适当的模型和系统消息等。

__tools__

ToolUserModel实例的列表 (list)

有关ToolUserModel实例属性的详细信息,请参阅tools.py中的代码。