mirror of
https://github.com/open-webui/pipelines
synced 2025-05-12 08:30:43 +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
|
return pipeline.valves
|
||||||
|
|
||||||
|
|
||||||
@app.post("/v1/{pipeline_id}/filter")
|
@app.post("/v1/{pipeline_id}/filter/inlet")
|
||||||
@app.post("/{pipeline_id}/filter")
|
@app.post("/{pipeline_id}/filter/inlet")
|
||||||
async def filter(pipeline_id: str, form_data: FilterForm):
|
async def filter_inlet(pipeline_id: str, form_data: FilterForm):
|
||||||
if (
|
if (
|
||||||
pipeline_id not in app.state.PIPELINES
|
pipeline_id not in app.state.PIPELINES
|
||||||
or app.state.PIPELINES[pipeline_id].get("type", "pipe") != "filter"
|
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]
|
pipeline = PIPELINE_MODULES[pipeline_id]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
body = await pipeline.filter(form_data.body, form_data.user)
|
if hasattr(pipeline, "inlet"):
|
||||||
return body
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
@ -56,8 +56,9 @@ class Pipeline:
|
|||||||
# This function is called when the valves are updated.
|
# This function is called when the valves are updated.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def filter(self, body: dict, user: Optional[dict] = None) -> dict:
|
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||||
print(f"filter:{__name__}")
|
# This filter is applied to the form data before it is sent to the OpenAI API.
|
||||||
|
print(f"inlet:{__name__}")
|
||||||
|
|
||||||
print(body)
|
print(body)
|
||||||
user_message = body["messages"][-1]["content"]
|
user_message = body["messages"][-1]["content"]
|
||||||
|
@ -43,8 +43,9 @@ class Pipeline:
|
|||||||
print(f"on_shutdown:{__name__}")
|
print(f"on_shutdown:{__name__}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
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__}")
|
# This filter is applied to the form data before it is sent to the OpenAI API.
|
||||||
|
print(f"inlet:{__name__}")
|
||||||
|
|
||||||
print(body)
|
print(body)
|
||||||
print(user)
|
print(user)
|
||||||
|
@ -77,8 +77,8 @@ class Pipeline:
|
|||||||
)
|
)
|
||||||
self.langfuse.auth_check()
|
self.langfuse.auth_check()
|
||||||
|
|
||||||
async def filter(self, body: dict, user: Optional[dict] = None) -> dict:
|
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||||
print(f"filter:{__name__}")
|
print(f"inlet:{__name__}")
|
||||||
|
|
||||||
trace = self.langfuse.trace(
|
trace = self.langfuse.trace(
|
||||||
name=f"filter:{__name__}",
|
name=f"filter:{__name__}",
|
||||||
|
@ -103,7 +103,7 @@ class Pipeline:
|
|||||||
|
|
||||||
return False
|
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(f"pipe:{__name__}")
|
||||||
print(body)
|
print(body)
|
||||||
print(user)
|
print(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user