mirror of
https://github.com/open-webui/open-webui
synced 2025-01-30 22:39:03 +00:00
refac
This commit is contained in:
parent
96d7c3e99f
commit
f14ca48334
@ -39,6 +39,7 @@ class Filter:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Indicates custom file handling logic. This flag helps disengage default routines in favor of custom
|
# Indicates custom file handling logic. This flag helps disengage default routines in favor of custom
|
||||||
# implementations, informing the WebUI to defer file-related operations to designated methods within this class.
|
# implementations, informing the WebUI to defer file-related operations to designated methods within this class.
|
||||||
|
# Alternatively, you can remove the files directly from the body in from the inlet hook
|
||||||
self.file_handler = True
|
self.file_handler = True
|
||||||
|
|
||||||
# Initialize 'valves' with specific configurations. Using 'Valves' instance helps encapsulate settings,
|
# Initialize 'valves' with specific configurations. Using 'Valves' instance helps encapsulate settings,
|
||||||
@ -50,16 +51,15 @@ class Filter:
|
|||||||
# Modify the request body or validate it before processing by the chat completion API.
|
# Modify the request body or validate it before processing by the chat completion API.
|
||||||
# This function is the pre-processor for the API where various checks on the input can be performed.
|
# This function is the pre-processor for the API where various checks on the input can be performed.
|
||||||
# It can also modify the request before sending it to the API.
|
# It can also modify the request before sending it to the API.
|
||||||
|
print(f"inlet:{__name__}")
|
||||||
|
print(f"inlet:body:{body}")
|
||||||
|
print(f"inlet:user:{user}")
|
||||||
|
|
||||||
print("inlet")
|
if user.get("role", "admin") in ["user", "admin"]:
|
||||||
print(body)
|
|
||||||
print(user)
|
|
||||||
|
|
||||||
if user.get("role", "admin") in ["user"]:
|
|
||||||
messages = body.get("messages", [])
|
messages = body.get("messages", [])
|
||||||
if len(messages) > self.max_turns:
|
if len(messages) > self.valves.max_turns:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Conversation turn limit exceeded. Max turns: {self.max_turns}"
|
f"Conversation turn limit exceeded. Max turns: {self.valves.max_turns}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return body
|
return body
|
||||||
@ -68,9 +68,9 @@ class Filter:
|
|||||||
# Modify or analyze the response body after processing by the API.
|
# Modify or analyze the response body after processing by the API.
|
||||||
# This function is the post-processor for the API, which can be used to modify the response
|
# This function is the post-processor for the API, which can be used to modify the response
|
||||||
# or perform additional checks and analytics.
|
# or perform additional checks and analytics.
|
||||||
print(f"outlet")
|
print(f"outlet:{__name__}")
|
||||||
print(body)
|
print(f"outlet:body:{body}")
|
||||||
print(user)
|
print(f"outlet:user:{user}")
|
||||||
|
|
||||||
return body`;
|
return body`;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user