Skip to content
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

Add TGISBackend.register_model_connection() method #55

Merged
merged 16 commits into from
Jun 7, 2024

Conversation

mynhardtburger
Copy link
Contributor

@mynhardtburger mynhardtburger commented Jun 5, 2024

Added TGISBackend.register_model_connection() to allow for registering a new TGISConnection model connection with either the default connection, a custom provided connection, or a mixture where the custom provided connection is enhanced by populating the missing settings with those from the default connection.

If the connection already exists, it does nothing.

Additionally the following refactoring was done:

  • Refactor common model connection testing code into TGISBackend._test_connection()
  • Refactor common state update logic into TGISBackend._safely_update_state() to ensure thread safe updates to the _model_connections and _remote_models_cfg dictionaries.

Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
@mynhardtburger
Copy link
Contributor Author

@gabe-l-hart FYI

Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Signed-off-by: Mynhardt Burger <[email protected]>
Copy link
Contributor

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few tiny NITs, but otherwise this looks great!

caikit_tgis_backend/tgis_backend.py Show resolved Hide resolved
"""Create an instance from a connection template and a model_id"""
hostname = config.get(cls.HOSTNAME_KEY)
if hostname:
hostname = hostname.format(
**{
assert isinstance(hostname, str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -681,6 +680,103 @@ def test_tgis_backend_config_load_prompt_artifacts():
tgis_be.load_prompt_artifacts("buz", prompt_id1, source_files[0])


def test_tgis_backend_register_model_connection():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to consolidate these two tests with @pytest.mark.parametrize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little bug fix to avoid mutating the base connection dict

new_conn_cfg = self._base_connection_cfg
else:
if fill_with_defaults:
new_conn_cfg = self._base_connection_cfg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be self._base_connection_cfg.copy otherwise the update below will mutate self._base_connection_cfg. Since there is nesting, it should actually probably be copy.deepcopy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. fixed.

tests/test_tgis_backend.py Show resolved Hide resolved
Copy link
Contributor

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks Mynhardt!

@gabe-l-hart gabe-l-hart merged commit ddbccd3 into caikit:main Jun 7, 2024
6 checks passed
@mynhardtburger mynhardtburger deleted the register_connection branch June 7, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants