Skip to content

Commit e18369b

Browse files
remove examples gateway. (opea-project#1250)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2af1ea0 commit e18369b

File tree

13 files changed

+128
-71
lines changed

13 files changed

+128
-71
lines changed

AudioQnA/audioqna.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import asyncio
55
import os
66

7-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
7+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
88
from comps.cores.proto.api_protocol import AudioChatCompletionRequest, ChatCompletionResponse
99
from comps.cores.proto.docarray import LLMParams
1010
from fastapi import Request
@@ -18,11 +18,12 @@
1818
TTS_SERVICE_PORT = int(os.getenv("TTS_SERVICE_PORT", 9088))
1919

2020

21-
class AudioQnAService(Gateway):
21+
class AudioQnAService:
2222
def __init__(self, host="0.0.0.0", port=8000):
2323
self.host = host
2424
self.port = port
2525
self.megaservice = ServiceOrchestrator()
26+
self.endpoint = str(MegaServiceEndpoint.AUDIO_QNA)
2627

2728
def add_remote_service(self):
2829
asr = MicroService(
@@ -78,14 +79,17 @@ async def handle_request(self, request: Request):
7879
return response
7980

8081
def start(self):
81-
super().__init__(
82-
megaservice=self.megaservice,
82+
self.service = MicroService(
83+
self.__class__.__name__,
84+
service_role=ServiceRoleType.MEGASERVICE,
8385
host=self.host,
8486
port=self.port,
85-
endpoint=str(MegaServiceEndpoint.AUDIO_QNA),
87+
endpoint=self.endpoint,
8688
input_datatype=AudioChatCompletionRequest,
8789
output_datatype=ChatCompletionResponse,
8890
)
91+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
92+
self.service.start()
8993

9094

9195
if __name__ == "__main__":

AudioQnA/audioqna_multilang.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import base64
66
import os
77

8-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
8+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
99
from comps.cores.proto.api_protocol import AudioChatCompletionRequest, ChatCompletionResponse
1010
from comps.cores.proto.docarray import LLMParams
1111
from fastapi import Request
@@ -54,14 +54,16 @@ def align_outputs(self, data, cur_node, inputs, runtime_graph, llm_parameters_di
5454
return data
5555

5656

57-
class AudioQnAService(Gateway):
57+
class AudioQnAService:
5858
def __init__(self, host="0.0.0.0", port=8000):
5959
self.host = host
6060
self.port = port
6161
ServiceOrchestrator.align_inputs = align_inputs
6262
ServiceOrchestrator.align_outputs = align_outputs
6363
self.megaservice = ServiceOrchestrator()
6464

65+
self.endpoint = str(MegaServiceEndpoint.AUDIO_QNA)
66+
6567
def add_remote_service(self):
6668
asr = MicroService(
6769
name="asr",
@@ -118,14 +120,17 @@ async def handle_request(self, request: Request):
118120
return response
119121

120122
def start(self):
121-
super().__init__(
122-
megaservice=self.megaservice,
123+
self.service = MicroService(
124+
self.__class__.__name__,
125+
service_role=ServiceRoleType.MEGASERVICE,
123126
host=self.host,
124127
port=self.port,
125-
endpoint=str(MegaServiceEndpoint.AUDIO_QNA),
128+
endpoint=self.endpoint,
126129
input_datatype=AudioChatCompletionRequest,
127130
output_datatype=ChatCompletionResponse,
128131
)
132+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
133+
self.service.start()
129134

130135

131136
if __name__ == "__main__":

AvatarChatbot/avatarchatbot.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import sys
77

8-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
8+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
99
from comps.cores.proto.api_protocol import AudioChatCompletionRequest, ChatCompletionResponse
1010
from comps.cores.proto.docarray import LLMParams
1111
from fastapi import Request
@@ -29,11 +29,12 @@ def check_env_vars(env_var_list):
2929
print("All environment variables are set.")
3030

3131

32-
class AvatarChatbotService(Gateway):
32+
class AvatarChatbotService:
3333
def __init__(self, host="0.0.0.0", port=8000):
3434
self.host = host
3535
self.port = port
3636
self.megaservice = ServiceOrchestrator()
37+
self.endpoint = str(MegaServiceEndpoint.AVATAR_CHATBOT)
3738

3839
def add_remote_service(self):
3940
asr = MicroService(
@@ -97,14 +98,17 @@ async def handle_request(self, request: Request):
9798
return response
9899

99100
def start(self):
100-
super().__init__(
101-
megaservice=self.megaservice,
101+
self.service = MicroService(
102+
self.__class__.__name__,
103+
service_role=ServiceRoleType.MEGASERVICE,
102104
host=self.host,
103105
port=self.port,
104-
endpoint=str(MegaServiceEndpoint.AVATAR_CHATBOT),
106+
endpoint=self.endpoint,
105107
input_datatype=AudioChatCompletionRequest,
106108
output_datatype=ChatCompletionResponse,
107109
)
110+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
111+
self.service.start()
108112

109113

110114
if __name__ == "__main__":

CodeGen/codegen.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import asyncio
55
import os
66

7-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
7+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
8+
from comps.cores.mega.utils import handle_message
89
from comps.cores.proto.api_protocol import (
910
ChatCompletionRequest,
1011
ChatCompletionResponse,
@@ -21,11 +22,12 @@
2122
LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000))
2223

2324

24-
class CodeGenService(Gateway):
25+
class CodeGenService:
2526
def __init__(self, host="0.0.0.0", port=8000):
2627
self.host = host
2728
self.port = port
2829
self.megaservice = ServiceOrchestrator()
30+
self.endpoint = str(MegaServiceEndpoint.CODE_GEN)
2931

3032
def add_remote_service(self):
3133
llm = MicroService(
@@ -42,7 +44,7 @@ async def handle_request(self, request: Request):
4244
data = await request.json()
4345
stream_opt = data.get("stream", True)
4446
chat_request = ChatCompletionRequest.parse_obj(data)
45-
prompt = self._handle_message(chat_request.messages)
47+
prompt = handle_message(chat_request.messages)
4648
parameters = LLMParams(
4749
max_tokens=chat_request.max_tokens if chat_request.max_tokens else 1024,
4850
top_k=chat_request.top_k if chat_request.top_k else 10,
@@ -78,14 +80,17 @@ async def handle_request(self, request: Request):
7880
return ChatCompletionResponse(model="codegen", choices=choices, usage=usage)
7981

8082
def start(self):
81-
super().__init__(
82-
megaservice=self.megaservice,
83+
self.service = MicroService(
84+
self.__class__.__name__,
85+
service_role=ServiceRoleType.MEGASERVICE,
8386
host=self.host,
8487
port=self.port,
85-
endpoint=str(MegaServiceEndpoint.CODE_GEN),
88+
endpoint=self.endpoint,
8689
input_datatype=ChatCompletionRequest,
8790
output_datatype=ChatCompletionResponse,
8891
)
92+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
93+
self.service.start()
8994

9095

9196
if __name__ == "__main__":

CodeTrans/code_translation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import asyncio
55
import os
66

7-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
7+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
88
from comps.cores.proto.api_protocol import (
99
ChatCompletionRequest,
1010
ChatCompletionResponse,
@@ -20,11 +20,12 @@
2020
LLM_SERVICE_PORT = int(os.getenv("LLM_SERVICE_PORT", 9000))
2121

2222

23-
class CodeTransService(Gateway):
23+
class CodeTransService:
2424
def __init__(self, host="0.0.0.0", port=8000):
2525
self.host = host
2626
self.port = port
2727
self.megaservice = ServiceOrchestrator()
28+
self.endpoint = str(MegaServiceEndpoint.CODE_TRANS)
2829

2930
def add_remote_service(self):
3031
llm = MicroService(
@@ -77,14 +78,17 @@ async def handle_request(self, request: Request):
7778
return ChatCompletionResponse(model="codetrans", choices=choices, usage=usage)
7879

7980
def start(self):
80-
super().__init__(
81-
megaservice=self.megaservice,
81+
self.service = MicroService(
82+
self.__class__.__name__,
83+
service_role=ServiceRoleType.MEGASERVICE,
8284
host=self.host,
8385
port=self.port,
84-
endpoint=str(MegaServiceEndpoint.CODE_TRANS),
86+
endpoint=self.endpoint,
8587
input_datatype=ChatCompletionRequest,
8688
output_datatype=ChatCompletionResponse,
8789
)
90+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
91+
self.service.start()
8892

8993

9094
if __name__ == "__main__":

DocIndexRetriever/retrieval_tool.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
from typing import Union
88

9-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
9+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
1010
from comps.cores.proto.api_protocol import ChatCompletionRequest, EmbeddingRequest
1111
from comps.cores.proto.docarray import LLMParamsDoc, RerankedDoc, RerankerParms, RetrieverParms, TextDoc
1212
from fastapi import Request
@@ -21,11 +21,12 @@
2121
RERANK_SERVICE_PORT = os.getenv("RERANK_SERVICE_PORT", 8000)
2222

2323

24-
class RetrievalToolService(Gateway):
24+
class RetrievalToolService:
2525
def __init__(self, host="0.0.0.0", port=8000):
2626
self.host = host
2727
self.port = port
2828
self.megaservice = ServiceOrchestrator()
29+
self.endpoint = str(MegaServiceEndpoint.RETRIEVALTOOL)
2930

3031
def add_remote_service(self):
3132
embedding = MicroService(
@@ -116,14 +117,17 @@ def parser_input(data, TypeClass, key):
116117
return response
117118

118119
def start(self):
119-
super().__init__(
120-
megaservice=self.megaservice,
120+
self.service = MicroService(
121+
self.__class__.__name__,
122+
service_role=ServiceRoleType.MEGASERVICE,
121123
host=self.host,
122124
port=self.port,
123-
endpoint=str(MegaServiceEndpoint.RETRIEVALTOOL),
125+
endpoint=self.endpoint,
124126
input_datatype=Union[TextDoc, EmbeddingRequest, ChatCompletionRequest],
125127
output_datatype=Union[RerankedDoc, LLMParamsDoc],
126128
)
129+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
130+
self.service.start()
127131

128132
def add_remote_service_without_rerank(self):
129133
embedding = MicroService(

EdgeCraftRAG/chatqna.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
PIPELINE_SERVICE_HOST_IP = os.getenv("PIPELINE_SERVICE_HOST_IP", "127.0.0.1")
1010
PIPELINE_SERVICE_PORT = int(os.getenv("PIPELINE_SERVICE_PORT", 16010))
1111

12-
from comps import Gateway, MegaServiceEndpoint
12+
from comps import MegaServiceEndpoint, ServiceRoleType
1313
from comps.cores.proto.api_protocol import (
1414
ChatCompletionRequest,
1515
ChatCompletionResponse,
@@ -22,11 +22,12 @@
2222
from fastapi.responses import StreamingResponse
2323

2424

25-
class EdgeCraftRagService(Gateway):
25+
class EdgeCraftRagService:
2626
def __init__(self, host="0.0.0.0", port=16010):
2727
self.host = host
2828
self.port = port
2929
self.megaservice = ServiceOrchestrator()
30+
self.endpoint = str(MegaServiceEndpoint.CHAT_QNA)
3031

3132
def add_remote_service(self):
3233
edgecraftrag = MicroService(
@@ -72,14 +73,17 @@ async def handle_request(self, request: Request):
7273
return ChatCompletionResponse(model="edgecraftrag", choices=choices, usage=usage)
7374

7475
def start(self):
75-
super().__init__(
76-
megaservice=self.megaservice,
76+
self.service = MicroService(
77+
self.__class__.__name__,
78+
service_role=ServiceRoleType.MEGASERVICE,
7779
host=self.host,
7880
port=self.port,
79-
endpoint=str(MegaServiceEndpoint.CHAT_QNA),
81+
endpoint=self.endpoint,
8082
input_datatype=ChatCompletionRequest,
8183
output_datatype=ChatCompletionResponse,
8284
)
85+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
86+
self.service.start()
8387

8488

8589
if __name__ == "__main__":

GraphRAG/graphrag.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import os
77
import re
88

9-
from comps import Gateway, MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceType
9+
from comps import MegaServiceEndpoint, MicroService, ServiceOrchestrator, ServiceRoleType, ServiceType
10+
from comps.cores.mega.utils import handle_message
1011
from comps.cores.proto.api_protocol import (
1112
ChatCompletionRequest,
1213
ChatCompletionResponse,
@@ -127,14 +128,15 @@ def align_generator(self, gen, **kwargs):
127128
yield "data: [DONE]\n\n"
128129

129130

130-
class GraphRAGService(Gateway):
131+
class GraphRAGService:
131132
def __init__(self, host="0.0.0.0", port=8000):
132133
self.host = host
133134
self.port = port
134135
ServiceOrchestrator.align_inputs = align_inputs
135136
ServiceOrchestrator.align_outputs = align_outputs
136137
ServiceOrchestrator.align_generator = align_generator
137138
self.megaservice = ServiceOrchestrator()
139+
self.endpoint = str(MegaServiceEndpoint.GRAPH_RAG)
138140

139141
def add_remote_service(self):
140142
retriever = MicroService(
@@ -180,7 +182,7 @@ def parser_input(data, TypeClass, key):
180182
raise ValueError(f"Unknown request type: {data}")
181183
if chat_request is None:
182184
raise ValueError(f"Unknown request type: {data}")
183-
prompt = self._handle_message(chat_request.messages)
185+
prompt = handle_message(chat_request.messages)
184186
parameters = LLMParams(
185187
max_tokens=chat_request.max_tokens if chat_request.max_tokens else 1024,
186188
top_k=chat_request.top_k if chat_request.top_k else 10,
@@ -223,14 +225,17 @@ def parser_input(data, TypeClass, key):
223225
return ChatCompletionResponse(model="chatqna", choices=choices, usage=usage)
224226

225227
def start(self):
226-
super().__init__(
227-
megaservice=self.megaservice,
228+
self.service = MicroService(
229+
self.__class__.__name__,
230+
service_role=ServiceRoleType.MEGASERVICE,
228231
host=self.host,
229232
port=self.port,
230-
endpoint=str(MegaServiceEndpoint.GRAPH_RAG),
233+
endpoint=self.endpoint,
231234
input_datatype=ChatCompletionRequest,
232235
output_datatype=ChatCompletionResponse,
233236
)
237+
self.service.add_route(self.endpoint, self.handle_request, methods=["POST"])
238+
self.service.start()
234239

235240

236241
if __name__ == "__main__":

0 commit comments

Comments
 (0)