-
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 all commits
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) | ||
Comment on lines
+15
to
22
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("default") |
||
|
@@ -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,30 +40,26 @@ 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: The model 'invalid-model' doesn't exist " | ||
"Unsupported model: The model 'invalid_model' doesn't exist " | ||
"or is not supported yet." | ||
), | ||
): | ||
google_vertexai._generate_text("Test prompt") | ||
|
||
def test_validate_without_model(self, google_vertexai: GoogleVertexAI): | ||
google_vertexai.model = None | ||
with pytest.raises(ValueError, match="model is required."): | ||
google_vertexai._validate() | ||
GoogleVertexAI(project_id, location, model) |
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
UnsupportedModelError
is raised if the providedmodel
is not supported. This is a good practice as it provides a clear error message to the user. However, it would be helpful to include a list of supported models in the error message to guide the user.