Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8349d24
move chatqna gateway.
Oct 20, 2024
3da7d3c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2024
eea3db3
fix import issue.
Oct 20, 2024
e51a6d7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2024
a252db3
move codegen gateway.
Oct 20, 2024
11c1516
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2024
139986e
Merge branch 'main' into move_gateway
lkk12014402 Oct 21, 2024
91bae4d
move code_translation gateway.
Oct 21, 2024
e11773d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2024
a07a12b
update all examples gateway.
Oct 21, 2024
ff1b675
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2024
324df2a
fix import issue.
Oct 21, 2024
cdcfbe9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2024
b5c970f
Merge branch 'main' into move_gateway
Spycsh Oct 29, 2024
866d72e
update service start entry.
Oct 29, 2024
e398527
update service start entry.
Oct 29, 2024
f72347f
remove `MEGA_SERVICE_HOST_IP` which is not actually used.
Oct 30, 2024
a8e6511
Merge branch 'main' into move_gateway
lkk12014402 Nov 12, 2024
2e9d6ad
Merge branch 'main' into move_gateway
chensuyue Nov 13, 2024
3ac80e2
Merge branch 'main' into move_gateway
lkk12014402 Nov 14, 2024
04c587d
Merge branch 'main' into move_gateway
lkk12014402 Dec 5, 2024
337f0dd
Merge branch 'main' into move_gateway
lkk12014402 Dec 5, 2024
76caa00
update docsum/faqgen.
lkk12014402 Dec 5, 2024
d13bf2a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2024
b1d5422
update docsum/faqgen.
lkk12014402 Dec 5, 2024
7f1f52d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2024
0c99b8a
Merge branch 'main' into move_gateway
lkk12014402 Dec 5, 2024
082caee
move more gates.
lkk12014402 Dec 5, 2024
3fbefd4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2024
6acdb75
fix 2 example.
lkk12014402 Dec 6, 2024
52e0d5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 6, 2024
3643e29
revert docsum ut.
lkk12014402 Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 74 additions & 4 deletions ChatQnA/chatqna_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

import os

from comps import ChatQnAGateway, MicroService, ServiceOrchestrator, ServiceType
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
from comps.cores.proto.api_protocol import (
ChatCompletionRequest,
ChatCompletionResponse,
ChatCompletionResponseChoice,
ChatMessage,
UsageInfo,
)
from comps.cores.proto.docarray import LLMParams, RerankerParms, RetrieverParms
from fastapi import Request
from fastapi.responses import StreamingResponse


MEGA_SERVICE_HOST_IP = os.getenv("MEGA_SERVICE_HOST_IP", "0.0.0.0")
MEGA_SERVICE_PORT = int(os.getenv("MEGA_SERVICE_PORT", 8888))
Expand All @@ -17,7 +28,7 @@
LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000))


class ChatQnAService:
class ChatQnAService(Gateway):
def __init__(self, host="0.0.0.0", port=8000):
self.host = host
self.port = port
Expand Down Expand Up @@ -60,9 +71,68 @@ def add_remote_service(self):
self.megaservice.flow_to(embedding, retriever)
self.megaservice.flow_to(retriever, rerank)
self.megaservice.flow_to(rerank, llm)
self.gateway = ChatQnAGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)

async def handle_request(self, request: Request):
data = await request.json()
stream_opt = data.get("stream", True)
chat_request = ChatCompletionRequest.parse_obj(data)
prompt = self._handle_message(chat_request.messages)
parameters = LLMParams(
max_tokens=chat_request.max_tokens if chat_request.max_tokens else 1024,
top_k=chat_request.top_k if chat_request.top_k else 10,
top_p=chat_request.top_p if chat_request.top_p else 0.95,
temperature=chat_request.temperature if chat_request.temperature else 0.01,
frequency_penalty=chat_request.frequency_penalty if chat_request.frequency_penalty else 0.0,
presence_penalty=chat_request.presence_penalty if chat_request.presence_penalty else 0.0,
repetition_penalty=chat_request.repetition_penalty if chat_request.repetition_penalty else 1.03,
streaming=stream_opt,
chat_template=chat_request.chat_template if chat_request.chat_template else None,
)
retriever_parameters = RetrieverParms(
search_type=chat_request.search_type if chat_request.search_type else "similarity",
k=chat_request.k if chat_request.k else 4,
distance_threshold=chat_request.distance_threshold if chat_request.distance_threshold else None,
fetch_k=chat_request.fetch_k if chat_request.fetch_k else 20,
lambda_mult=chat_request.lambda_mult if chat_request.lambda_mult else 0.5,
score_threshold=chat_request.score_threshold if chat_request.score_threshold else 0.2,
)
reranker_parameters = RerankerParms(
top_n=chat_request.top_n if chat_request.top_n else 1,
)
result_dict, runtime_graph = await self.megaservice.schedule(
initial_inputs={"text": prompt},
llm_parameters=parameters,
retriever_parameters=retriever_parameters,
reranker_parameters=reranker_parameters,
)
for node, response in result_dict.items():
if isinstance(response, StreamingResponse):
return response
last_node = runtime_graph.all_leaves()[-1]
response = result_dict[last_node]["text"]
choices = []
usage = UsageInfo()
choices.append(
ChatCompletionResponseChoice(
index=0,
message=ChatMessage(role="assistant", content=response),
finish_reason="stop",
)
)
return ChatCompletionResponse(model="chatqna", choices=choices, usage=usage)

def start(self):

