mirror of
https://github.com/open-webui/pipelines
synced 2025-05-14 17:35:45 +00:00
refac
This commit is contained in:
parent
7268268f0f
commit
72a119f4db
5
main.py
5
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}")
|
||||
|
@ -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__}")
|
||||
|
@ -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__}")
|
||||
|
@ -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.
|
||||
|
@ -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__}")
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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__}")
|
||||
|
@ -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__}")
|
||||
|
@ -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__}")
|
||||
|
@ -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__}")
|
||||
|
@ -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__}")
|
||||
|
@ -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__}")
|
||||
|
@ -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")
|
||||
|
2
utils.py
2
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
|
||||
|
Loading…
Reference in New Issue
Block a user