mirror of
https://github.com/open-webui/pipelines
synced 2025-05-11 08:01:08 +00:00
refac: filter -> inlet
This commit is contained in:
parent
0b43a73996
commit
f677bb9d0c
41
main.py
41
main.py
@ -463,9 +463,9 @@ async def update_valves(pipeline_id: str, form_data: dict):
|
||||
return pipeline.valves
|
||||
|
||||
|
||||
@app.post("/v1/{pipeline_id}/filter")
|
||||
@app.post("/{pipeline_id}/filter")
|
||||
async def filter(pipeline_id: str, form_data: FilterForm):
|
||||
@app.post("/v1/{pipeline_id}/filter/inlet")
|
||||
@app.post("/{pipeline_id}/filter/inlet")
|
||||
async def filter_inlet(pipeline_id: str, form_data: FilterForm):
|
||||
if (
|
||||
pipeline_id not in app.state.PIPELINES
|
||||
or app.state.PIPELINES[pipeline_id].get("type", "pipe") != "filter"
|
||||
@ -478,8 +478,39 @@ async def filter(pipeline_id: str, form_data: FilterForm):
|
||||
pipeline = PIPELINE_MODULES[pipeline_id]
|
||||
|
||||
try:
|
||||
body = await pipeline.filter(form_data.body, form_data.user)
|
||||
return body
|
||||
if hasattr(pipeline, "inlet"):
|
||||
body = await pipeline.inlet(form_data.body, form_data.user)
|
||||
return body
|
||||
else:
|
||||
return form_data.body
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"{str(e)}",
|
||||
)
|
||||
|
||||
|
||||
@app.post("/v1/{pipeline_id}/filter/outlet")
|
||||
@app.post("/{pipeline_id}/filter/outlet")
|
||||
async def filter_outlet(pipeline_id: str, form_data: FilterForm):
|
||||
if (
|
||||
pipeline_id not in app.state.PIPELINES
|
||||
or app.state.PIPELINES[pipeline_id].get("type", "pipe") != "filter"
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Filter {pipeline_id} not found",
|
||||
)
|
||||
|
||||
pipeline = PIPELINE_MODULES[pipeline_id]
|
||||
|
||||
try:
|
||||
if hasattr(pipeline, "outlet"):
|
||||
body = await pipeline.outlet(form_data.body, form_data.user)
|
||||
return body
|
||||
else:
|
||||
return form_data.body
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise HTTPException(
|
||||
|
@ -56,8 +56,9 @@ class Pipeline:
|
||||
# This function is called when the valves are updated.
|
||||
pass
|
||||
|
||||
async def filter(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
print(f"filter:{__name__}")
|
||||
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
# This filter is applied to the form data before it is sent to the OpenAI API.
|
||||
print(f"inlet:{__name__}")
|
||||
|
||||
print(body)
|
||||
user_message = body["messages"][-1]["content"]
|
||||
|
@ -43,8 +43,9 @@ class Pipeline:
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
async def filter(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
print(f"pipe:{__name__}")
|
||||
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
# This filter is applied to the form data before it is sent to the OpenAI API.
|
||||
print(f"inlet:{__name__}")
|
||||
|
||||
print(body)
|
||||
print(user)
|
||||
|
@ -77,8 +77,8 @@ class Pipeline:
|
||||
)
|
||||
self.langfuse.auth_check()
|
||||
|
||||
async def filter(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
print(f"filter:{__name__}")
|
||||
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
print(f"inlet:{__name__}")
|
||||
|
||||
trace = self.langfuse.trace(
|
||||
name=f"filter:{__name__}",
|
||||
|
@ -103,7 +103,7 @@ class Pipeline:
|
||||
|
||||
return False
|
||||
|
||||
async def filter(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
print(f"pipe:{__name__}")
|
||||
print(body)
|
||||
print(user)
|
||||
|
Loading…
Reference in New Issue
Block a user