本教程由社区贡献,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"]
访问其实例。否则,__user__
中完全没有 valves
键值对。
示例
{
"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()
请注意,同一个文件 dict 也可以通过 __metadata__["files"]
访问(如果未发送文件,其值为 []
),或者通过 body["files"]
访问(但如果未发送文件,则 body
中完全没有 files
键)。
示例
[
{
"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 中的代码。