Skip to content

Commit 93b5719

Browse files
Apply suggestions from code review
Co-authored-by: andrey-zelenkov <[email protected]>
1 parent 0fabf26 commit 93b5719

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/f5_ai_gateway_sdk/processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def __init_subclass__(cls, **kwargs):
226226
"The DEPRECATED 'process' method must not be implemented "
227227
"alongside 'process_input' or 'process_response'."
228228
)
229-
if is_process_overridden and inspect.iscoroutinefunction(cls.process):
229+
if is_process_overridden and inspect.iscoroutinefunction(inspect.unwrap(cls.process)):
230230
# we don't want to add async capabilities to the deprecated function
231231
raise TypeError(
232232
f"Cannot create concrete class {cls.__name__}. "

tests/test_processor.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,47 @@ async def process_response(self):
831831

832832
self.assertIsNotNone(AsyncImplementedProcessor())
833833

834+
async def test_async_message(self):
835+
prompt = TEST_REQ_INPUT.model_dump_json()
836+
metadata = {"key": "value"}
837+
request = fake_multipart_request(
838+
prompt=prompt,
839+
metadata=metadata,
840+
parameters={"modify": True, "annotate": True},
841+
)
842+
843+
class AsyncInputProcessor(Processor):
844+
def __init__(self):
845+
super().__init__(
846+
name="async-input-processor",
847+
namespace="fake",
848+
signature=INPUT_ONLY_SIGNATURE,
849+
version="v1",
850+
)
851+
852+
async def process_input(self, prompt, metadata, parameters, request) -> Result:
853+
prompt.messages.append(Message(content="Test message"))
854+
return Result(modified_prompt=prompt)
855+
856+
processor = AsyncInputProcessor()
857+
858+
response = await processor.handle_request(request)
859+
860+
self.assertStatusCodeEqual(response, HTTP_200_OK)
861+
862+
content = await self.buffer_response(response)
863+
multipart = MultipartDecoderHelper(
864+
content=content, content_type=response.headers["Content-Type"]
865+
)
866+
867+
self.assertTrue(
868+
multipart.has_prompt(),
869+
"prompt should be in the response",
870+
)
871+
872+
multipart_prompt = multipart.prompt
873+
assert "Test message" in multipart_prompt.content
874+
834875
def test_async_process_implemented(self):
835876
expected_message = (
836877
"Cannot create concrete class AsyncProcessImplementedProcessor. "

0 commit comments

Comments
 (0)