GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: async call bug in CodeChatModel.send_message_async method · googleapis/python-aiplatform@fcf05cb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/unit/aiplatform
    • test_language_models.py
  • vertexai/language_models
    • _language_models.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/unit/aiplatform/test_language_models.py‎

Copy file name to clipboardExpand all lines: tests/unit/aiplatform/test_language_models.py
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,54 @@ def test_code_chat_model_send_message_with_multiple_candidates(self):
31823182
assert chat.message_history[1].author == chat.MODEL_AUTHOR
31833183
assert chat.message_history[1].content == expected_candidate_0
31843184

3185+
async def test_code_chat_model_send_message_async(self):
3186+
"""Tests the send_message_async method for code chat model."""
3187+
aiplatform.init(
3188+
project=_TEST_PROJECT,
3189+
location=_TEST_LOCATION,
3190+
)
3191+
with mock.patch.object(
3192+
target=model_garden_service_client.ModelGardenServiceClient,
3193+
attribute="get_publisher_model",
3194+
return_value=gca_publisher_model.PublisherModel(
3195+
_CODECHAT_BISON_PUBLISHER_MODEL_DICT
3196+
),
3197+
):
3198+
model = language_models.CodeChatModel.from_pretrained("codechat-bison@001")
3199+
chat = model.start_chat()
3200+
3201+
gca_predict_response = gca_prediction_service.PredictResponse()
3202+
gca_predict_response.predictions.append(
3203+
_TEST_CHAT_GENERATION_MULTI_CANDIDATE_PREDICTION
3204+
)
3205+
with mock.patch.object(
3206+
target=prediction_service_async_client.PredictionServiceAsyncClient,
3207+
attribute="predict",
3208+
return_value=gca_predict_response,
3209+
autospec=True,
3210+
):
3211+
message_text = "Are my favorite movies based on a book series?"
3212+
expected_response_candidates = (
3213+
_TEST_CHAT_GENERATION_MULTI_CANDIDATE_PREDICTION["candidates"]
3214+
)
3215+
expected_candidate_0 = expected_response_candidates[0]["content"]
3216+
expected_candidate_1 = expected_response_candidates[1]["content"]
3217+
3218+
response = await chat.send_message_async(
3219+
message=message_text,
3220+
)
3221+
# The service can return a different number of candidates.
3222+
assert response.text == expected_candidate_0
3223+
assert len(response.candidates) == 2
3224+
assert response.candidates[0].text == expected_candidate_0
3225+
assert response.candidates[1].text == expected_candidate_1
3226+
3227+
assert len(chat.message_history) == 2
3228+
assert chat.message_history[0].author == chat.USER_AUTHOR
3229+
assert chat.message_history[0].content == message_text
3230+
assert chat.message_history[1].author == chat.MODEL_AUTHOR
3231+
assert chat.message_history[1].content == expected_candidate_0
3232+
31853233
def test_code_chat_model_send_message_streaming(self):
31863234
"""Tests the chat generation model."""
31873235
aiplatform.init(
Collapse file

‎vertexai/language_models/_language_models.py‎

Copy file name to clipboardExpand all lines: vertexai/language_models/_language_models.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2558,12 +2558,13 @@ async def send_message_async(
25582558
A `MultiCandidateTextGenerationResponse` object that contains the
25592559
text produced by the model.
25602560
"""
2561-
return super().send_message_async(
2561+
response = await super().send_message_async(
25622562
message=message,
25632563
max_output_tokens=max_output_tokens,
25642564
temperature=temperature,
25652565
candidate_count=candidate_count,
25662566
)
2567+
return response
25672568

25682569
def send_message_streaming(
25692570
self,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.