Skip to content

Commit

Permalink
unify port in one microservice. (#424)
Browse files Browse the repository at this point in the history
* unify port in one microservice.

* update ut.

---------

Co-authored-by: sdp <[email protected]>
  • Loading branch information
lkk12014402 and sdp authored Aug 8, 2024
1 parent e156101 commit f8d45e5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
35 changes: 18 additions & 17 deletions comps/cores/mega/micro_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,24 @@ def register_microservice(
provider_endpoint: Optional[str] = None,
):
def decorator(func):
micro_service = MicroService(
name=name,
service_role=service_role,
service_type=service_type,
protocol=protocol,
host=host,
port=port,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
endpoint=endpoint,
input_datatype=input_datatype,
output_datatype=output_datatype,
provider=provider,
provider_endpoint=provider_endpoint,
)
micro_service.app.router.add_api_route(endpoint, func, methods=["POST"])
opea_microservices[name] = micro_service
if name not in opea_microservices:
micro_service = MicroService(
name=name,
service_role=service_role,
service_type=service_type,
protocol=protocol,
host=host,
port=port,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
endpoint=endpoint,
input_datatype=input_datatype,
output_datatype=output_datatype,
provider=provider,
provider_endpoint=provider_endpoint,
)
opea_microservices[name] = micro_service
opea_microservices[name].app.router.add_api_route(endpoint, func, methods=["POST"])
return func

return decorator
12 changes: 6 additions & 6 deletions comps/dataprep/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ docker build -t opea/dataprep-on-ray-redis:latest --build-arg https_proxy=$https
- option 1: Start single-process version (for 1-10 files processing)

```bash
docker run -d --name="dataprep-redis-server" -p 6007:6007 -p 6008:6008 -p 6009:6009 --runtime=runc --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT opea/dataprep-redis:latest
docker run -d --name="dataprep-redis-server" -p 6007:6007 --runtime=runc --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT opea/dataprep-redis:latest
```

- option 2: Start multi-process version (for >10 files processing)

```bash
docker run -d --name="dataprep-redis-server" -p 6007:6007 -p 6008:6008 -p 6009:6009 --runtime=runc --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT -e TIMEOUT_SECONDS=600 opea/dataprep-on-ray-redis:latest
docker run -d --name="dataprep-redis-server" -p 6007:6007 --runtime=runc --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT -e TIMEOUT_SECONDS=600 opea/dataprep-on-ray-redis:latest
```

## 2.5 Run with Docker Compose (Option B - deprecated, will move to genAIExample in future)
Expand Down Expand Up @@ -250,7 +250,7 @@ To get uploaded file structures, use the following command:
```bash
curl -X POST \
-H "Content-Type: application/json" \
http://localhost:6008/v1/dataprep/get_file
http://localhost:6007/v1/dataprep/get_file
```

Then you will get the response JSON like this:
Expand Down Expand Up @@ -283,17 +283,17 @@ The `file_path` here should be the `id` get from `/v1/dataprep/get_file` API.
curl -X POST \
-H "Content-Type: application/json" \
-d '{"file_path": "https://www.ces.tech/.txt"}' \
http://10.165.57.68:6009/v1/dataprep/delete_file
http://localhost:6007/v1/dataprep/delete_file

# delete file
curl -X POST \
-H "Content-Type: application/json" \
-d '{"file_path": "uploaded_file_1.txt"}' \
http://10.165.57.68:6009/v1/dataprep/delete_file
http://localhost:6007/v1/dataprep/delete_file

# delete all files and links
curl -X POST \
-H "Content-Type: application/json" \
-d '{"file_path": "all"}' \
http://10.165.57.68:6009/v1/dataprep/delete_file
http://localhost:6007/v1/dataprep/delete_file
```
6 changes: 2 additions & 4 deletions comps/dataprep/redis/langchain/prepare_doc_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async def ingest_documents(


@register_microservice(
name="opea_service@prepare_doc_redis_file", endpoint="/v1/dataprep/get_file", host="0.0.0.0", port=6008
name="opea_service@prepare_doc_redis", endpoint="/v1/dataprep/get_file", host="0.0.0.0", port=6007
)
@traceable(run_type="tool")
async def rag_get_file_structure():
Expand All @@ -276,7 +276,7 @@ async def rag_get_file_structure():


@register_microservice(
name="opea_service@prepare_doc_redis_del", endpoint="/v1/dataprep/delete_file", host="0.0.0.0", port=6009
name="opea_service@prepare_doc_redis", endpoint="/v1/dataprep/delete_file", host="0.0.0.0", port=6007
)
@traceable(run_type="tool")
async def delete_single_file(file_path: str = Body(..., embed=True)):
Expand Down Expand Up @@ -334,5 +334,3 @@ async def delete_single_file(file_path: str = Body(..., embed=True)):
if __name__ == "__main__":
create_upload_folder(upload_folder)
opea_microservices["opea_service@prepare_doc_redis"].start()
opea_microservices["opea_service@prepare_doc_redis_file"].start()
opea_microservices["opea_service@prepare_doc_redis_del"].start()
10 changes: 3 additions & 7 deletions tests/test_dataprep_redis_langchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ function start_service() {
REDIS_PORT=6380
docker run -d --name="test-comps-dataprep-redis-langchain" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p $REDIS_PORT:6379 -p 8002:8001 --ipc=host redis/redis-stack:7.2.0-v9
dataprep_service_port=5013
dataprep_file_service_port=5016
dataprep_del_service_port=5020
REDIS_URL="redis://${ip_address}:${REDIS_PORT}"
docker run -d --name="test-comps-dataprep-redis-langchain-server" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e REDIS_HOST=$ip_address -e REDIS_PORT=$REDIS_PORT -p ${dataprep_service_port}:6007 -p ${dataprep_file_service_port}:6008 -p ${dataprep_del_service_port}:6009 --ipc=host opea/dataprep-redis:comps
docker run -d --name="test-comps-dataprep-redis-langchain-server" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e REDIS_HOST=$ip_address -e REDIS_PORT=$REDIS_PORT -p ${dataprep_service_port}:6007 --ipc=host opea/dataprep-redis:comps
sleep 1m
}

Expand Down Expand Up @@ -72,8 +70,7 @@ function validate_microservice() {
fi

# test /v1/dataprep/get_file
dataprep_file_service_port=5016
URL="http://${ip_address}:$dataprep_file_service_port/v1/dataprep/get_file"
URL="http://${ip_address}:$dataprep_service_port/v1/dataprep/get_file"
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST "$URL")
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
RESPONSE_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
Expand All @@ -94,8 +91,7 @@ function validate_microservice() {
fi

# test /v1/dataprep/delete_file
dataprep_del_service_port=5020
URL="http://${ip_address}:$dataprep_del_service_port/v1/dataprep/delete_file"
URL="http://${ip_address}:$dataprep_service_port/v1/dataprep/delete_file"
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST -d '{"file_path": "dataprep_file.txt"}' -H 'Content-Type: application/json' "$URL")
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
RESPONSE_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
Expand Down

0 comments on commit f8d45e5

Please sign in to comment.