From 39d801f5b218e98e41377df62b41434865052e0f Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Thu, 3 Oct 2024 21:19:19 +0000 Subject: [PATCH 1/3] feat: update LLM generators to warn user about model name instead of raise error. --- bigframes/ml/llm.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index c12da01b54..e168a3c2da 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -154,8 +154,11 @@ def _create_bqml_model(self): ) if self.model_name not in _TEXT_GENERATOR_ENDPOINTS: - raise ValueError( - f"Model name {self.model_name} is not supported. We only support {', '.join(_TEXT_GENERATOR_ENDPOINTS)}." + warnings.warn( + f"Model name '{self.model_name}' is not supported. " + f"We currently support the following models: {', '.join(_TEXT_GENERATOR_ENDPOINTS)}. " + "However, model names can change, and the supported models may be outdated. " + "You can try using this model name, but it might result in unexpected errors." ) options = { @@ -484,8 +487,11 @@ def _create_bqml_model(self): ) if self.model_name not in _PALM2_EMBEDDING_GENERATOR_ENDPOINTS: - raise ValueError( - f"Model name {self.model_name} is not supported. We only support {', '.join(_PALM2_EMBEDDING_GENERATOR_ENDPOINTS)}." + warnings.warn( + f"Model name '{self.model_name}' is not supported. " + f"We currently support the following models: {', '.join(_PALM2_EMBEDDING_GENERATOR_ENDPOINTS)}. " + "However, model names can change, and the supported models may be outdated. " + "You can try using this model name, but it might result in unexpected errors." ) endpoint = ( @@ -644,8 +650,11 @@ def _create_bqml_model(self): ) if self.model_name not in _TEXT_EMBEDDING_ENDPOINTS: - raise ValueError( - f"Model name {self.model_name} is not supported. We only support {', '.join(_TEXT_EMBEDDING_ENDPOINTS)}." + warnings.warn( + f"Model name '{self.model_name}' is not supported. " + f"We currently support the following models: {', '.join(_TEXT_EMBEDDING_ENDPOINTS)}. " + "However, model names can change, and the supported models may be outdated. " + "You can try using this model name, but it might result in unexpected errors." ) options = { @@ -801,8 +810,11 @@ def _create_bqml_model(self): ) if self.model_name not in _GEMINI_ENDPOINTS: - raise ValueError( - f"Model name {self.model_name} is not supported. We only support {', '.join(_GEMINI_ENDPOINTS)}." + warnings.warn( + f"Model name '{self.model_name}' is not supported. " + f"We currently support the following models: {', '.join(_GEMINI_ENDPOINTS)}. " + "However, model names can change, and the supported models may be outdated. " + "You can try using this model name, but it might result in unexpected errors." ) options = {"endpoint": self.model_name} @@ -1118,8 +1130,11 @@ def _create_bqml_model(self): ) if self.model_name not in _CLAUDE_3_ENDPOINTS: - raise ValueError( - f"Model name {self.model_name} is not supported. We only support {', '.join(_CLAUDE_3_ENDPOINTS)}." + warnings.warn( + f"Model name '{self.model_name}' is not supported. " + f"We currently support the following models: {', '.join(_CLAUDE_3_ENDPOINTS)}. " + "However, model names can change, and the supported models may be outdated. " + "You can try using this model name, but it might result in unexpected errors." ) options = { From 0ac35493a586cb36e3d07afdbbee26f17c4ad154 Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Fri, 4 Oct 2024 06:36:36 +0000 Subject: [PATCH 2/3] update message and format --- bigframes/ml/llm.py | 47 ++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index e168a3c2da..d260c93b24 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -83,6 +83,13 @@ _ML_EMBED_TEXT_STATUS = "ml_embed_text_status" _ML_GENERATE_EMBEDDING_STATUS = "ml_generate_embedding_status" +_MODEL_NOT_SUPPORTED_WARNING = ( + "Model name '{model_name}' is not supported. " + "We are currently aware of the following models: {known_models}. " + "However, model names can change, and the supported models may be outdated. " + "You can try using this model name, but it might result in unexpected errors." +) + @typing_extensions.deprecated( "PaLM2TextGenerator is going to be deprecated. Use GeminiTextGenerator(https://cloud.google.com/python/docs/reference/bigframes/latest/bigframes.ml.llm.GeminiTextGenerator) instead. ", @@ -155,10 +162,10 @@ def _create_bqml_model(self): if self.model_name not in _TEXT_GENERATOR_ENDPOINTS: warnings.warn( - f"Model name '{self.model_name}' is not supported. " - f"We currently support the following models: {', '.join(_TEXT_GENERATOR_ENDPOINTS)}. " - "However, model names can change, and the supported models may be outdated. " - "You can try using this model name, but it might result in unexpected errors." + _MODEL_NOT_SUPPORTED_WARNING.format( + model_name=self.model_name, + known_models=", ".join(_TEXT_GENERATOR_ENDPOINTS), + ) ) options = { @@ -488,10 +495,10 @@ def _create_bqml_model(self): if self.model_name not in _PALM2_EMBEDDING_GENERATOR_ENDPOINTS: warnings.warn( - f"Model name '{self.model_name}' is not supported. " - f"We currently support the following models: {', '.join(_PALM2_EMBEDDING_GENERATOR_ENDPOINTS)}. " - "However, model names can change, and the supported models may be outdated. " - "You can try using this model name, but it might result in unexpected errors." + _MODEL_NOT_SUPPORTED_WARNING.format( + model_name=self.model_name, + known_models=", ".join(_PALM2_EMBEDDING_GENERATOR_ENDPOINTS), + ) ) endpoint = ( @@ -651,10 +658,10 @@ def _create_bqml_model(self): if self.model_name not in _TEXT_EMBEDDING_ENDPOINTS: warnings.warn( - f"Model name '{self.model_name}' is not supported. " - f"We currently support the following models: {', '.join(_TEXT_EMBEDDING_ENDPOINTS)}. " - "However, model names can change, and the supported models may be outdated. " - "You can try using this model name, but it might result in unexpected errors." + _MODEL_NOT_SUPPORTED_WARNING.format( + model_name=self.model_name, + known_models=", ".join(_TEXT_EMBEDDING_ENDPOINTS), + ) ) options = { @@ -811,10 +818,10 @@ def _create_bqml_model(self): if self.model_name not in _GEMINI_ENDPOINTS: warnings.warn( - f"Model name '{self.model_name}' is not supported. " - f"We currently support the following models: {', '.join(_GEMINI_ENDPOINTS)}. " - "However, model names can change, and the supported models may be outdated. " - "You can try using this model name, but it might result in unexpected errors." + _MODEL_NOT_SUPPORTED_WARNING.format( + model_name=self.model_name, + known_models=", ".join(_GEMINI_ENDPOINTS), + ) ) options = {"endpoint": self.model_name} @@ -1131,10 +1138,10 @@ def _create_bqml_model(self): if self.model_name not in _CLAUDE_3_ENDPOINTS: warnings.warn( - f"Model name '{self.model_name}' is not supported. " - f"We currently support the following models: {', '.join(_CLAUDE_3_ENDPOINTS)}. " - "However, model names can change, and the supported models may be outdated. " - "You can try using this model name, but it might result in unexpected errors." + _MODEL_NOT_SUPPORTED_WARNING.format( + model_name=self.model_name, + known_models=", ".join(_CLAUDE_3_ENDPOINTS), + ) ) options = { From 035882c39424b522bf0faf815ff90ac71f87e3ae Mon Sep 17 00:00:00 2001 From: Huan Chen Date: Fri, 4 Oct 2024 06:39:08 +0000 Subject: [PATCH 3/3] update message and format --- bigframes/ml/llm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigframes/ml/llm.py b/bigframes/ml/llm.py index d260c93b24..3920da6c71 100644 --- a/bigframes/ml/llm.py +++ b/bigframes/ml/llm.py @@ -87,7 +87,7 @@ "Model name '{model_name}' is not supported. " "We are currently aware of the following models: {known_models}. " "However, model names can change, and the supported models may be outdated. " - "You can try using this model name, but it might result in unexpected errors." + "You should use this model name only if you are sure that it is supported in BigQuery." )