Skip to content

[TP-1781] Add test for MiniCPM-o-2_6-language model #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ def metadata(pat: bool = False) -> Tuple[Tuple[str, str], Tuple[str, str]]:
)


def grpc_channel(func):
"""
A decorator that runs the test using the gRPC channel.
:param func: The test function.
:return: A function wrapper.
"""

def func_wrapper():
if os.getenv("CLARIFAI_GRPC_INSECURE", "False").lower() in ("true", "1", "t"):
channel = ClarifaiChannel.get_insecure_grpc_channel(port=443)
else:
channel = ClarifaiChannel.get_grpc_channel()
func(channel)

return func_wrapper


def both_channels(func):
"""
A decorator that runs the test first using the gRPC channel and then using the JSON channel.
Expand All @@ -73,9 +90,10 @@ def both_channels(func):
"""

def func_wrapper():
channel = ClarifaiChannel.get_grpc_channel()
if os.getenv("CLARIFAI_GRPC_INSECURE", "False").lower() in ("true", "1", "t"):
channel = ClarifaiChannel.get_insecure_grpc_channel(port=443)
else:
channel = ClarifaiChannel.get_grpc_channel()
func(channel)

channel = ClarifaiChannel.get_json_channel()
Expand Down Expand Up @@ -335,6 +353,25 @@ def post_model_outputs_and_maybe_allow_retries(
return response


def _generate_model_outputs(
stub: service_pb2_grpc.V2Stub,
request: service_pb2.PostModelOutputsRequest,
metadata: Tuple,
):
is_model_loaded = False
for i in range(1, MAX_PREDICT_ATTEMPTS + 1):
response_iterator = stub.GenerateModelOutputs(request, metadata=metadata)
for response in response_iterator:
if not is_model_loaded and response.status.code == status_code_pb2.MODEL_LOADING:
print(f"Model {request.model_id} is still loading...")
time.sleep(15)
break
is_model_loaded = True
yield response
if is_model_loaded:
break


async def async_post_model_outputs_and_maybe_allow_retries(
stub: service_pb2_grpc.V2Stub,
request: service_pb2.PostModelOutputsRequest,
Expand Down
5 changes: 5 additions & 0 deletions tests/public_models/public_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
TEXT_SENTIMENT_MODEL_ID = "multilingual-uncased-sentiment" # bert-based
TEXT_MULTILINGUAL_MODERATION_MODEL_ID = "bdcedc0f8da58c396b7df12f634ef923"

TEXT_MINI_CPM_MODEL_ID = "MiniCPM-o-2_6-language"

TRANSLATION_TEST_DATA = {
"ROMANCE": "No me apetece nada estudiar esta noche",
Expand Down Expand Up @@ -212,6 +213,10 @@
),
]

TEXT_LLM_MODEL_TITLE_IDS_TUPLE = [
("multimodal large language model", TEXT_MINI_CPM_MODEL_ID, "miniCPM", "openbmb")
]

# title, model_id, text, app, user
TEXT_FB_TRANSLATION_MODEL_TITLE_ID_DATA_TUPLE = []
TEXT_HELSINKI_TRANSLATION_MODEL_TITLE_ID_DATA_TUPLE = []
Expand Down
57 changes: 57 additions & 0 deletions tests/public_models/test_public_models_predicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
GENERAL_MODEL_ID,
MAIN_APP_ID,
MAIN_APP_USER_ID,
_generate_model_outputs,
async_post_model_outputs_and_maybe_allow_retries,
async_raise_on_failure,
asyncio_channel,
both_channels,
grpc_channel,
metadata,
post_model_outputs_and_maybe_allow_retries,
raise_on_failure,
Expand All @@ -35,6 +37,7 @@
MULTIMODAL_MODEL_TITLE_AND_IDS,
TEXT_FB_TRANSLATION_MODEL_TITLE_ID_DATA_TUPLE,
TEXT_HELSINKI_TRANSLATION_MODEL_TITLE_ID_DATA_TUPLE,
TEXT_LLM_MODEL_TITLE_IDS_TUPLE,
TEXT_MODEL_TITLE_IDS_TUPLE,
TRANSLATION_TEST_DATA,
)
Expand Down Expand Up @@ -120,6 +123,60 @@ def test_text_predict_on_public_models(channel):
)


@grpc_channel
def test_text_predict_on_public_llm_models(channel):
stub = service_pb2_grpc.V2Stub(channel)

for title, model_id, app_id, user_id in TEXT_LLM_MODEL_TITLE_IDS_TUPLE:
request = service_pb2.PostModelOutputsRequest(
user_app_id=resources_pb2.UserAppIDSet(user_id=user_id, app_id=app_id),
model_id=model_id,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
parts=[
resources_pb2.Part(
id="prompt",
data=resources_pb2.Data(
string_value=TRANSLATION_TEST_DATA["EN"],
),
),
resources_pb2.Part(
id="max_tokens",
data=resources_pb2.Data(
int_value=10,
),
),
resources_pb2.Part(
id="temperature",
data=resources_pb2.Data(
float_value=0.7,
),
),
resources_pb2.Part(
id="top_p",
data=resources_pb2.Data(
float_value=0.95,
),
),
]
)
)
],
)
response_iterator = _generate_model_outputs(stub, request, metadata(pat=True))

responses_count = 0
for response in response_iterator:
responses_count += 1
raise_on_failure(
response,
custom_message=f"Text predict failed for the {title} model (ID: {model_id}).",
)

assert responses_count > 0


@asyncio_channel
async def test_text_predict_on_public_models_async(channel):
"""Test non translation text/nlp models.
Expand Down
Loading