diff --git a/comps/cores/mega/micro_service.py b/comps/cores/mega/micro_service.py index 5d96be70c4..2adc6fd326 100644 --- a/comps/cores/mega/micro_service.py +++ b/comps/cores/mega/micro_service.py @@ -159,8 +159,7 @@ def _validate_env(self): def endpoint_path(self, model=None): if self.api_key: - model_endpoint = model.split("/")[1] - return f"{self.host}/{model_endpoint}{self.endpoint}" + return f"{self.host}{self.endpoint}" else: return f"{self.protocol}://{self.host}:{self.port}{self.endpoint}" diff --git a/comps/cores/mega/orchestrator.py b/comps/cores/mega/orchestrator.py index 61246ee5a8..bae5f24c99 100644 --- a/comps/cores/mega/orchestrator.py +++ b/comps/cores/mega/orchestrator.py @@ -276,6 +276,7 @@ async def execute( stream=True, timeout=2000, ) + else: response = requests.post( url=endpoint, @@ -367,7 +368,11 @@ def generate(): if ENABLE_OPEA_TELEMETRY else contextlib.nullcontext() ): - response = await session.post(endpoint, json=input_data) + response = await session.post( + endpoint, + json=input_data, + headers={"Content-type": "application/json", "Authorization": f"Bearer {access_token}"}, + ) if response.content_type == "audio/wav": audio_data = await response.read() diff --git a/comps/llms/src/doc-summarization/integrations/common.py b/comps/llms/src/doc-summarization/integrations/common.py index 654fca37cb..8edccb5331 100644 --- a/comps/llms/src/doc-summarization/integrations/common.py +++ b/comps/llms/src/doc-summarization/integrations/common.py @@ -27,6 +27,7 @@ TOKEN_URL = os.getenv("TOKEN_URL") CLIENTID = os.getenv("CLIENTID") CLIENT_SECRET = os.getenv("CLIENT_SECRET") +OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") MAX_INPUT_TOKENS = int(os.getenv("MAX_INPUT_TOKENS", 2048)) MAX_TOTAL_TOKENS = int(os.getenv("MAX_TOTAL_TOKENS", 4096)) @@ -67,9 +68,14 @@ class OpeaDocSum(OpeaComponent): def __init__(self, name: str, description: str, config: dict = None): super().__init__(name, ServiceType.LLM.name.lower(), description, config) - self.access_token = ( - get_access_token(TOKEN_URL, CLIENTID, CLIENT_SECRET) if TOKEN_URL and CLIENTID and CLIENT_SECRET else None - ) + if OPENAI_API_KEY: + self.access_token = OPENAI_API_KEY + else: + self.access_token = ( + get_access_token(TOKEN_URL, CLIENTID, CLIENT_SECRET) + if TOKEN_URL and CLIENTID and CLIENT_SECRET + else None + ) self.llm_endpoint = get_llm_endpoint() self.tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) health_status = self.check_health()