Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with anthropic_manifold_pipeline #166

Open
4 tasks done
dannykorpan opened this issue Jul 19, 2024 · 43 comments
Open
4 tasks done

Error with anthropic_manifold_pipeline #166

dannykorpan opened this issue Jul 19, 2024 · 43 comments

Comments

@dannykorpan
Copy link

Bug Report

Description

Bug Summary:
When using Claude 3.5 via anthropic_manifold_pipeline.py from https://github.com/open-webui/pipelines/blob/main/examples/pipelines/providers/anthropic_manifold_pipeline.py, I get the following error after a while. The API Key is correct.
grafik

Steps to Reproduce:
I deployed Pipelines via docker and set up the API Key via the admin interface.
grafik

After using Claude 3.5 the pipelines container prints the following error after 2-3 uses.

INFO:     192.168.0.4:59372 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:57282 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:36000 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
anthropic.claude-3-5-sonnet-20240620
anthropic.claude-3-5-sonnet-20240620
INFO:     192.168.0.4:36014 - "POST /chat/completions HTTP/1.1" 200 OK
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
    yield await anyio.to_thread.run_sync(_next, as_iterator)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
    return next(iterator)
           ^^^^^^^^^^^^^^
  File "/app/main.py", line 665, in stream_content
    for line in res:
  File "/app/./pipelines/anthropic_manifold_pipeline.py", line 141, in stream_response
    stream = self.client.messages.create(**payload)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/resources/messages.py", line 904, in create
    return self._post(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1266, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 942, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1046, in _request
    raise self._make_status_error_from_response(err.response) from None
anthropic.AuthenticationError: Error code: 401 - {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'invalid x-api-key'}}

Environment

  • Open WebUI Version: [e.g., 0.1.120]
    v0.3.10

  • Operating System: [e.g., Windows 10, macOS Big Sur, Ubuntu 20.04]
    Server: Latest Docker, x64
    Client: Latest macOS Sonoma, ARM64

  • Browser (if applicable): [e.g., Chrome 100.0, Firefox 98.0]
    Latest Firefox, ARM64

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
@dannykorpan dannykorpan changed the title Error with Error with anthropic_manifold_pipeline Jul 19, 2024
@tjbck tjbck transferred this issue from open-webui/open-webui Jul 19, 2024
@eddienubes
Copy link

We often experience the same thing.

@justinh-rahb
Copy link
Collaborator

I'll have a look when I've got time, but I've been mostly using my Anthropic Function nowadays. I haven't noticed this issue in that, but then it's just using requests and not using the anthropic library actually, so there could be differences there.

@dannykorpan
Copy link
Author

Any solution yet? Today I have the same problem.

RESET_PIPELINES_DIR is not set to true. No action taken.
PIPELINES_REQUIREMENTS_PATH not specified. Skipping installation of requirements.
PIPELINES_URLS not specified. Skipping pipelines download and installation.
INFO:     Started server process [7]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:9099 (Press CTRL+C to quit)
Loaded module: anthropic_manifold_pipeline
Loaded module: openai_dalle_manifold_pipeline
on_startup:anthropic_manifold_pipeline
on_startup:openai_dalle_manifold_pipeline
INFO:     192.168.0.4:52276 - "GET /models HTTP/1.1" 200 OK
RESET_PIPELINES_DIR is not set to true. No action taken.
PIPELINES_REQUIREMENTS_PATH not specified. Skipping installation of requirements.
PIPELINES_URLS not specified. Skipping pipelines download and installation.
INFO:     Started server process [7]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:9099 (Press CTRL+C to quit)
Loaded module: anthropic_manifold_pipeline
Loaded module: openai_dalle_manifold_pipeline
on_startup:anthropic_manifold_pipeline
on_startup:openai_dalle_manifold_pipeline
INFO:     192.168.0.4:59008 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:60898 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:60940 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:51132 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
anthropic.claude-3-5-sonnet-20240620
anthropic.claude-3-5-sonnet-20240620
INFO:     192.168.0.4:51134 - "POST /chat/completions HTTP/1.1" 200 OK
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
    yield await anyio.to_thread.run_sync(_next, as_iterator)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
    return next(iterator)
           ^^^^^^^^^^^^^^
  File "/app/main.py", line 665, in stream_content
    for line in res:
  File "/app/./pipelines/anthropic_manifold_pipeline.py", line 141, in stream_response
    stream = self.client.messages.create(**payload)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/resources/messages.py", line 904, in create
    return self._post(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1266, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 942, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1046, in _request
    raise self._make_status_error_from_response(err.response) from None
anthropic.AuthenticationError: Error code: 401 - {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'invalid x-api-key'}}
INFO:     192.168.0.4:52738 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
anthropic.claude-3-5-sonnet-20240620
anthropic.claude-3-5-sonnet-20240620
INFO:     192.168.0.4:52740 - "POST /chat/completions HTTP/1.1" 200 OK
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
    yield await anyio.to_thread.run_sync(_next, as_iterator)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
    return next(iterator)
           ^^^^^^^^^^^^^^
  File "/app/main.py", line 665, in stream_content
    for line in res:
  File "/app/./pipelines/anthropic_manifold_pipeline.py", line 141, in stream_response
    stream = self.client.messages.create(**payload)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/resources/messages.py", line 904, in create
    return self._post(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1266, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 942, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1046, in _request
    raise self._make_status_error_from_response(err.response) from None
anthropic.AuthenticationError: Error code: 401 - {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'invalid x-api-key'}}

@justinh-rahb
Copy link
Collaborator

401 Authentication error. Have you checked your keys work if you do a request manually with cURL?

@dannykorpan
Copy link
Author

The API Key is correct.

See my initial post.

@justinh-rahb
Copy link
Collaborator

Your logs are either at odds with the reality, or your key is bad. You didn't answer the question of whether you've tried that key with anything else. You're certain your account is in good-standing, and adequately funded ($5 minimum balance required IIRC)?

If I deliberately set an incorrect key I get this error, same as you:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
    yield await anyio.to_thread.run_sync(_next, as_iterator)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
    return next(iterator)
           ^^^^^^^^^^^^^^
  File "/app/main.py", line 665, in stream_content
    for line in res:
  File "/app/./pipelines/anthropic_manifold_pipeline.py", line 141, in stream_response
    stream = self.client.messages.create(**payload)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/resources/messages.py", line 904, in create
    return self._post(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1266, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 942, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1046, in _request
    raise self._make_status_error_from_response(err.response) from None
anthropic.AuthenticationError: Error code: 401 - {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'invalid x-api-key'}}

