diff --git a/examples/applescript_pipeline.py b/examples/applescript_pipeline.py index ace7e54..c4910a4 100644 --- a/examples/applescript_pipeline.py +++ b/examples/applescript_pipeline.py @@ -31,7 +31,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") OLLAMA_BASE_URL = "http://localhost:11434" diff --git a/examples/azure_openai_pipeline.py b/examples/azure_openai_pipeline.py index 4d741d1..994c378 100644 --- a/examples/azure_openai_pipeline.py +++ b/examples/azure_openai_pipeline.py @@ -26,7 +26,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") print(messages) diff --git a/examples/example_pipeline.py b/examples/example_pipeline.py index fc9c6d2..417974e 100644 --- a/examples/example_pipeline.py +++ b/examples/example_pipeline.py @@ -48,7 +48,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") print(messages) diff --git a/examples/llama_cpp_pipeline.py b/examples/llama_cpp_pipeline.py index acd3593..1bb05a6 100644 --- a/examples/llama_cpp_pipeline.py +++ b/examples/llama_cpp_pipeline.py @@ -46,7 +46,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") print(messages) diff --git a/examples/manifold_pipeline.py b/examples/manifold_pipeline.py index c968cfe..80c64fd 100644 --- a/examples/manifold_pipeline.py +++ b/examples/manifold_pipeline.py @@ -42,7 +42,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") print(messages) diff --git a/examples/ollama_manifold_pipeline.py b/examples/ollama_manifold_pipeline.py index 0eb4b13..6fc18f8 100644 --- a/examples/ollama_manifold_pipeline.py +++ b/examples/ollama_manifold_pipeline.py @@ -67,7 +67,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. if "user" in body: print("######################################") diff --git a/examples/ollama_pipeline.py b/examples/ollama_pipeline.py index 9bebd88..c7134cc 100644 --- a/examples/ollama_pipeline.py +++ b/examples/ollama_pipeline.py @@ -26,7 +26,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") OLLAMA_BASE_URL = "http://localhost:11434" diff --git a/examples/openai_pipeline.py b/examples/openai_pipeline.py index 4e315de..e72f369 100644 --- a/examples/openai_pipeline.py +++ b/examples/openai_pipeline.py @@ -26,7 +26,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") print(messages) diff --git a/examples/python_code_pipeline.py b/examples/python_code_pipeline.py index e134d32..bfe432a 100644 --- a/examples/python_code_pipeline.py +++ b/examples/python_code_pipeline.py @@ -33,7 +33,7 @@ class Pipeline: def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: - # This is where you can add your custom pipelines like RAG.' + # This is where you can add your custom pipelines like RAG. print(f"pipe:{__name__}") print(messages) diff --git a/examples/wikipedia_pipeline.py b/examples/wikipedia_pipeline.py new file mode 100644 index 0000000..1a296ae --- /dev/null +++ b/examples/wikipedia_pipeline.py @@ -0,0 +1,68 @@ +from typing import List, Union, Generator, Iterator +from pydantic import BaseModel +from schemas import OpenAIChatMessage +import requests +import os + + +class Pipeline: + def __init__(self): + # Assign a unique identifier to the pipeline. + # The identifier must be unique across all pipelines. + # The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes. + self.id = "wiki_pipeline" + self.name = "Wikipedia Pipeline" + + class Valves(BaseModel): + pass + + # Initialize rate limits + self.valves = Valves(**{"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY", "")}) + + 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 + + def pipe( + self, user_message: str, model_id: str, messages: List[dict], body: dict + ) -> Union[str, Generator, Iterator]: + # This is where you can add your custom pipelines like RAG. + print(f"pipe:{__name__}") + + if body.get("title", False): + print("Title Generation") + return "Wikipedia Pipeline" + else: + titles = [] + for query in [user_message]: + query = query.replace(" ", "_") + + r = requests.get( + f"https://en.wikipedia.org/w/api.php?action=opensearch&search={query}&limit=1&namespace=0&format=json" + ) + + response = r.json() + titles = titles + response[1] + print(titles) + + context = None + if len(titles) > 0: + r = requests.get( + f"https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles={'|'.join(titles)}" + ) + response = r.json() + # get extracts + pages = response["query"]["pages"] + for page in pages: + if context == None: + context = pages[page]["extract"] + "\n" + else: + context = context + pages[page]["extract"] + "\n" + + return context if context else "No information found"