Skip to content

Commit

Permalink
Update ChatQnA Guadi microservice (#126)
Browse files Browse the repository at this point in the history
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
  • Loading branch information
lvliang-intel authored May 13, 2024
1 parent 4885e6d commit e080c26
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
15 changes: 14 additions & 1 deletion ChatQnA/microservice/gaudi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export INDEX_NAME="rag-redis"
export HUGGINGFACEHUB_API_TOKEN=${your_hf_api_token}
```

Note: Please replace with `your_ip` with you external IP address, do not use localhost.

Note: Please replace with `host_ip` with you external IP address, do not use localhost.

### Start Microservice Docker Containers
Expand Down Expand Up @@ -125,10 +127,21 @@ curl http://${host_ip}:6000/v1/embeddings\

3. Retriever Microservice

To consume the retriever microservice, you need to generate a mock embedding vector of length 768 in Python script:

```python
import random

embedding = [random.uniform(-1, 1) for _ in range(768)]
print(embedding)
```

Then substitute your mock embedding vector for the `${your_embedding}` in the following cURL command:

```bash
curl http://${host_ip}:7000/v1/retrieval\
-X POST \
-d '{"text":"test", "embedding":[1,1,...1]}' \
-d '{"text":"test", "embedding":${your_embedding}}' \
-H 'Content-Type: application/json'
```

Expand Down
24 changes: 16 additions & 8 deletions ChatQnA/microservice/gaudi/chatqna.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,39 @@
# limitations under the License.


from comps import RemoteMicroService, ServiceOrchestrator
from comps import MicroService, ServiceOrchestrator


class ChatQnAService:
def __init__(self, port=8000):
self.service_builder = ServiceOrchestrator(port=port)
self.service_builder = ServiceOrchestrator(host="0.0.0.0", port=port, endpoint="/v1/chatqna")

def add_remote_service(self):
embedding = RemoteMicroService(name="embedding", host="0.0.0.0", port=6000, expose_endpoint="/v1/embeddings")
retriever = RemoteMicroService(name="retriever", host="0.0.0.0", port=7000, expose_endpoint="/v1/retrieval")
rerank = RemoteMicroService(name="rerank", host="0.0.0.0", port=8000, expose_endpoint="/v1/reranking")
llm = RemoteMicroService(name="llm", host="0.0.0.0", port=9000, expose_endpoint="/v1/chat/completions")
embedding = MicroService(
name="embedding", host="0.0.0.0", port=6000, expose_endpoint="/v1/embeddings", use_remote_service=True
)
retriever = MicroService(
name="retriever", host="0.0.0.0", port=7000, expose_endpoint="/v1/retrieval", use_remote_service=True
)
rerank = MicroService(
name="rerank", host="0.0.0.0", port=8000, expose_endpoint="/v1/reranking", use_remote_service=True
)
llm = MicroService(
name="llm", host="0.0.0.0", port=9000, expose_endpoint="/v1/chat/completions", use_remote_service=True
)
self.service_builder.add(embedding).add(retriever).add(rerank).add(llm)
self.service_builder.flow_to(embedding, retriever)
self.service_builder.flow_to(retriever, rerank)
self.service_builder.flow_to(rerank, llm)

def schedule(self):
self.service_builder.schedule(initial_inputs={"text": "What is the revenue of Nike?"})
self.service_builder.schedule(initial_inputs={"text": "What is the revenue of Nike in 2023?"})
self.service_builder.get_all_final_outputs()
result_dict = self.service_builder.result_dict
print(result_dict)


if __name__ == "__main__":
chatqna = ChatQnAService(port=9001)
chatqna = ChatQnAService(port=8888)
chatqna.add_remote_service()
chatqna.schedule()
28 changes: 18 additions & 10 deletions ChatQnA/microservice/xeon/chatqna.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@
# limitations under the License.


from comps import RemoteMicroService, ServiceOrchestrator
from comps import MicroService, ServiceOrchestrator


class MyServiceOrchestrator:
class ChatQnAService:
def __init__(self, port=8000):
self.service_builder = ServiceOrchestrator(port=port)
self.service_builder = ServiceOrchestrator(host="0.0.0.0", port=port, endpoint="/v1/chatqna")

def add_remote_service(self):
embedding = RemoteMicroService(name="embedding", host="0.0.0.0", port=6000, expose_endpoint="/v1/embeddings")
retriever = RemoteMicroService(name="retriever", host="0.0.0.0", port=7000, expose_endpoint="/v1/retrieval")
rerank = RemoteMicroService(name="rerank", host="0.0.0.0", port=8000, expose_endpoint="/v1/reranking")
llm = RemoteMicroService(name="llm", host="0.0.0.0", port=9000, expose_endpoint="/v1/chat/completions")
embedding = MicroService(
name="embedding", host="0.0.0.0", port=6000, expose_endpoint="/v1/embeddings", use_remote_service=True
)
retriever = MicroService(
name="retriever", host="0.0.0.0", port=7000, expose_endpoint="/v1/retrieval", use_remote_service=True
)
rerank = MicroService(
name="rerank", host="0.0.0.0", port=8000, expose_endpoint="/v1/reranking", use_remote_service=True
)
llm = MicroService(
name="llm", host="0.0.0.0", port=9000, expose_endpoint="/v1/chat/completions", use_remote_service=True
)
self.service_builder.add(embedding).add(retriever).add(rerank).add(llm)
self.service_builder.flow_to(embedding, retriever)
self.service_builder.flow_to(retriever, rerank)
Expand All @@ -38,6 +46,6 @@ def schedule(self):


if __name__ == "__main__":
service_ochestrator = MyServiceOrchestrator(port=9001)
service_ochestrator.add_remote_service()
service_ochestrator.schedule()
chatqna = ChatQnAService(port=8888)
chatqna.add_remote_service()
chatqna.schedule()

0 comments on commit e080c26

Please sign in to comment.