@dannykorpan
Copy link
Author

Your logs are either at odds with the reality, or your key is bad. You didn't answer the question of whether you've tried that key with anything else. You're certain your account is in good-standing, and adequately funded ($5 minimum balance required IIRC)?

25$ Balance

Here is the cURL Example with output

curl https://api.anthropic.com/v1/messages --header "x-api-key: MYAPIKEY" --header "anthropic-version: 2023-06-01" --header "content-type: application/json" --data '{"model": "claude-3-5-sonnet-20240620", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello, world"}]}'
{"id":"msg_018VV4ca8WAiR8iTgSfMcx3d","type":"message","role":"assistant","model":"claude-3-5-sonnet-20240620","content":[{"type":"text","text":"Hello! How can I assist you today? Is there anything specific you'd like to talk about or any questions you have?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":28}}

@justinh-rahb
Copy link
Collaborator

Well, I'm truly at a loss then, I've been unable to reproduce this by any easy means, and I don't wish to push the issue too much further for fear of affecting my own access to their API.

@dannykorpan
Copy link
Author

If I create a second API key and use it, it works. The first API key, however, functions flawlessly via cURL.

@justinh-rahb
Copy link
Collaborator

Strange... is it possible they're using a weird character in your first key that isn't being escaped properly?

@dannykorpan
Copy link
Author

Sometimes it's working with the key and after some time the same key won't work anymore.

@realies
Copy link

realies commented Jul 26, 2024

I occasionally see the same issue with a working key. Seems reproducible when I restart the pipelines container. If I go into Open WebUI/Pipelines and select the anthropic_manifold_pipeline (manifold), the saved API key loads up. After pressing save without changing anything, it starts working as it should. The mounted appdata folder has the correct file/folder permissions and ownership.

PS: I have to do the same steps for openai_manifold_pipeline (manifold) for OpenAI models to load up and be usable.

@justinh-rahb
Copy link
Collaborator

Now there's a clue I can work on. Thanks @realies, I'll see if this new information uncovers anything.

@Digit404
Copy link

Digit404 commented Jul 26, 2024

I am also experiencing this same error. With curl, the key works fine before I use it with Pipelines, but after I use it in Open WebUI, like a banshee, the key is marked for death (figuratively speaking) and will unceremoniously expire in <24 hours. After this, not even curl can revive the key. I have made dozens of new keys trying to get around this issue and I have not been banned from the API or anything, but my keys are dropping like flies.

This is the error that happens after a key has been cursed:

{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "invalid x-api-key"
  }
}

@justinh-rahb
Copy link
Collaborator

If you're paying customers, have any of you tried contacting Anthropic's support to inquire as to the reason your keys are being revoked?

@Digit404
Copy link

I have, and Anthropic took the entirety of the month to respond (Thanks, Claude 3.5). Today, they're asking for what the header sent from the app looks like and I don't really know how to find that out.

@justinh-rahb
Copy link
Collaborator

Thanks for the additional datapoint @Digit404. I've no intention of closing this until I figure out what the heck is going on 😅

@sriparashiva
Copy link

sriparashiva commented Jul 27, 2024

While this issue is being looked at, anyone who wants to temporarily bypass this problem can use the following working anthropic pipeline which uses the HTTP API directly and is currently working without any errors (no invalid x-api-key error):

"""
title: Anthropic Manifold HTTP Pipeline
author: sriparashiva
date: 2024-07-27
version: 1.0
license: MIT
description: A pipeline for generating text and processing images using the Anthropic HTTP API.
requirements: requests, sseclient-py
environment_variables: ANTHROPIC_API_KEY
"""

import os

from typing import List, Union, Generator, Iterator
from pydantic import BaseModel
import requests

from utils.pipelines.main import pop_system_message

import requests
import sseclient
from typing import Generator
import json

class Pipeline:
    class Valves(BaseModel):
        ANTHROPIC_API_KEY: str = ""

    def __init__(self):
        self.type = "manifold"
        self.id = "anthropic"
        self.name = "anthropic/"

        self.valves = self.Valves(
            **{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY", "your-api-key-here")}
        )
        self.api_key = self.valves.ANTHROPIC_API_KEY
        self.url = 'https://api.anthropic.com/v1/messages'
        self.headers = {
            'anthropic-version': '2023-06-01',
            'content-type': 'application/json',
            'x-api-key': self.api_key
        }

    def get_anthropic_models(self):
        return [
            {"id": "claude-3-haiku-20240307", "name": "claude-3-haiku"},
            {"id": "claude-3-opus-20240229", "name": "claude-3-opus"},
            {"id": "claude-3-sonnet-20240229", "name": "claude-3-sonnet"},
            {"id": "claude-3-5-sonnet-20240620", "name": "claude-3.5-sonnet"},
        ]

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

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

    async def on_valves_updated(self):
        self.api_key = self.valves.ANTHROPIC_API_KEY
        self.headers = {
                    'anthropic-version': '2023-06-01',
                    'content-type': 'application/json',
                    'x-api-key': self.api_key
                }
        pass

    def pipelines(self) -> List[dict]:
        return self.get_anthropic_models()

    def process_image(self, image_data):
        if image_data["url"].startswith("data:image"):
            mime_type, base64_data = image_data["url"].split(",", 1)
            media_type = mime_type.split(":")[1].split(";")[0]
            return {
                "type": "image",
                "source": {
                    "type": "base64",
                    "media_type": media_type,
                    "data": base64_data,
                },
            }
        else:
            return {
                "type": "image",
                "source": {"type": "url", "url": image_data["url"]},
            }

    def pipe(
        self, user_message: str, model_id: str, messages: List[dict], body: dict
    ) -> Union[str, Generator, Iterator]:
        try:
            # Remove unnecessary keys
            for key in ['user', 'chat_id', 'title']:
                body.pop(key, None)

            system_message, messages = pop_system_message(messages)

            processed_messages = []
            image_count = 0
            total_image_size = 0

            for message in messages:
                processed_content = []
                if isinstance(message.get("content"), list):
                    for item in message["content"]:
                        if item["type"] == "text":
                            processed_content.append({"type": "text", "text": item["text"]})
                        elif item["type"] == "image_url":
                            if image_count >= 5:
                                raise ValueError("Maximum of 5 images per API call exceeded")

                            processed_image = self.process_image(item["image_url"])
                            processed_content.append(processed_image)

                            if processed_image["source"]["type"] == "base64":
                                image_size = len(processed_image["source"]["data"]) * 3 / 4
                            else:
                                image_size = 0

                            total_image_size += image_size
                            if total_image_size > 100 * 1024 * 1024:
                                raise ValueError("Total size of images exceeds 100 MB limit")

                            image_count += 1
                else:
                    processed_content = [{"type": "text", "text": message.get("content", "")}]

                processed_messages.append({"role": message["role"], "content": processed_content})

            # Prepare the payload
            payload = {
                "model": model_id,
                "messages": processed_messages,
                "max_tokens": body.get("max_tokens", 4096),
                "temperature": body.get("temperature", 0.8),
                "top_k": body.get("top_k", 40),
                "top_p": body.get("top_p", 0.9),
                "stop_sequences": body.get("stop", []),
                **({"system": str(system_message)} if system_message else {}),
                "stream": body.get("stream", False),
            }

            if body.get("stream", False):
                return self.stream_response(model_id, payload)
            else:
                return self.get_completion(model_id, payload)
        except Exception as e:
            return f"Error: {e}"

    def stream_response(self, model_id: str, payload: dict) -> Generator:
        response = requests.post(self.url, headers=self.headers, json=payload, stream=True)

        if response.status_code == 200:
            client = sseclient.SSEClient(response)
            for event in client.events():
                event_data = event.data
                try:
                    event_json = json.loads(event_data)
                    if event_json['type'] == "content_block_start":
                        yield event_json['content_block']['text']
                    elif event_json['type'] == "content_block_delta":
                        yield event_json['delta']['text']
                except ValueError:
                    # Handle any JSON decoding errors if necessary
                    print(f"Unable to decode JSON: {event_data}")
                    raise ValueError
        else:
            raise Exception(f"Error: {response.status_code} - {response.text}")

    def get_completion(self, model_id: str, payload: dict) -> str:
        response = requests.post(self.url, headers=self.headers, json=payload)
        if response.status_code == 200:
            response_json = response.json()
            # Assuming we're interested in the first text content block.
            return response_json['content'][0]['text']
        else:
            raise Exception(f"Error: {response.status_code} - {response.text}")

@justinh-rahb
Copy link
Collaborator

@sriparashiva ironically that's exactly what I was planning to do to "resolve" this if I had to, since using requests has been working just fine on my Function version of this: https://openwebui.com/f/justinrahb/anthropic

@dannykorpan
Copy link
Author

dannykorpan commented Jul 29, 2024

While this issue is being looked at, anyone who wants to temporarily bypass this problem can use the following working anthropic pipeline which uses the HTTP API directly and is currently working without any errors (no invalid x-api-key error.

Hi, thank you. I have downloaded your script and uploaded it through the OpenWebUI interface. Afterwards, the file is immediately moved to the "failed" subfolder within the pipeline folder. In the pipeline docker Logs, I see the following:

WARNING:root:No Pipeline class found in Anthropic
Error loading module: Anthropic
No module named 'sseclient'

@sriparashiva
Copy link

@dannykorpan Since the pipeline has an additional dependency sseclient, you need to install it manually on the pipelines python environment. This currently needs to be done manually (I couldn't find any existing documentation showing how to have the dependencies of a custom pipeline auto-installed).

I am using a Docker setup for pipelines, so I just executed the command pip3 install sseclient-py inside the pipelines docker container. That should make it work.

Or alternatively, you can use the code snippet from @justinh-rahb's linked custom function which does not use any external dependencies.

@dannykorpan
Copy link
Author

@dannykorpan Since the pipeline has an additional dependency sseclient, you need to install it manually on the pipelines python environment. This currently needs to be done manually (I couldn't find any existing documentation showing how to have the dependencies of a custom pipeline auto-installed).

I am using a Docker setup for pipelines, so I just executed the command pip3 install sseclient-py inside the pipelines docker container. That should make it work.

Or alternatively, you can use the code snippet from @justinh-rahb's linked custom function which does not use any external dependencies.

Your workaround works :-) Thank you!

@justinh-rahb
Copy link
Collaborator

justinh-rahb commented Jul 30, 2024

@dannykorpan @Digit404 @sriparashiva please give this PR a try:

If you install it by putting the raw URL into your PIPELINES_URLS environment variable, the server will pull it and install dependency sseclient-py automatically on startup:

https://raw.githubusercontent.com/justinh-rahb/open-webui-pipelines/anthropic-fix/examples/pipelines/providers/anthropic_manifold_pipeline.py

@dannykorpan
Copy link
Author

Thank you, but still get the following error after importing into pipelines:

WARNING:root:No Pipeline class found in anthropic_manifold_pipeline
https://raw.githubusercontent.com/justinh-rahb/open-webui-pipelines/anthropic-fix/examples/pipelines/providers/anthropic_manifold_pipeline.py
Error loading module: anthropic_manifold_pipeline
No module named 'sseclient'

@justinh-rahb
Copy link
Collaborator

justinh-rahb commented Jul 30, 2024

Thank you, but still get the following error after importing into pipelines:

WARNING:root:No Pipeline class found in anthropic_manifold_pipeline
https://raw.githubusercontent.com/justinh-rahb/open-webui-pipelines/anthropic-fix/examples/pipelines/providers/anthropic_manifold_pipeline.py
Error loading module: anthropic_manifold_pipeline
No module named 'sseclient'

@dannykorpan as noted, the dependency only installs on server startup if it is already in the pipelines/ dir or you've added the URL to PIPELINES_URLS, if you attempt to upload the pipeline from Admin Settings > Pipelines, you'll get such an error.

Screenshot 2024-07-30 at 1 26 10 PM

@dannykorpan
Copy link
Author

Thank you, but I think it represents a potential source of error.

If I restart the server, the sseclient module still won't be installed automatically. I always have to install it manually, even after a restart. Or am I misunderstanding something?

@justinh-rahb
Copy link
Collaborator

You are misunderstanding something, yes. The frontmatter at the top of the file specifies what depends it uses:

requirements: requests, sseclient-py

When the server is started (or restarted) with start.sh, it loops through all of the installed pipelines and will pip install their requirements:

pipelines/start.sh

Lines 85 to 105 in cd6c092

install_frontmatter_requirements() {
local file=$1
local file_content=$(cat "$1")
# Extract the first triple-quoted block
local first_block=$(echo "$file_content" | awk '/"""/{flag=!flag; if(flag) count++; if(count == 2) {exit}} flag' )
# Check if the block contains requirements
local requirements=$(echo "$first_block" | grep -i 'requirements:')
if [ -n "$requirements" ]; then
# Extract the requirements list
requirements=$(echo "$requirements" | awk -F': ' '{print $2}' | tr ',' ' ' | tr -d '\r')
# Construct and echo the pip install command
local pip_command="pip install $requirements"
echo "$pip_command"
pip install $requirements
else
echo "No requirements found in frontmatter of $file."
fi
}

@dannykorpan
Copy link
Author

But I start the pipelines server via docker.

@justinh-rahb
Copy link
Collaborator

justinh-rahb commented Jul 30, 2024

But I start the pipelines server via docker.

Two options:

Bind mount the pipelines volume:

docker run -d \
  -p 9099:9099 \
  --add-host=host.docker.internal:host-gateway \
  -v /home/your-username/pipelines:/app/pipelines \
  --name pipelines \
  --restart always \
  ghcr.io/open-webui/pipelines:main

You can then drop the anthropic_manifold_pipeline.py file in the pipelines dir, restart the container, and it should install.

Alternatively, use the PIPELINES_URLS environment variable:

docker run -d \
  -p 9099:9099 \
  --add-host=host.docker.internal:host-gateway \
  -v pipelines:/app/pipelines \
  -e PIPELINES_URLS="github_raw_urls;separated_by_semicolons"
  --name pipelines \
  --restart always \
  ghcr.io/open-webui/pipelines:main

This should install the depends immediately after downloading the pipeline when the container starts.

@dannykorpan
Copy link
Author

Works, thank you!

@Digit404
Copy link

After installing the new pipeline, it's been a while and my key still works. Thanks for the fix!

@realies
Copy link

realies commented Aug 3, 2024

@justinh-rahb, for some reason I still have to re-submit API keys for each pipeline for the service to continue to work after a restart; this is the compose file:

$ cat docker-compose.yml
services:
  pipelines:
    image: ghcr.io/open-webui/pipelines:main
    container_name: pipelines
    volumes:
      - ./data:/app/pipelines
    environment:
      - PIPELINES_URLS=https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/anthropic_manifold_pipeline.py;https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/openai_manifold_pipeline.py;https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/ollama_manifold_pipeline.py
    restart: unless-stopped

here's a log of starting the container, trying to use anthropic and failing to do so because

pipelines  | Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}

going to the settings page for anthropic_manifold_pipeline and pressing save can be seen to fix it further down the logs

any idea why this is happening?

realies@rpi-1:~/compose/pipelines $ docker compose up -d && docker compose logs -f
[+] Running 1/1
 ✔ Container pipelines  Started                                                                                                                                                                  0.4s
pipelines  | RESET_PIPELINES_DIR is not set to true. No action taken.
pipelines  | PIPELINES_REQUIREMENTS_PATH not specified. Skipping installation of requirements.
pipelines  | Downloading pipeline files from https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/anthropic_manifold_pipeline.py to ./pipelines...
pipelines  |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
pipelines  |                                  Dload  Upload   Total   Spent    Left  Speed
100  6523  100  6523    0     0  36722      0 --:--:-- --:--:-- --:--:-- 36853
pipelines  | Downloading pipeline files from https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/openai_manifold_pipeline.py to ./pipelines...
pipelines  |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
pipelines  |                                  Dload  Upload   Total   Spent    Left  Speed
100  3917  100  3917    0     0  36027      0 --:--:-- --:--:-- --:--:-- 36268
pipelines  | Downloading pipeline files from https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/ollama_manifold_pipeline.py to ./pipelines...
pipelines  |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
pipelines  |                                  Dload  Upload   Total   Spent    Left  Speed
100  3488  100  3488    0     0  28807      0 --:--:-- --:--:-- --:--:-- 29066
pipelines  | pip install requests  sseclient-py
pipelines  | Requirement already satisfied: requests in /usr/local/lib/python3.11/site-packages (2.32.2)
pipelines  | Collecting sseclient-py
pipelines  |   Downloading sseclient_py-1.8.0-py2.py3-none-any.whl.metadata (2.0 kB)
pipelines  | Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/site-packages (from requests) (3.3.2)
pipelines  | Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/site-packages (from requests) (3.7)
pipelines  | Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/site-packages (from requests) (2.2.2)
pipelines  | Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/site-packages (from requests) (2024.7.4)
pipelines  | Downloading sseclient_py-1.8.0-py2.py3-none-any.whl (8.8 kB)
pipelines  | Installing collected packages: sseclient-py
pipelines  | Successfully installed sseclient-py-1.8.0
pipelines  | WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
pipelines  |
pipelines  | [notice] A new release of pip is available: 24.0 -> 24.2
pipelines  | [notice] To update, run: pip install --upgrade pip
pipelines  | No requirements found in frontmatter of ./pipelines/ollama_manifold_pipeline.py.
pipelines  | No requirements found in frontmatter of ./pipelines/openai_manifold_pipeline.py.
pipelines  | INFO:     Started server process [55]
pipelines  | INFO:     Waiting for application startup.
pipelines  | INFO:     Application startup complete.
pipelines  | INFO:     Uvicorn running on http://0.0.0.0:9099 (Press CTRL+C to quit)
pipelines  | Loaded module: anthropic_manifold_pipeline
pipelines  | Loaded module: openai_manifold_pipeline
pipelines  | Error: 'data'
pipelines  | Loaded module: ollama_manifold_pipeline
pipelines  | on_startup:anthropic_manifold_pipeline
pipelines  | on_startup:openai_manifold_pipeline
pipelines  | on_startup:ollama_manifold_pipeline
pipelines  | INFO:     172.18.0.9:38112 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:55694 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | INFO:     172.18.0.9:55706 - "POST /chat/completions HTTP/1.1" 200 OK
pipelines  | ERROR:    Exception in ASGI application
pipelines  |   + Exception Group Traceback (most recent call last):
pipelines  |   |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 192, in __call__
pipelines  |   |     await response(scope, wrapped_receive, send)
pipelines  |   |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
pipelines  |   |     async with anyio.create_task_group() as task_group:
pipelines  |   |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
pipelines  |   |     raise BaseExceptionGroup(
pipelines  |   | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
pipelines  |   +-+---------------- 1 ----------------
pipelines  |     | Exception Group Traceback (most recent call last):
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |     |     await func()
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
pipelines  |     |     return await super().stream_response(send)
pipelines  |     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
pipelines  |     |     async for chunk in self.body_iterator:
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
pipelines  |     |     raise app_exc
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
pipelines  |     |     await self.app(scope, receive_or_disconnect, send_no_error)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
pipelines  |     |     await self.app(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
pipelines  |     |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
pipelines  |     |     raise exc
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
pipelines  |     |     await app(scope, receive, sender)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
pipelines  |     |     await self.middleware_stack(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
pipelines  |     |     await route.handle(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
pipelines  |     |     await self.app(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
pipelines  |     |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
pipelines  |     |     raise exc
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
pipelines  |     |     await app(scope, receive, sender)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 75, in app
pipelines  |     |     await response(scope, receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
pipelines  |     |     async with anyio.create_task_group() as task_group:
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
pipelines  |     |     raise BaseExceptionGroup(
pipelines  |     | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
pipelines  |     +-+---------------- 1 ----------------
pipelines  |       | Traceback (most recent call last):
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
pipelines  |       |     result = await app(  # type: ignore[func-returns-value]
pipelines  |       |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
pipelines  |       |     return await self.app(scope, receive, send)
pipelines  |       |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
pipelines  |       |     await super().__call__(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
pipelines  |       |     await self.middleware_stack(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
pipelines  |       |     raise exc
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
pipelines  |       |     await self.app(scope, receive, _send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
pipelines  |       |     with collapse_excgroups():
pipelines  |       |   File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
pipelines  |       |     self.gen.throw(typ, value, traceback)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
pipelines  |       |     raise exc
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |       |     await func()
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
pipelines  |       |     async for chunk in self.body_iterator:
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
pipelines  |       |     yield await anyio.to_thread.run_sync(_next, as_iterator)
pipelines  |       |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
pipelines  |       |     return await get_async_backend().run_sync_in_worker_thread(
pipelines  |       |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
pipelines  |       |     return await future
pipelines  |       |            ^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
pipelines  |       |     result = context.run(func, *args)
pipelines  |       |              ^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
pipelines  |       |     return next(iterator)
pipelines  |       |            ^^^^^^^^^^^^^^
pipelines  |       |   File "/app/main.py", line 665, in stream_content
pipelines  |       |     for line in res:
pipelines  |       |   File "/app/./pipelines/anthropic_manifold_pipeline.py", line 166, in stream_response
pipelines  |       |     raise Exception(f"Error: {response.status_code} - {response.text}")
pipelines  |       | Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}
pipelines  |       +------------------------------------
pipelines  |
pipelines  | During handling of the above exception, another exception occurred:
pipelines  |
pipelines  |   + Exception Group Traceback (most recent call last):
pipelines  |   |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 87, in collapse_excgroups
pipelines  |   |     yield
pipelines  |   |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 190, in __call__
pipelines  |   |     async with anyio.create_task_group() as task_group:
pipelines  |   |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
pipelines  |   |     raise BaseExceptionGroup(
pipelines  |   | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
pipelines  |   +-+---------------- 1 ----------------
pipelines  |     | Traceback (most recent call last):
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 265, in __call__
pipelines  |     |     await wrap(partial(self.listen_for_disconnect, receive))
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |     |     await func()
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 238, in listen_for_disconnect
pipelines  |     |     message = await receive()
pipelines  |     |               ^^^^^^^^^^^^^^^
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 54, in wrapped_receive
pipelines  |     |     msg = await self.receive()
pipelines  |     |           ^^^^^^^^^^^^^^^^^^^^
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 596, in receive
pipelines  |     |     await self.message_event.wait()
pipelines  |     |   File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
pipelines  |     |     await fut
pipelines  |     | asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f957d9cd0
pipelines  |     |
pipelines  |     | During handling of the above exception, another exception occurred:
pipelines  |     |
pipelines  |     | Exception Group Traceback (most recent call last):
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 192, in __call__
pipelines  |     |     await response(scope, wrapped_receive, send)
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
pipelines  |     |     async with anyio.create_task_group() as task_group:
pipelines  |     |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
pipelines  |     |     raise BaseExceptionGroup(
pipelines  |     | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
pipelines  |     +-+---------------- 1 ----------------
pipelines  |       | Traceback (most recent call last):
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 265, in __call__
pipelines  |       |     await wrap(partial(self.listen_for_disconnect, receive))
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |       |     await func()
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 238, in listen_for_disconnect
pipelines  |       |     message = await receive()
pipelines  |       |               ^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 128, in receive_or_disconnect
pipelines  |       |     message = await wrap(wrapped_receive)
pipelines  |       |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 123, in wrap
pipelines  |       |     result = await func()
pipelines  |       |              ^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 54, in wrapped_receive
pipelines  |       |     msg = await self.receive()
pipelines  |       |           ^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 596, in receive
pipelines  |       |     await self.message_event.wait()
pipelines  |       |   File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
pipelines  |       |     await fut
pipelines  |       | asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f957eeed0
pipelines  |       |
pipelines  |       | During handling of the above exception, another exception occurred:
pipelines  |       |
pipelines  |       | Exception Group Traceback (most recent call last):
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |       |     await func()
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
pipelines  |       |     return await super().stream_response(send)
pipelines  |       |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
pipelines  |       |     async for chunk in self.body_iterator:
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
pipelines  |       |     raise app_exc
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
pipelines  |       |     await self.app(scope, receive_or_disconnect, send_no_error)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
pipelines  |       |     await self.app(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
pipelines  |       |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
pipelines  |       |     raise exc
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
pipelines  |       |     await app(scope, receive, sender)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
pipelines  |       |     await self.middleware_stack(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
pipelines  |       |     await route.handle(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
pipelines  |       |     await self.app(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
pipelines  |       |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
pipelines  |       |     raise exc
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
pipelines  |       |     await app(scope, receive, sender)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 75, in app
pipelines  |       |     await response(scope, receive, send)
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
pipelines  |       |     async with anyio.create_task_group() as task_group:
pipelines  |       |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
pipelines  |       |     raise BaseExceptionGroup(
pipelines  |       | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
pipelines  |       +-+---------------- 1 ----------------
pipelines  |         | Traceback (most recent call last):
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
pipelines  |         |     result = await app(  # type: ignore[func-returns-value]
pipelines  |         |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
pipelines  |         |     return await self.app(scope, receive, send)
pipelines  |         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
pipelines  |         |     await super().__call__(scope, receive, send)
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
pipelines  |         |     await self.middleware_stack(scope, receive, send)
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
pipelines  |         |     raise exc
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
pipelines  |         |     await self.app(scope, receive, _send)
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
pipelines  |         |     with collapse_excgroups():
pipelines  |         |   File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
pipelines  |         |     self.gen.throw(typ, value, traceback)
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
pipelines  |         |     raise exc
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |         |     await func()
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
pipelines  |         |     async for chunk in self.body_iterator:
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
pipelines  |         |     yield await anyio.to_thread.run_sync(_next, as_iterator)
pipelines  |         |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
pipelines  |         |     return await get_async_backend().run_sync_in_worker_thread(
pipelines  |         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
pipelines  |         |     return await future
pipelines  |         |            ^^^^^^^^^^^^
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
pipelines  |         |     result = context.run(func, *args)
pipelines  |         |              ^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |         |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
pipelines  |         |     return next(iterator)
pipelines  |         |            ^^^^^^^^^^^^^^
pipelines  |         |   File "/app/main.py", line 665, in stream_content
pipelines  |         |     for line in res:
pipelines  |         |   File "/app/./pipelines/anthropic_manifold_pipeline.py", line 166, in stream_response
pipelines  |         |     raise Exception(f"Error: {response.status_code} - {response.text}")
pipelines  |         | Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}
pipelines  |         +------------------------------------
pipelines  |
pipelines  | During handling of the above exception, another exception occurred:
pipelines  |
pipelines  | Traceback (most recent call last):
pipelines  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
pipelines  |     result = await app(  # type: ignore[func-returns-value]
pipelines  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
pipelines  |     return await self.app(scope, receive, send)
pipelines  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
pipelines  |     await super().__call__(scope, receive, send)
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
pipelines  |     await self.middleware_stack(scope, receive, send)
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
pipelines  |     raise exc
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
pipelines  |     await self.app(scope, receive, _send)
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
pipelines  |     with collapse_excgroups():
pipelines  |   File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
pipelines  |     self.gen.throw(typ, value, traceback)
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
pipelines  |     raise exc
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
pipelines  |     await func()
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
pipelines  |     async for chunk in self.body_iterator:
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
pipelines  |     yield await anyio.to_thread.run_sync(_next, as_iterator)
pipelines  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |   File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
pipelines  |     return await get_async_backend().run_sync_in_worker_thread(
pipelines  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
pipelines  |     return await future
pipelines  |            ^^^^^^^^^^^^
pipelines  |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
pipelines  |     result = context.run(func, *args)
pipelines  |              ^^^^^^^^^^^^^^^^^^^^^^^^
pipelines  |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
pipelines  |     return next(iterator)
pipelines  |            ^^^^^^^^^^^^^^
pipelines  |   File "/app/main.py", line 665, in stream_content
pipelines  |     for line in res:
pipelines  |   File "/app/./pipelines/anthropic_manifold_pipeline.py", line 166, in stream_response
pipelines  |     raise Exception(f"Error: {response.status_code} - {response.text}")
pipelines  | Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}
pipelines  | INFO:     172.18.0.9:55708 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | INFO:     172.18.0.9:55724 - "POST /chat/completions HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35642 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35654 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35664 - "GET /pipelines HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35668 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35672 - "GET /anthropic/valves/spec HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35686 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35700 - "GET /anthropic/valves HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35714 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35716 - "POST /anthropic/valves/update HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35724 - "GET /pipelines HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35738 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35754 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35760 - "GET /anthropic/valves/spec HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35764 - "GET /models HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:35774 - "GET /anthropic/valves HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:43800 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | INFO:     172.18.0.9:43812 - "POST /chat/completions HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:43826 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/outlet HTTP/1.1" 200 OK
pipelines  | INFO:     172.18.0.9:43842 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | anthropic.claude-3-5-sonnet-20240620
pipelines  | INFO:     172.18.0.9:43844 - "POST /chat/completions HTTP/1.1" 200 OK
^Ccanceled

@dannykorpan
Copy link
Author

Today getting the same error as @realies. After resaving the API-Key in the UI under Pipelines it works for a while.

RESET_PIPELINES_DIR is not set to true. No action taken.
PIPELINES_REQUIREMENTS_PATH not specified. Skipping installation of requirements.
Downloading pipeline files from https://raw.githubusercontent.com/justinh-rahb/open-webui-pipelines/anthropic-fix/examples/pipelines/providers/anthropic_manifold_pipeline.py to ./pipelines...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6523  100  6523    0     0  26845      0 --:--:-- --:--:-- --:--:-- 26843
Downloading pipeline files from https://raw.githubusercontent.com/open-webui/pipelines/main/examples/pipelines/providers/openai_dalle_manifold_pipeline.py to ./pipelines...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2491  100  2491    0     0  10863      0 --:--:-- --:--:-- --:--:-- 10877
pip install requests  sseclient-py
Requirement already satisfied: requests in /usr/local/lib/python3.11/site-packages (2.32.2)
Collecting sseclient-py
  Downloading sseclient_py-1.8.0-py2.py3-none-any.whl.metadata (2.0 kB)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/site-packages (from requests) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/site-packages (from requests) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/site-packages (from requests) (2.2.2)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/site-packages (from requests) (2024.7.4)
Downloading sseclient_py-1.8.0-py2.py3-none-any.whl (8.8 kB)
Installing collected packages: sseclient-py
Successfully installed sseclient-py-1.8.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip
No requirements found in frontmatter of ./pipelines/openai_dalle_manifold_pipeline.py.
INFO:     Started server process [42]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:9099 (Press CTRL+C to quit)
Loaded module: anthropic_manifold_pipeline
Loaded module: openai_dalle_manifold_pipeline
on_startup:anthropic_manifold_pipeline
on_startup:openai_dalle_manifold_pipeline
INFO:     192.168.0.4:49114 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:46652 - "GET /models HTTP/1.1" 200 OK
INFO:     192.168.0.4:46658 - "POST /anthropic.claude-3-5-sonnet-20240620/filter/inlet HTTP/1.1" 200 OK
anthropic.claude-3-5-sonnet-20240620
anthropic.claude-3-5-sonnet-20240620
INFO:     192.168.0.4:46674 - "POST /chat/completions HTTP/1.1" 200 OK
ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 192, in __call__
  |     await response(scope, wrapped_receive, send)
  |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Exception Group Traceback (most recent call last):
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    |     await func()
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    |     return await super().stream_response(send)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    |     async for chunk in self.body_iterator:
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    |     raise app_exc
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    |     await self.app(scope, receive_or_disconnect, send_no_error)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    |     await self.app(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    |     raise exc
    |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
    |     await route.handle(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
    |     await self.app(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
    |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    |     raise exc
    |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    |     await app(scope, receive, sender)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 75, in app
    |     await response(scope, receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
    |     async with anyio.create_task_group() as task_group:
    |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
    |     raise BaseExceptionGroup(
    | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
      | Traceback (most recent call last):
      |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
      |     result = await app(  # type: ignore[func-returns-value]
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
      |     return await self.app(scope, receive, send)
      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
      |     await super().__call__(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
      |     await self.middleware_stack(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
      |     raise exc
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
      |     await self.app(scope, receive, _send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
      |     with collapse_excgroups():
      |   File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
      |     self.gen.throw(typ, value, traceback)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
      |     raise exc
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
      |     await func()
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
      |     async for chunk in self.body_iterator:
      |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
      |     yield await anyio.to_thread.run_sync(_next, as_iterator)
      |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
      |     return await get_async_backend().run_sync_in_worker_thread(
      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
      |     return await future
      |            ^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
      |     result = context.run(func, *args)
      |              ^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
      |     return next(iterator)
      |            ^^^^^^^^^^^^^^
      |   File "/app/main.py", line 665, in stream_content
      |     for line in res:
      |   File "/app/./pipelines/anthropic_manifold_pipeline.py", line 166, in stream_response
      |     raise Exception(f"Error: {response.status_code} - {response.text}")
      | Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}
      +------------------------------------

During handling of the above exception, another exception occurred:

  + Exception Group Traceback (most recent call last):
  |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 87, in collapse_excgroups
  |     yield
  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 190, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 265, in __call__
    |     await wrap(partial(self.listen_for_disconnect, receive))
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    |     await func()
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 238, in listen_for_disconnect
    |     message = await receive()
    |               ^^^^^^^^^^^^^^^
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 54, in wrapped_receive
    |     msg = await self.receive()
    |           ^^^^^^^^^^^^^^^^^^^^
    |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 596, in receive
    |     await self.message_event.wait()
    |   File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
    |     await fut
    | asyncio.exceptions.CancelledError: Cancelled by cancel scope 77ced5b27890
    |
    | During handling of the above exception, another exception occurred:
    |
    | Exception Group Traceback (most recent call last):
    |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 192, in __call__
    |     await response(scope, wrapped_receive, send)
    |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
    |     async with anyio.create_task_group() as task_group:
    |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
    |     raise BaseExceptionGroup(
    | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
      | Traceback (most recent call last):
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 265, in __call__
      |     await wrap(partial(self.listen_for_disconnect, receive))
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
      |     await func()
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 238, in listen_for_disconnect
      |     message = await receive()
      |               ^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 128, in receive_or_disconnect
      |     message = await wrap(wrapped_receive)
      |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 123, in wrap
      |     result = await func()
      |              ^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 54, in wrapped_receive
      |     msg = await self.receive()
      |           ^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 596, in receive
      |     await self.message_event.wait()
      |   File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
      |     await fut
      | asyncio.exceptions.CancelledError: Cancelled by cancel scope 77ced5b376d0
      |
      | During handling of the above exception, another exception occurred:
      |
      | Exception Group Traceback (most recent call last):
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
      |     await func()
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
      |     return await super().stream_response(send)
      |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
      |     async for chunk in self.body_iterator:
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
      |     raise app_exc
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
      |     await self.app(scope, receive_or_disconnect, send_no_error)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
      |     await self.app(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
      |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
      |     raise exc
      |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
      |     await app(scope, receive, sender)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
      |     await self.middleware_stack(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
      |     await route.handle(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
      |     await self.app(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
      |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
      |     raise exc
      |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
      |     await app(scope, receive, sender)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 75, in app
      |     await response(scope, receive, send)
      |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 258, in __call__
      |     async with anyio.create_task_group() as task_group:
      |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 680, in __aexit__
      |     raise BaseExceptionGroup(
      | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
      +-+---------------- 1 ----------------
        | Traceback (most recent call last):
        |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
        |     result = await app(  # type: ignore[func-returns-value]
        |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
        |     return await self.app(scope, receive, send)
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
        |     await super().__call__(scope, receive, send)
        |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
        |     await self.middleware_stack(scope, receive, send)
        |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
        |     raise exc
        |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
        |     await self.app(scope, receive, _send)
        |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
        |     with collapse_excgroups():
        |   File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
        |     self.gen.throw(typ, value, traceback)
        |   File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
        |     raise exc
        |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
        |     await func()
        |   File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
        |     async for chunk in self.body_iterator:
        |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
        |     yield await anyio.to_thread.run_sync(_next, as_iterator)
        |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |   File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
        |     return await get_async_backend().run_sync_in_worker_thread(
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
        |     return await future
        |            ^^^^^^^^^^^^
        |   File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
        |     result = context.run(func, *args)
        |              ^^^^^^^^^^^^^^^^^^^^^^^^
        |   File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
        |     return next(iterator)
        |            ^^^^^^^^^^^^^^
        |   File "/app/main.py", line 665, in stream_content
        |     for line in res:
        |   File "/app/./pipelines/anthropic_manifold_pipeline.py", line 166, in stream_response
        |     raise Exception(f"Error: {response.status_code} - {response.text}")
        | Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}
        +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 435, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/local/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/usr/local/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 65, in iterate_in_threadpool
    yield await anyio.to_thread.run_sync(_next, as_iterator)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/starlette/concurrency.py", line 54, in _next
    return next(iterator)
           ^^^^^^^^^^^^^^
  File "/app/main.py", line 665, in stream_content
    for line in res:
  File "/app/./pipelines/anthropic_manifold_pipeline.py", line 166, in stream_response
    raise Exception(f"Error: {response.status_code} - {response.text}")
Exception: Error: 401 - {"type":"error","error":{"type":"authentication_error","message":"invalid x-api-key"}}

@dannykorpan dannykorpan reopened this Aug 5, 2024
@realies
Copy link

realies commented Aug 6, 2024

Sonnet 3.5 said this could help:

index 81fa910..43d261e 100644
--- a/examples/pipelines/providers/anthropic_manifold_pipeline.py
+++ b/examples/pipelines/providers/anthropic_manifold_pipeline.py
@@ -2,23 +2,22 @@
 title: Anthropic Manifold Pipeline
 author: justinh-rahb, sriparashiva
 date: 2024-06-20
-version: 1.4
+version: 1.5
 license: MIT
 description: A pipeline for generating text and processing images using the Anthropic API.
 requirements: requests, sseclient-py
-environment_variables: ANTHROPIC_API_KEY
 """
 
-import os
-import requests
 import json
+import os
 from typing import List, Union, Generator, Iterator
 from pydantic import BaseModel
+import requests
 import sseclient
+import threading
 
 from utils.pipelines.main import pop_system_message
 
-
 class Pipeline:
     class Valves(BaseModel):
         ANTHROPIC_API_KEY: str = ""
@@ -28,18 +27,27 @@ class Pipeline:
         self.id = "anthropic"
         self.name = "anthropic/"
 
-        self.valves = self.Valves(
-            **{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY", "your-api-key-here")}
-        )
+        self.valves = self.Valves()
         self.url = 'https://api.anthropic.com/v1/messages'
+        self._lock = threading.Lock()
+        self.headers = {}
+        self.load_valves()
+
+    def load_valves(self):
+        valves_path = os.path.join(os.path.dirname(__file__), 'valves.json')
+        if os.path.exists(valves_path):
+            with open(valves_path, 'r') as f:
+                valves_data = json.load(f)
+                self.valves = self.Valves(**valves_data)
         self.update_headers()
 
     def update_headers(self):
-        self.headers = {
-            'anthropic-version': '2023-06-01',
-            'content-type': 'application/json',
-            'x-api-key': self.valves.ANTHROPIC_API_KEY
-        }
+        with self._lock:
+            self.headers = {
+                'anthropic-version': '2023-06-01',
+                'content-type': 'application/json',
+                'x-api-key': self.valves.ANTHROPIC_API_KEY
+            }
 
     def get_anthropic_models(self):
         return [
@@ -51,14 +59,14 @@ class Pipeline:
 
     async def on_startup(self):
         print(f"on_startup:{__name__}")
-        pass
+        self.load_valves()
 
     async def on_shutdown(self):
         print(f"on_shutdown:{__name__}")
-        pass
 
     async def on_valves_updated(self):
-        self.update_headers()
+        self.load_valves()
+        print(f"Anthropic API key updated: {self.valves.ANTHROPIC_API_KEY[:5]}...")
 
     def pipelines(self) -> List[dict]:
         return self.get_anthropic_models()
@@ -85,6 +93,9 @@ class Pipeline:
         self, user_message: str, model_id: str, messages: List[dict], body: dict
     ) -> Union[str, Generator, Iterator]:
         try:
+            # Ensure we're using the most up-to-date API key
+            self.load_valves()
+
             # Remove unnecessary keys
             for key in ['user', 'chat_id', 'title']:
                 body.pop(key, None)
@@ -141,12 +152,14 @@ class Pipeline:
             else:
                 return self.get_completion(payload)
         except Exception as e:
+            print(f"Error in pipe: {e}")
             return f"Error: {e}"
 
     def stream_response(self, payload: dict) -> Generator:
-        response = requests.post(self.url, headers=self.headers, json=payload, stream=True)
+        try:
+            response = requests.post(self.url, headers=self.headers, json=payload, stream=True)
+            response.raise_for_status()
 
-        if response.status_code == 200:
             client = sseclient.SSEClient(response)
             for event in client.events():
                 try:
@@ -162,13 +175,16 @@ class Pipeline:
                 except KeyError as e:
                     print(f"Unexpected data structure: {e}")
                     print(f"Full data: {data}")
-        else:
-            raise Exception(f"Error: {response.status_code} - {response.text}")
+        except requests.exceptions.RequestException as e:
+            print(f"Error in stream_response: {e}")
+            yield f"Error: {e}"
 
     def get_completion(self, payload: dict) -> str:
-        response = requests.post(self.url, headers=self.headers, json=payload)
-        if response.status_code == 200:
+        try:
+            response = requests.post(self.url, headers=self.headers, json=payload)
+            response.raise_for_status()
             res = response.json()
             return res["content"][0]["text"] if "content" in res and res["content"] else ""
-        else:
-            raise Exception(f"Error: {response.status_code} - {response.text}")
+        except requests.exceptions.RequestException as e:
+            print(f"Error in get_completion: {e}")
+            return f"Error: {e}"

@realies
Copy link

realies commented Aug 6, 2024

wait, you're supposed to provide the key via ANTHROPIC_API_KEY? can keys be fetched from valves.json as a fallback?

@justinh-rahb
Copy link
Collaborator

wait, you're supposed to provide the key via ANTHROPIC_API_KEY? can keys be fetched from valves.json as a fallback?

Intended to be optional with ability to set via valves as well, but if this is not working it'll need refac. Will look into when my time allows. For now, yes, setting an ANTHROPIC_API_KEY environment variable should resolve the current issue until a new PR is made.

@dannykorpan
Copy link
Author

wait, you're supposed to provide the key via ANTHROPIC_API_KEY? can keys be fetched from valves.json as a fallback?

Will try it.

@dannykorpan
Copy link
Author

The day after... same problem today.

@justinh-rahb
Copy link
Collaborator

For what it's worth, I’ve been using my own pipeline since I created it and haven’t personally encountered any of the reported errors or issues. All my troubleshooting and debugging has been based on these reports, but I haven’t been able to fully reproduce them. This means I’m essentially working in the dark. I would greatly appreciate any additional information, such as logs or detailed accounts of the exact sequence of events that led to these outcomes, even if it feels excessive or "too much detail", let me decide that.

@dannykorpan
Copy link
Author

How do I enable debugging, so that I can see the the used API key?

@RamboRogers
Copy link

RamboRogers commented Sep 7, 2024

I have the same error. Brand new install, valid key used on other things. Google works, anthropic crashes.

image

@bgeneto
Copy link

bgeneto commented Sep 23, 2024

I'm also having to save api key manually (for both Anthropic and Dall-E) manifold pipelines every time the docker container restarts. What is more Strange is that api keys are there and correct, I just have press save button.

@Aman-14
Copy link

Aman-14 commented Sep 24, 2024

@bgeneto Pipeline headers need to be updated at startup, I have create another here #271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants