OpenAI and Anthropic Pipeline Not working #29

Closed
opened 2026-02-15 19:15:04 -05:00 by yindo · 5 comments
Owner

Originally created by @MarlNox on GitHub (Jun 2, 2024).

Both pipelines, in the latest iteration fail to work properly.
The issues in the OpenAI one, is that setting the key doesn't work using the current structure.
Trying to interact with the OpenAI pipeline gives a 400 error, related to the api key.

The OpenAI webui connection works just fine.

Originally created by @MarlNox on GitHub (Jun 2, 2024). Both pipelines, in the latest iteration fail to work properly. The issues in the OpenAI one, is that setting the key doesn't work using the current structure. Trying to interact with the OpenAI pipeline gives a 400 error, related to the api key. The OpenAI webui connection works just fine.
yindo closed this issue 2026-02-15 19:15:04 -05:00
Author
Owner

@MarlNox commented on GitHub (Jun 2, 2024):

Proposed fix:

from typing import List, Union, Generator, Iterator
from schemas import OpenAIChatMessage
import requests


class Pipeline:
    def __init__(self):
        self.name = "OpenAI Pipeline"
        self.OPENAI_API_KEY = "your-openai-api-key-here"
        self.MODEL = "gpt-3.5-turbo"

    async def on_startup(self):
        print(f"on_startup:{__name__}")
        pass

    async def on_shutdown(self):
        print(f"on_shutdown:{__name__}")
        pass

    def pipe(
        self, user_message: str, model_id: str, messages: List[OpenAIChatMessage], body: dict
    ) -> Union[str, Generator, Iterator]:
        print(f"pipe:{__name__}")

        print(messages)
        print(user_message)

        headers = {
            "Authorization": f"Bearer {self.OPENAI_API_KEY}",
            "Content-Type": "application/json"
        }

        payload = {
            "model": self.MODEL,
            "messages": messages
        }

        if 'stream' in body:
            payload['stream'] = body['stream']

        print(f"Using API Key: {self.OPENAI_API_KEY}")
        print(f"Request Payload: {payload}")

        try:
            r = requests.post(
                url="https://api.openai.com/v1/chat/completions",
                json=payload,
                headers=headers,
                stream=True,
            )

            r.raise_for_status()

            if payload.get("stream"):
                return r.iter_lines()
            else:
                return r.json()
        except requests.exceptions.RequestException as e:
            print(f"Request failed: {e}")
            return f"Error: {e}"


@MarlNox commented on GitHub (Jun 2, 2024): Proposed fix: ``` from typing import List, Union, Generator, Iterator from schemas import OpenAIChatMessage import requests class Pipeline: def __init__(self): self.name = "OpenAI Pipeline" self.OPENAI_API_KEY = "your-openai-api-key-here" self.MODEL = "gpt-3.5-turbo" async def on_startup(self): print(f"on_startup:{__name__}") pass async def on_shutdown(self): print(f"on_shutdown:{__name__}") pass def pipe( self, user_message: str, model_id: str, messages: List[OpenAIChatMessage], body: dict ) -> Union[str, Generator, Iterator]: print(f"pipe:{__name__}") print(messages) print(user_message) headers = { "Authorization": f"Bearer {self.OPENAI_API_KEY}", "Content-Type": "application/json" } payload = { "model": self.MODEL, "messages": messages } if 'stream' in body: payload['stream'] = body['stream'] print(f"Using API Key: {self.OPENAI_API_KEY}") print(f"Request Payload: {payload}") try: r = requests.post( url="https://api.openai.com/v1/chat/completions", json=payload, headers=headers, stream=True, ) r.raise_for_status() if payload.get("stream"): return r.iter_lines() else: return r.json() except requests.exceptions.RequestException as e: print(f"Request failed: {e}") return f"Error: {e}" ```
Author
Owner

@tjbck commented on GitHub (Jun 2, 2024):

Taking a look!

@tjbck commented on GitHub (Jun 2, 2024): Taking a look!
Author
Owner

@tjbck commented on GitHub (Jun 2, 2024):

Both should be fixed! Let me know if the issue persists!

@tjbck commented on GitHub (Jun 2, 2024): Both should be fixed! Let me know if the issue persists!
Author
Owner

@Lhemamou commented on GitHub (Jun 21, 2024):

The issue is persisting for OpenAI (I have only tested this one). I make a PR to fix it #107

@Lhemamou commented on GitHub (Jun 21, 2024): The issue is persisting for OpenAI (I have only tested this one). I make a PR to fix it #107
Author
Owner

@healdgar commented on GitHub (Jan 31, 2025):

Same issue. It's a 400 error, so it seems like a malformed request? Maybe the message body isn't parsing correctly?

console shows:
"### Context:
<chat_history>
USER: test
ASSISTANT: Error: 400 Client Error: Bad Request for url: https://api.openai.com/v1/chat/completions
</chat_history>
search query
test

Output:

INFO: 127.0.0.1:53222 - "POST /chat/completions HTTP/1.1" 200 OK
openai_pipeline
openai_pipeline
INFO: 127.0.0.1:53226 - "POST /chat/completions HTTP/1.1" 200 OK
pipe:openai_pipeline
[{'role': 'user', 'content': 'test'}, {'role': 'assistant', 'content': 'Error: 400 Client Error: Bad Request for url: https://api.openai.com/v1/chat/completions'}, {'role': 'user', 'content': 'test'}]
test
INFO: 127.0.0.1:53230 - "POST /openai_pipeline/filter/outlet HTTP/1.1" 200 OK"

@healdgar commented on GitHub (Jan 31, 2025): Same issue. It's a 400 error, so it seems like a malformed request? Maybe the message body isn't parsing correctly? console shows: "### Context: <chat_history> USER: test ASSISTANT: Error: 400 Client Error: Bad Request for url: https://api.openai.com/v1/chat/completions </chat_history> <type>search query</type> <text>test</text> #### Output: INFO: 127.0.0.1:53222 - "POST /chat/completions HTTP/1.1" 200 OK openai_pipeline openai_pipeline INFO: 127.0.0.1:53226 - "POST /chat/completions HTTP/1.1" 200 OK pipe:openai_pipeline [{'role': 'user', 'content': 'test'}, {'role': 'assistant', 'content': 'Error: 400 Client Error: Bad Request for url: https://api.openai.com/v1/chat/completions'}, {'role': 'user', 'content': 'test'}] test INFO: 127.0.0.1:53230 - "POST /openai_pipeline/filter/outlet HTTP/1.1" 200 OK"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-webui/pipelines#29