diff --git a/main.py b/main.py index 63234e7..aef7888 100644 --- a/main.py +++ b/main.py @@ -117,6 +117,7 @@ async def get_models(): @app.post("/v1/chat/completions") async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm): user_message = get_last_user_message(form_data.messages) + messages = [message.model_dump() for message in form_data.messages] if form_data.model not in app.state.PIPELINES: return HTTPException( @@ -133,7 +134,7 @@ async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm): def stream_content(): res = get_response( user_message, - messages=form_data.messages, + messages=messages, body=form_data.model_dump(), ) @@ -186,7 +187,7 @@ async def generate_openai_chat_completion(form_data: OpenAIChatCompletionForm): else: res = get_response( user_message, - messages=form_data.messages, + messages=messages, body=form_data.model_dump(), ) logging.info(f"stream:false:{res}") diff --git a/pipelines/examples/applescript_pipeline.py b/pipelines/examples/applescript_pipeline.py index d2c28f6..3453ddc 100644 --- a/pipelines/examples/applescript_pipeline.py +++ b/pipelines/examples/applescript_pipeline.py @@ -25,7 +25,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/azure_openai_pipeline.py b/pipelines/examples/azure_openai_pipeline.py index 0052760..6b746d0 100644 --- a/pipelines/examples/azure_openai_pipeline.py +++ b/pipelines/examples/azure_openai_pipeline.py @@ -21,7 +21,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/haystack_pipeline.py b/pipelines/examples/haystack_pipeline.py index cea62ff..650a771 100644 --- a/pipelines/examples/haystack_pipeline.py +++ b/pipelines/examples/haystack_pipeline.py @@ -79,7 +79,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom RAG pipeline. # Typically, you would retrieve relevant information from your knowledge base and synthesize it to generate a response. diff --git a/pipelines/examples/llama_cpp_pipeline.py b/pipelines/examples/llama_cpp_pipeline.py index 2032558..c555993 100644 --- a/pipelines/examples/llama_cpp_pipeline.py +++ b/pipelines/examples/llama_cpp_pipeline.py @@ -30,7 +30,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/llamaindex_ollama_github_pipeline.py b/pipelines/examples/llamaindex_ollama_github_pipeline.py index 17d1461..2f091d6 100644 --- a/pipelines/examples/llamaindex_ollama_github_pipeline.py +++ b/pipelines/examples/llamaindex_ollama_github_pipeline.py @@ -70,7 +70,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom RAG pipeline. # Typically, you would retrieve relevant information from your knowledge base and synthesize it to generate a response. diff --git a/pipelines/examples/llamaindex_ollama_pipeline.py b/pipelines/examples/llamaindex_ollama_pipeline.py index 089c499..19ed721 100644 --- a/pipelines/examples/llamaindex_ollama_pipeline.py +++ b/pipelines/examples/llamaindex_ollama_pipeline.py @@ -30,7 +30,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom RAG pipeline. # Typically, you would retrieve relevant information from your knowledge base and synthesize it to generate a response. diff --git a/pipelines/examples/llamaindex_pipeline.py b/pipelines/examples/llamaindex_pipeline.py index 8dbce35..195e3f8 100644 --- a/pipelines/examples/llamaindex_pipeline.py +++ b/pipelines/examples/llamaindex_pipeline.py @@ -25,7 +25,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom RAG pipeline. # Typically, you would retrieve relevant information from your knowledge base and synthesize it to generate a response. diff --git a/pipelines/examples/mlx_pipeline.py b/pipelines/examples/mlx_pipeline.py index 71faa4f..8487d8e 100644 --- a/pipelines/examples/mlx_pipeline.py +++ b/pipelines/examples/mlx_pipeline.py @@ -73,7 +73,7 @@ class Pipeline: print(f"Failed to terminate subprocess: {e}") def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/ollama_pipeline.py b/pipelines/examples/ollama_pipeline.py index 437461d..876380a 100644 --- a/pipelines/examples/ollama_pipeline.py +++ b/pipelines/examples/ollama_pipeline.py @@ -21,7 +21,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/openai_pipeline.py b/pipelines/examples/openai_pipeline.py index 1c712e4..f4273e7 100644 --- a/pipelines/examples/openai_pipeline.py +++ b/pipelines/examples/openai_pipeline.py @@ -21,7 +21,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/pipeline_example.py b/pipelines/examples/pipeline_example.py index a0d1f95..1015ba8 100644 --- a/pipelines/examples/pipeline_example.py +++ b/pipelines/examples/pipeline_example.py @@ -20,7 +20,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/examples/python_code_pipeline.py b/pipelines/examples/python_code_pipeline.py index cfe1408..8d3aa20 100644 --- a/pipelines/examples/python_code_pipeline.py +++ b/pipelines/examples/python_code_pipeline.py @@ -31,7 +31,7 @@ class Pipeline: return e.output.strip(), e.returncode def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/pipelines/ollama_pipeline.py b/pipelines/ollama_pipeline.py index 437461d..876380a 100644 --- a/pipelines/ollama_pipeline.py +++ b/pipelines/ollama_pipeline.py @@ -21,7 +21,7 @@ class Pipeline: pass def get_response( - self, user_message: str, messages: List[OpenAIChatMessage], body: dict + self, user_message: str, messages: List[dict], body: dict ) -> Union[str, Generator, Iterator]: # This is where you can add your custom pipelines like RAG.' print(f"get_response:{__name__}") diff --git a/schemas.py b/schemas.py index 6f90d68..5cad1e6 100644 --- a/schemas.py +++ b/schemas.py @@ -12,6 +12,6 @@ class OpenAIChatMessage(BaseModel): class OpenAIChatCompletionForm(BaseModel): stream: bool = True model: str - messages: List[OpenAIChatMessage] + messages: List[dict] model_config = ConfigDict(extra="allow") diff --git a/utils.py b/utils.py index 97b22fc..a50cddf 100644 --- a/utils.py +++ b/utils.py @@ -22,7 +22,7 @@ def stream_message_template(model: str, message: str): } -def get_last_user_message(messages: List[OpenAIChatMessage]) -> str: +def get_last_user_message(messages: List[dict]) -> str: for message in reversed(messages): if message.role == "user": return message.content