Skip to content

remote endpoint support #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion comps/cores/mega/micro_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
protocol: str = "http",
host: str = "localhost",
port: int = 8080,
api_key: str = None,
ssl_keyfile: Optional[str] = None,
ssl_certfile: Optional[str] = None,
endpoint: Optional[str] = "/",
Expand All @@ -49,6 +50,7 @@
self.protocol = protocol
self.host = host
self.port = port
self.api_key = api_key
self.endpoint = endpoint
self.input_datatype = input_datatype
self.output_datatype = output_datatype
Expand Down Expand Up @@ -137,7 +139,14 @@

@property
def endpoint_path(self):
return f"{self.protocol}://{self.host}:{self.port}{self.endpoint}"
if self.api_key:
return f"{self.host}{self.endpoint}"

Check warning on line 143 in comps/cores/mega/micro_service.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/micro_service.py#L143

Added line #L143 was not covered by tests
else:
return f"{self.protocol}://{self.host}:{self.port}{self.endpoint}"

@property
def api_key_value(self):
return self.api_key


def register_microservice(
Expand Down
54 changes: 41 additions & 13 deletions comps/cores/mega/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
):
# send the cur_node request/reply
endpoint = self.services[cur_node].endpoint_path
access_token = self.services[cur_node].api_key_value
llm_parameters_dict = llm_parameters.dict()

is_llm_vlm = self.services[cur_node].service_type in (ServiceType.LLM, ServiceType.LVM)
Expand All @@ -263,14 +264,27 @@
if ENABLE_OPEA_TELEMETRY
else contextlib.nullcontext()
):
response = requests.post(
url=endpoint,
data=json.dumps(inputs),
headers={"Content-type": "application/json"},
proxies={"http": None},
stream=True,
timeout=1000,
)
if access_token:
response = requests.post(

Check warning on line 268 in comps/cores/mega/orchestrator.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/orchestrator.py#L268

Added line #L268 was not covered by tests
url=endpoint,
data=json.dumps(inputs),
headers={"Content-type": "application/json", "Authorization": f"Bearer {access_token}"},
proxies={"http": None},
stream=True,
timeout=1000,
)
else:
response = requests.post(
url=endpoint,
data=json.dumps(inputs),
headers={
"Content-type": "application/json",
},
proxies={"http": None},
stream=True,
timeout=1000,
)

downstream = runtime_graph.downstream(cur_node)
if downstream:
assert len(downstream) == 1, "Not supported multiple stream downstreams yet!"
Expand All @@ -291,11 +305,25 @@
buffered_chunk_str += self.extract_chunk_str(chunk)
is_last = chunk.endswith("[DONE]\n\n")
if (buffered_chunk_str and buffered_chunk_str[-1] in hitted_ends) or is_last:
res = requests.post(
url=downstream_endpoint,
data=json.dumps({"text": buffered_chunk_str}),
proxies={"http": None},
)
if access_token:
res = requests.post(

Check warning on line 309 in comps/cores/mega/orchestrator.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/orchestrator.py#L309

Added line #L309 was not covered by tests
url=downstream_endpoint,
data=json.dumps({"text": buffered_chunk_str}),
headers={
"Content-type": "application/json",
"Authorization": f"Bearer {access_token}",
},
proxies={"http": None},
)
else:
res = requests.post(
url=downstream_endpoint,
data=json.dumps({"text": buffered_chunk_str}),
headers={
"Content-type": "application/json",
},
proxies={"http": None},
)
res_json = res.json()
if "text" in res_json:
res_txt = res_json["text"]
Expand Down