-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
chore(llm): major refactor of VertexAI models #636
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,11 @@ def __init__(self, result: str): | |
|
||
|
||
class TestGoogleVertexAI: | ||
def test_init_with_default_model(self): | ||
def test_init_with_default_model(self, mocker): | ||
mocker.patch( | ||
"vertexai.preview.language_models.TextGenerationModel.from_pretrained", | ||
return_value="Test", | ||
) | ||
project_id = "your_project_id" | ||
location = "northamerica-northeast1" | ||
vertexai_instance = GoogleVertexAI(project_id, location) | ||
|
@@ -21,7 +25,11 @@ def test_init_with_default_model(self): | |
assert vertexai_instance.project_id == project_id | ||
assert vertexai_instance.location == location | ||
|
||
def test_init_with_custom_model(self): | ||
def test_init_with_custom_model(self, mocker): | ||
mocker.patch( | ||
"vertexai.preview.language_models.CodeGenerationModel.from_pretrained", | ||
return_value="Test", | ||
) | ||
project_id = "test-project" | ||
location = "northamerica-northeast1" | ||
custom_model = "code-bison@001" | ||
Comment on lines
+28
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, the mock_from_pretrained = mocker.patch(
"vertexai.preview.language_models.CodeGenerationModel.from_pretrained",
return_value="Test",
)
# ... rest of the test code ...
mock_from_pretrained.assert_called_once_with(custom_model) |
||
|
@@ -32,24 +40,21 @@ def test_init_with_custom_model(self): | |
assert vertexai_instance.project_id == project_id | ||
assert vertexai_instance.location == location | ||
|
||
@pytest.fixture | ||
def google_vertexai(self): | ||
# Create an instance of YourClass for testing | ||
def test_validate_with_model(self, mocker): | ||
mocker.patch( | ||
"vertexai.preview.language_models.TextGenerationModel.from_pretrained", | ||
return_value="Test", | ||
) | ||
model = "text-bison@001" | ||
project_id = "test-project" | ||
location = "northamerica-northeast1" | ||
custom_model = "code-bison@001" | ||
return GoogleVertexAI(project_id, location, custom_model) | ||
|
||
def test_validate_with_model(self, google_vertexai: GoogleVertexAI): | ||
google_vertexai.model = "text-bison@001" | ||
google_vertexai._validate() # Should not raise any errors | ||
llm = GoogleVertexAI(project_id, location, model) | ||
llm._validate() # Should not raise any errors | ||
Comment on lines
+43
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock_from_pretrained = mocker.patch(
"vertexai.preview.language_models.TextGenerationModel.from_pretrained",
return_value="Test",
)
# ... rest of the test code ...
mock_from_pretrained.assert_called_once_with(model) |
||
|
||
def test_validate_with_invalid_model(self, google_vertexai: GoogleVertexAI): | ||
google_vertexai.model = "invalid-model" | ||
def test_validate_with_invalid_model(self): | ||
model = "invalid_model" | ||
project_id = "test-project" | ||
location = "northamerica-northeast1" | ||
with pytest.raises(UnsupportedModelError, match="Unsupported model"): | ||
google_vertexai._generate_text("Test prompt") | ||
GoogleVertexAI(project_id, location, model) | ||
|
||
def test_validate_without_model(self, google_vertexai: GoogleVertexAI): | ||
google_vertexai.model = None | ||
with pytest.raises(ValueError, match="model is required."): | ||
google_vertexai._validate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
mocker.patch
method is used to mock thefrom_pretrained
method of theTextGenerationModel
class. This is a good practice for unit testing as it isolates the method being tested from external dependencies. However, it would be beneficial to verify that the mocked method is called with the expected arguments. This can be done by storing the mock object and asserting that it was called with the correct arguments.