feat: allow inlet, outlet for pipes

This commit is contained in:
Timothy J. Baek 2024-05-30 21:43:32 -07:00
parent 8be45c7949
commit ef79179c7f
2 changed files with 26 additions and 9 deletions

10
main.py
View File

@ -470,10 +470,7 @@ async def update_valves(pipeline_id: str, form_data: dict):
@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"
):
if pipeline_id not in app.state.PIPELINES:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Filter {pipeline_id} not found",
@ -498,10 +495,7 @@ async def filter_inlet(pipeline_id: str, form_data: FilterForm):
@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"
):
if pipeline_id not in app.state.PIPELINES:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Filter {pipeline_id} not found",

View File

@ -9,8 +9,8 @@ class Pipeline:
# The identifier must be unique across all pipelines.
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
self.id = "pipeline_example"
self.name = "Pipeline Example"
pass
async def on_startup(self):
@ -23,6 +23,29 @@ class Pipeline:
print(f"on_shutdown:{__name__}")
pass
async def on_valves_updated(self):
# This function is called when the valves are updated.
pass
async def inlet(self, body: dict, user: dict) -> dict:
# This function is called before the OpenAI API request is made. You can modify the form data before it is sent to the OpenAI API.
print(f"inlet:{__name__}")
print(body)
print(user)
return body
async def outlet(self, body: dict, user: dict) -> dict:
# This function is called after the OpenAI API response is completed. You can modify the messages after they are received from the OpenAI API.
print(f"outlet:{__name__}")
print(body)
print(user)
return body
def pipe(
self, user_message: str, model_id: str, messages: List[dict], body: dict
) -> Union[str, Generator, Iterator]: