unify port in one microservice. (#424)

* unify port in one microservice.

* update ut.

---------

Co-authored-by: sdp <sdp@srf797636.jf.intel.com>
This commit is contained in:
lkk
2024-08-08 20:45:15 +08:00
committed by GitHub
parent e15610101c
commit f8d45e53c6
4 changed files with 29 additions and 34 deletions

View File

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

View File

@@ -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)
@@ -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:
@@ -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
```

View File

@@ -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():
@@ -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)):
@@ -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()

View File

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