super().__init__(
megaservice=self.megaservice,
host=self.host,
port=self.port,
endpoint=str(MegaServiceEndpoint.CHAT_QNA),
input_datatype=ChatCompletionRequest,
output_datatype=ChatCompletionResponse,
)

if __name__ == "__main__":
chatqna = ChatQnAService(host=MEGA_SERVICE_HOST_IP, port=MEGA_SERVICE_PORT)
chatqna = ChatQnAService(port=MEGA_SERVICE_PORT)
chatqna.add_remote_service()
chatqna.start()
6 changes: 3 additions & 3 deletions DocSum/tests/test_compose_on_gaudi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ function validate_microservices() {
# Video2Audio service
validate_services \
"${host_ip}:7078/v1/video2audio" \
"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAAIAAAN3wAtLS0tLS0tLS0tLS1LS0tLS0tLS0tLS0tpaWlpaWlpaWlpaWlph4eHh4eHh4eHh4eHpaWlpaWlpaWlpaWlpcPDw8PDw8PDw8PDw+Hh4eHh4eHh4eHh4eH///////////////8AAAAATGF2YzU4LjU0AAAAAAAAAAAAAAAAJAYwAAAAAAAADd9L18KaAAAAAAAAAAAAAAAAAAAAAP/7kGQAAAMhClSVMEACMOAabaCMAREA" \
"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAAIAAAN3wAtLS0tLS0tLS0tLS1LS0tLS0tLS0tLS0tpaWlpaWlpaWlpaWlph4eHh4eHh4eHh4eHpaWlpaWlpaWlpaWlpcPDw8PDw8PDw8PDw+Hh4eHh4eHh4eHh4eH///////////////8AAAAATGF2YzU4LjU0AAAAAAAAAAAAAAAAJAYwAAAAAAAADd95t4qPAAAAAAAAAAAAAAAAAAAAAP/7kGQAAAMhClSVMEACMOAabaCMAREA" \
"dataprep-video2audio" \
"dataprep-video2audio-service" \
"{\"byte_str\": \"$(input_data_for_test "video")\"}"

# Docsum Data service - video
validate_services \
"${host_ip}:7079/v1/multimedia2text" \
'"query":"well"' \
'"query":"well' \
"dataprep-multimedia2text" \
"dataprep-multimedia2text" \
"{\"video\": \"$(input_data_for_test "video")\"}"

# Docsum Data service - audio
validate_services \
"${host_ip}:7079/v1/multimedia2text" \
'"query":"well"' \
'"query":"well' \
"dataprep-multimedia2text" \
"dataprep-multimedia2text" \
"{\"audio\": \"$(input_data_for_test "audio")\"}"
Expand Down
8 changes: 4 additions & 4 deletions DocSum/tests/test_compose_on_xeon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

set -xe
# set -xe

IMAGE_REPO=${IMAGE_REPO:-"opea"}
IMAGE_TAG=${IMAGE_TAG:-"latest"}
Expand Down Expand Up @@ -150,23 +150,23 @@ function validate_microservices() {
# Video2Audio service
validate_services \
"${host_ip}:7078/v1/video2audio" \
"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAAIAAAN3wAtLS0tLS0tLS0tLS1LS0tLS0tLS0tLS0tpaWlpaWlpaWlpaWlph4eHh4eHh4eHh4eHpaWlpaWlpaWlpaWlpcPDw8PDw8PDw8PDw+Hh4eHh4eHh4eHh4eH///////////////8AAAAATGF2YzU4LjU0AAAAAAAAAAAAAAAAJAYwAAAAAAAADd9L18KaAAAAAAAAAAAAAAAAAAAAAP/7kGQAAAMhClSVMEACMOAabaCMAREA" \
"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAAIAAAN3wAtLS0tLS0tLS0tLS1LS0tLS0tLS0tLS0tpaWlpaWlpaWlpaWlph4eHh4eHh4eHh4eHpaWlpaWlpaWlpaWlpcPDw8PDw8PDw8PDw+Hh4eHh4eHh4eHh4eH///////////////8AAAAATGF2YzU4LjU0AAAAAAAAAAAAAAAAJAYwAAAAAAAADd95t4qPAAAAAAAAAAAAAAAAAAAAAP/7kGQAAAMhClSVMEACMOAabaCMAREA" \
"dataprep-video2audio" \
"dataprep-video2audio-service" \
"{\"byte_str\": \"$(input_data_for_test "video")\"}"

# Docsum Data service - video
validate_services \
"${host_ip}:7079/v1/multimedia2text" \
'"query":"well"' \
'"query":"well' \
"dataprep-multimedia2text-service" \
"dataprep-multimedia2text" \
"{\"video\": \"$(input_data_for_test "video")\"}"

# Docsum Data service - audio
validate_services \
"${host_ip}:7079/v1/multimedia2text" \
'"query":"well"' \
'"query":"well' \
"dataprep-multimedia2text-service" \
"dataprep-multimedia2text" \
"{\"audio\": \"$(input_data_for_test "audio")\"}"
Expand Down
2 changes: 1 addition & 1 deletion MultimodalQnA/multimodalqna.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def handle_request(self, request: Request):
data = await request.json()
stream_opt = bool(data.get("stream", False))
if stream_opt:
print("[ MultimodalQnAGateway ] stream=True not used, this has not support streaming yet!")
print("[ MultimodalQnAService ] stream=True not used, this has not support streaming yet!")
stream_opt = False
chat_request = ChatCompletionRequest.model_validate(data)
# Multimodal RAG QnA With Videos has not yet accepts image as input during QnA.
Expand Down
Loading