Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 26, 2024
1 parent 89003ff commit 67c0b4f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 49 deletions.
8 changes: 3 additions & 5 deletions comps/reranks/src/integrations/opea_fastrag_reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@

import os

from comps.cores.common.component import OpeaComponent
from fastrag.rankers import IPEXBiEncoderSimilarityRanker
from haystack import Document

from comps import CustomLogger
from comps.cores.common.component import OpeaComponent
from comps.cores.mega.micro_service import ServiceType
from comps.cores.proto.docarray import RerankedDoc, SearchedDoc, TextDoc

logger = CustomLogger("local_reranking")
logflag = os.getenv("LOGFLAG", False)
RANKER_MODEL = os.getenv("RANKER_MODEL")

class OpeaFastRAGReranking(OpeaComponent):
"""A specialized reranking component derived from OpeaComponent for fastRAG reranking services.

"""
class OpeaFastRAGReranking(OpeaComponent):
"""A specialized reranking component derived from OpeaComponent for fastRAG reranking services."""

def __init__(self, name: str, description: str, config: dict = None):
super().__init__(name, ServiceType.RERANK.name.lower(), description, config)
self.reranker_model = IPEXBiEncoderSimilarityRanker(RANKER_MODEL)
self.reranker_model.warm_up()


async def invoke(self, input: SearchedDoc) -> RerankedDoc:
"""Invokes the reranking service to generate reranking for the provided input.
Expand Down
14 changes: 3 additions & 11 deletions comps/reranks/src/integrations/opea_mosec_reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,22 @@
import re

import requests
from comps.cores.common.component import OpeaComponent
from langchain_core.prompts import ChatPromptTemplate

from comps import (
CustomLogger,
LLMParamsDoc,
SearchedDoc,
ServiceType,
)
from comps import CustomLogger, LLMParamsDoc, SearchedDoc, ServiceType
from comps.cores.common.component import OpeaComponent

logger = CustomLogger("reranking_mosec_xeon")
logflag = os.getenv("LOGFLAG", False)


class OPEAMosecReranking(OpeaComponent):
"""A specialized reranking component derived from OpeaComponent for mosec reranking services.
"""
"""A specialized reranking component derived from OpeaComponent for mosec reranking services."""

def __init__(self, name: str, description: str, config: dict = None):
super().__init__(name, ServiceType.RERANK.name.lower(), description, config)
self.mosec_reranking_endpoint = os.getenv("MOSEC_RERANKING_ENDPOINT", "http://localhost:8080")


async def invoke(self, input: SearchedDoc) -> LLMParamsDoc:
"""Invokes the reranking service to generate reranking for the provided input.
Expand Down Expand Up @@ -79,7 +72,6 @@ async def invoke(self, input: SearchedDoc) -> LLMParamsDoc:
logger.info(input.initial_query)
return LLMParamsDoc(query=input.initial_query)


def check_health(self) -> bool:
"""Checks the health of the reranking service.
Expand Down
16 changes: 5 additions & 11 deletions comps/reranks/src/integrations/opea_tei_reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

import aiohttp

from comps import (
CustomLogger,
LLMParamsDoc,
SearchedDoc,
ServiceType,
)
from comps import CustomLogger, LLMParamsDoc, SearchedDoc, ServiceType
from comps.cores.common.component import OpeaComponent
from comps.cores.mega.utils import get_access_token
from comps.cores.proto.api_protocol import (
Expand Down Expand Up @@ -43,11 +38,10 @@ def __init__(self, name: str, description: str, config: dict = None):
super().__init__(name, ServiceType.reranking.name.lower(), description, config)
self.tei_reranking_endpoint = os.getenv("TEI_RERANKING_ENDPOINT", "http://localhost:8080")


async def invoke(self, input: Union[SearchedDoc, RerankingRequest, ChatCompletionRequest]
) -> Union[LLMParamsDoc, RerankingResponse, ChatCompletionRequest]:
"""Invokes the reranking service to generate rerankings for the provided input.
"""
async def invoke(
self, input: Union[SearchedDoc, RerankingRequest, ChatCompletionRequest]
) -> Union[LLMParamsDoc, RerankingResponse, ChatCompletionRequest]:
"""Invokes the reranking service to generate rerankings for the provided input."""
reranking_results = []
access_token = (
get_access_token(TOKEN_URL, CLIENTID, CLIENT_SECRET) if TOKEN_URL and CLIENTID and CLIENT_SECRET else None
Expand Down
13 changes: 3 additions & 10 deletions comps/reranks/src/integrations/opea_video_native_reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
import re
import time

from comps.cores.common.component import OpeaComponent
from fastapi import HTTPException

from comps import (
LVMVideoDoc,
SearchedMultimodalDoc,
ServiceType,
)
from comps import LVMVideoDoc, SearchedMultimodalDoc, ServiceType
from comps.cores.common.component import OpeaComponent

chunk_duration = os.getenv("CHUNK_DURATION", "10") or "10"
chunk_duration = float(chunk_duration) if chunk_duration.isdigit() else 10.0
Expand Down Expand Up @@ -72,14 +68,11 @@ def format_video_name(video_name):


class OPEAVideoNativeReranking(OpeaComponent):
"""A specialized reranking component derived from OpeaComponent for OPEA Video native reranking services.
"""
"""A specialized reranking component derived from OpeaComponent for OPEA Video native reranking services."""

def __init__(self, name: str, description: str, config: dict = None):
super().__init__(name, ServiceType.RERANK.name.lower(), description, config)


async def invoke(self, input: SearchedMultimodalDoc) -> LVMVideoDoc:
"""Invokes the reranking service to generate reranking for the provided input.
Expand Down
22 changes: 11 additions & 11 deletions comps/reranks/src/opea_reranking_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import time
from typing import Union

from comps.cores.proto.docarray import LLMParamsDoc, LVMVideoDoc, RerankedDoc, SearchedDoc, SearchedMultimodalDoc
from integrations.opea_fastrag_reranking import OpeaFastRAGReranking
from integrations.opea_mosec_reranking import OPEAMosecReranking
from integrations.opea_tei_reranking import OPEATEIReranking
from comps.reranks.src.integrations.opea_video_native_reranking import OPEAVideoNativeReranking

from comps import (
CustomLogger,
Expand All @@ -21,7 +19,8 @@
statistics_dict,
)
from comps.cores.proto.api_protocol import ChatCompletionRequest, RerankingRequest, RerankingResponse

from comps.cores.proto.docarray import LLMParamsDoc, LVMVideoDoc, RerankedDoc, SearchedDoc, SearchedMultimodalDoc
from comps.reranks.src.integrations.opea_video_native_reranking import OPEAVideoNativeReranking

logger = CustomLogger("opea_reranking_microservice")
logflag = os.getenv("LOGFLAG", False)
Expand All @@ -43,23 +42,23 @@
opea_mosec_reranking = OPEAMosecReranking(
name="OPEAMosecReranking",
description="OPEA Mosec Reranking Service",
)
)
# Register components with the controller
controller.register(opea_mosec_reranking)
controller.register(opea_mosec_reranking)
if os.getenv("TEI_EMBEDDING_ENDPOINT"):
opea_tei_reranking = OPEATEIReranking(
name="OPEATEIReranking",
description="OPEA TEI Reranking Service",
)
)
# Register components with the controller
controller.register(opea_tei_reranking)
controller.register(opea_tei_reranking)
if os.getenv("CHUNK_DURATION"):
opea_video_native_reranking = OPEAVideoNativeReranking(
name="OPEAVideoNativeReranking",
description="OPEA Video Native Reranking Service",
)
)
# Register components with the controller
controller.register(opea_video_native_reranking)
controller.register(opea_video_native_reranking)

# Discover and activate a healthy component
controller.discover_and_activate()
Expand All @@ -75,8 +74,9 @@
port=8000,
)
@register_statistics(names=["opea_service@reranking"])
async def reranking(input: Union[SearchedMultimodalDoc, SearchedDoc, RerankingRequest, ChatCompletionRequest]
) -> Union[RerankedDoc, LLMParamsDoc, RerankingResponse, ChatCompletionRequest, LVMVideoDoc]:
async def reranking(
input: Union[SearchedMultimodalDoc, SearchedDoc, RerankingRequest, ChatCompletionRequest]
) -> Union[RerankedDoc, LLMParamsDoc, RerankingResponse, ChatCompletionRequest, LVMVideoDoc]:
start = time.time()

# Log the input if logging is enabled
Expand Down
1 change: 0 additions & 1 deletion comps/retrievers/pinecone/langchain/retriever_pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@register_microservice(
name="opea_service@retriever_pinecone",
service_type=ServiceType.RETRIEVER,
host="0.0.0.0",
port=7000,
)
Expand Down

0 comments on commit 67c0b4f

Please sign in to comment.