extensions_class.py
Source: sunholo/vertex/extensions_class.py
Classes
VertexAIExtensions
Example
from sunholo.vertex import VertexAIExtensions
vex = VertexAIExtensions(project_id='your-project')
vex.list_extensions()
# [{'resource_name': 'projects/374404277595/locations/us-central1/extensions/770924776838397952',
# 'display_name': 'Code Interpreter',
# 'description': 'N/A'}]
Creating an extension example as per: https://cloud.google.com/vertex-ai/generative-ai/docs/extensions/create-extension
## validates before upload
vex.upload_openapi_file("your-extension-name.yaml")
vex.openapi_file_gcs
# 'gs://your-extensions-bucket/your-extension-name.yaml'
## load in examples to be used by creation later
vex.load_tool_use_examples('your-examples.yaml')
vex.create_extension(
"My New Extension",
description="Querying the VAC above my database",
service_account='sa-serviceaccount@my-project.iam.gserviceaccount.com')
Call the extension
operation_params = {"input": {"question":"This needs to be in same schema as your openapi spec"}
vex.execute_extension("an_operation_id_from_your_openai_spec",
operation_params = operation_params)
-
init(self, project_id=None)
- Initialize self. See help(type(self)) for accurate signature.
-
create_extension(self, display_name: str, description: str, open_api_file: str = None, tool_example_file: str = None, runtime_config: dict = None, service_account: str = None, bucket_name: str = None, vac: str = None)
- No docstring available.
-
create_extension_manifest(self, display_name, description, open_api_gcs_uri: str, service_account: str)
- No docstring available.
-
execute_code_extension(self, query: str, filenames: list[str] = None, gcs_files: list[str] = None, bucket_name: str = None)
- No docstring available.
-
execute_extension(self, operation_id: str, operation_params: dict, extension_id: str = None, extension_display_name: str = None, vac: str = None)
- No docstring available.
-
get_auth_token(self)
- No docstring available.
-
get_extension(self, extension_id: str = None, extension_display_name: str = None)
- Resolves the extension_id from the Display Name if not given.
Returns: Extension object
-
get_openapi_spec(self, extension_id: str = None, extension_display_name: str = None)
- Gets the openapi spec file for an extension
-
list_extensions(self)
- No docstring available.
-
load_tool_use_examples(self, filename: str)
- No docstring available.
-
parse_files_to_html(self, outputFiles, save_files_locally=True)
- No docstring available.
-
process_response(self, response: dict, save_file_name=None) -> str
- No docstring available.
-
update_tool_use_examples_via_patch(self)
- No docstring available.
-
upload_openapi_file(self, filename: str, extension_name: str, vac: str = None)
- No docstring available.
-
upload_to_gcs(self, filename)
- No docstring available.
-
validate_extension_id(self, ext_id: str)
- Ensures the passed string fits the criteria for an extension ID. If not, changes it so it will be.
Criteria:
- Length should be 4-63 characters.
- Valid characters are lowercase letters, numbers, and hyphens ("-").
- Should start with a number or a lowercase letter.
Args: ext_id (str): The extension ID to validate and correct.
Returns: str: The validated and corrected extension ID.
- validate_openapi(self, filename)
- No docstring available.