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

Can't import dspy in my pipeline file #400

Open
Rensing1 opened this issue Jan 18, 2025 · 1 comment
Open

Can't import dspy in my pipeline file #400

Rensing1 opened this issue Jan 18, 2025 · 1 comment

Comments

@Rensing1
Copy link

Rensing1 commented Jan 18, 2025

I want to use the DSPy framework in my pipeline. But before I could implement anything, I already get an error when I try to import the DSPy module.

When I upload my pipeline.py into open-webui, I receive the message that the upload was successful; however, no new pipeline is available.

Everything works fine when I don't use import dspy at the top of my pipeline.py. This rest of the file content is basically copied from the pipeline examples folder.

Here's the code:

import os
from typing import List, Optional
from pydantic import BaseModel
from schemas import OpenAIChatMessage
import time
import dspy

class Pipeline:
class Valves(BaseModel):
pipelines: List[str] = []
priority: int = 0

    # Valves for conversation turn limiting
    target_user_roles: List[str] = ["user"]
    max_turns: Optional[int] = None

def __init__(self):
    self.type = "filter"
    self.name = "DSPy-Pipeline"
    self.valves = self.Valves(
        **{
            "pipelines": os.getenv("CONVERSATION_TURN_PIPELINES", "*").split(","),
            "max_turns": 1,
        }
    )

async def on_startup(self):
    # This function is called when the server is started.
    print(f"on_startup:{__name__}")
    pass

async def on_shutdown(self):
    # This function is called when the server is stopped.
    print(f"on_shutdown:{__name__}")
    pass

async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
    print(f"pipe:{__name__}")
    print(body)
    print(user)

    if user.get("role", "admin") in self.valves.target_user_roles:
        messages = body.get("messages", [])
        if len(messages) > self.valves.max_turns:
            raise Exception(
                f"Conversation turn limit exceeded. Max turns: {self.valves.max_turns}"
            )

    return body

`

And here is the relevant part of the output from docker logs webui:
upload_pipeline 1 pipeline.py
INFO: 172.19.0.1:45164 - "POST /api/v1/pipelines/upload HTTP/1.1" 200 OK
INFO: 172.19.0.1:45164 - "GET /api/v1/pipelines/?urlIdx=1 HTTP/1.1" 200 OK
INFO [open_webui.routers.openai] get_all_models()
INFO [open_webui.routers.ollama] get_all_models()
INFO: 172.19.0.1:45180 - "GET /api/models HTTP/1.1" 200 OK
INFO: 172.19.0.1:45164 - "GET /api/v1/pipelines/pipeline/valves/spec?urlIdx=1 HTTP/1.1" 200 OK
INFO: 172.19.0.1:45180 - "GET /api/v1/pipelines/pipeline/valves?urlIdx=1 HTTP/1.1" 200 OK
WARNI [python_multipart.multipart] Skipping data after last boundary
upload_pipeline 1 pipeline.py
INFO: 172.19.0.1:58594 - "POST /api/v1/pipelines/upload HTTP/1.1" 200 OK
INFO: 172.19.0.1:58594 - "GET /api/v1/pipelines/?urlIdx=1 HTTP/1.1" 200 OK
INFO [open_webui.routers.openai] get_all_models()
INFO [open_webui.routers.ollama] get_all_models()
INFO: 172.19.0.1:58608 - "GET /api/models HTTP/1.1" 200 OK

The first upload is the file without import dspy, the second upload is with import dspy.

And here is the output from docker logs pipelines:
INFO: 172.19.0.3:37984 - "POST /pipelines/upload HTTP/1.1" 200 OK
INFO: 172.19.0.3:37996 - "GET /pipelines HTTP/1.1" 200 OK
INFO: 172.19.0.3:38010 - "GET /models HTTP/1.1" 200 OK
WARNING:root:No Pipeline class found in pipeline
Error loading module: pipeline
Failed to import dspy: cannot import name 'TypeIs' from 'typing_extensions' (/usr/local/lib/python3.11/site-packages/typing_extensions.py)
INFO: 172.19.0.3:51356 - "POST /pipelines/upload HTTP/1.1" 200 OK
INFO: 172.19.0.3:51368 - "GET /pipelines HTTP/1.1" 200 OK
INFO: 172.19.0.3:51384 - "GET /models HTTP/1.1" 200 OK

The error can't be resolved by pip install dspy or pip install typing_extensions in the respective docker container.

@TheWasilingMan
Copy link

Try putting a "requirements" header on the file with dspy listed. For instance, check out this example: https://github.com/open-webui/pipelines/blob/main/examples/pipelines/rag/haystack_pipeline.py#L8

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

2 participants