-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix pydantic BaseModel in/out in dataflow (#818)
* fix protocol in/out supported types * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3473bfb
commit 02c3dfe
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import unittest | ||
|
||
from comps import ServiceOrchestrator, opea_microservices, register_microservice | ||
from comps.cores.proto.api_protocol import ChatCompletionRequest | ||
|
||
|
||
@register_microservice(name="s1", host="0.0.0.0", port=8083, endpoint="/v1/add") | ||
async def s1_add(request: ChatCompletionRequest) -> ChatCompletionRequest: | ||
# support pydantic protocol message object in/out in data flow | ||
return request | ||
|
||
|
||
class TestServiceOrchestratorProtocol(unittest.IsolatedAsyncioTestCase): | ||
def setUp(self): | ||
self.s1 = opea_microservices["s1"] | ||
self.s1.start() | ||
|
||
self.service_builder = ServiceOrchestrator() | ||
|
||
self.service_builder.add(opea_microservices["s1"]) | ||
|
||
def tearDown(self): | ||
self.s1.stop() | ||
|
||
async def test_schedule(self): | ||
input_data = ChatCompletionRequest(messages=[{"role": "user", "content": "What's up man?"}], seed=None) | ||
result_dict, _ = await self.service_builder.schedule(initial_inputs=input_data) | ||
self.assertEqual( | ||
result_dict[self.s1.name]["messages"], | ||
[{"role": "user", "content": "What's up man?"}], | ||
) | ||
self.assertEqual(result_dict[self.s1.name]["seed"], None) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |