open-webui / pipelines

Pipelines: Versatile, UI-Agnostic OpenAI-Compatible Plugin Framework
MIT License
1.01k stars 319 forks source link

Modifying body in langfuse_filter_pipeline Causes 400 Bad Request Errors in Open-WebUI #288

Open mcdorians opened 1 month ago

mcdorians commented 1 month ago

Issue Summary

When using the langfuse_filter_pipeline in Open-WebUI, modifying the part where the body dictionary gets extended with chat_id within the inlet or outlet methods causes a 400 Bad Request error from the downstream API (https://<openai_api_url>/chat/completions). As a result, non-streamed completions like tool requests fail and are ignored because the completions fails..

Steps to Reproduce

  1. Install and activate the langfuse_filter_pipeline.py in Open-WebUI.
  2. Use a tool that triggers a non-streamed completion (e.g., a tool request).
  3. Observe that a 400 Bad Request error occurs in the Open-WebUI logs.
  4. The tool does not function as expected due to this error.

Code Causing the Issue

The following code in langfuse_filter_pipeline.py appears to cause the error:

if "chat_id" not in body:
    unique_id = f"SYSTEM MESSAGE {uuid.uuid4()}"
    body["chat_id"] = unique_id
    print(f"chat_id was missing, set to: {unique_id}")

Even adding any arbitrary key to body every time, such as:

body["my_stupid_test"] = "bla" # in this case every completion request will lead to 400

leads to the same 400 Bad Request error.

Observed Behavior

Expected Behavior

Question

Logs

ERROR [open_webui.main] Error: 400: External: 400, message='Bad Request', url='https://<url>/chat/completions'

Additional Information

if not body.get("chat_id"):
      print("Skipping inlet processing because no chat_id.")
      return body

Request

Please investigate this issue. It seems that modifying the body in the langfuse_filter_pipeline causes downstream API requests to fail with a 400 Bad Request error.

cspengler-plexxis commented 1 month ago

This happens in a custom pipeline I've written as well. It would be super useful to be able to add keys to the body dict within the filter (in my case, I want to append context retrieved by the RAG process in the inlet, and then access that context in the outlet so I can log it in a database along with all the other details of the user-assistant exchange).