"git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "9f0c9d973c7a3b7feb590e1febed35b3f7e4f3ea"
Commit f14ca483 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac

parent 96d7c3e9
...@@ -39,6 +39,7 @@ class Filter: ...@@ -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: ...@@ -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: ...@@ -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`;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment