Skip to content

Commit

Permalink
feat: allow inlet, outlet for pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbck committed May 31, 2024
1 parent 8be45c7 commit ef79179
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
10 changes: 2 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
25 changes: 24 additions & 1 deletion pipelines/examples/example_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def __init__(self):
# 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):
Expand All @@ -23,6 +23,29 @@ async def on_shutdown(self):
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]:
Expand Down

0 comments on commit ef79179

Please sign in to comment.