Skip to content

Commit d8b9068

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

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/f5_ai_gateway_sdk/processor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ 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(
230+
inspect.unwrap(cls.process)
231+
):
230232
# we don't want to add async capabilities to the deprecated function
231233
raise TypeError(
232234
f"Cannot create concrete class {cls.__name__}. "

tests/test_processor.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,49 @@ 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(
853+
self, prompt, metadata, parameters, request
854+
) -> Result:
855+
prompt.messages.append(Message(content="Test message"))
856+
return Result(modified_prompt=prompt)
857+
858+
processor = AsyncInputProcessor()
859+
860+
response = await processor.handle_request(request)
861+
862+
self.assertStatusCodeEqual(response, HTTP_200_OK)
863+
864+
content = await self.buffer_response(response)
865+
multipart = MultipartDecoderHelper(
866+
content=content, content_type=response.headers["Content-Type"]
867+
)
868+
869+
self.assertTrue(
870+
multipart.has_prompt(),
871+
"prompt should be in the response",
872+
)
873+
874+
multipart_prompt = multipart.prompt
875+
assert "Test message" in multipart_prompt.content
876+
834877
def test_async_process_implemented(self):
835878
expected_message = (
836879
"Cannot create concrete class AsyncProcessImplementedProcessor. "

0 commit comments

Comments
 (0)