This commit is contained in:
Timothy J. Baek 2024-05-22 13:33:44 -07:00
parent 7268268f0f
commit 72a119f4db
16 changed files with 18 additions and 17 deletions

View File

@ -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}")

View File

@ -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__}")

View File

@ -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__}")

View File

@ -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.

View File

@ -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__}")

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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__}")

View File

@ -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__}")

View File

@ -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__}")

View File

@ -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__}")

View File

@ -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__}")

View File

@ -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__}")

View File

@ -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")

View File

@ -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