From 58cfbfa7c2c77b6f28188a597d1aa7fe60e3a8c6 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Mon, 18 Nov 2024 17:37:17 -0500 Subject: [PATCH 1/5] upddate in groq models groq models updated --- .../langflow/base/models/groq_constants.py | 21 +++++++++++++- .../base/langflow/components/models/groq.py | 28 ++----------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/backend/base/langflow/base/models/groq_constants.py b/src/backend/base/langflow/base/models/groq_constants.py index 1f460f60a64c..c90b015268ff 100644 --- a/src/backend/base/langflow/base/models/groq_constants.py +++ b/src/backend/base/langflow/base/models/groq_constants.py @@ -1 +1,20 @@ -MODEL_NAMES = ["llama3-8b-8192", "llama3-70b-8192", "mixtral-8x7b-32768", "gemma-7b-it", "gemma2-9b-it"] +GROQ_MODELS = [ + "distil-whisper-large-v3-en", # HuggingFace + "gemma2-9b-it", # Google + "gemma-7b-it", # Google + "llama3-groq-70b-8192-tool-use-preview", # Groq + "llama3-groq-8b-8192-tool-use-preview", # Groq + "llama-3.1-70b-versatile", # Meta + "llama-3.1-8b-instant", # Meta + "llama-3.2-1b-preview", # Meta + "llama-3.2-3b-preview", # Meta + "llama-3.2-11b-vision-preview",# Meta + "llama-3.2-90b-vision-preview",# Meta + "llama-guard-3-8b", # Meta + "llama3-70b-8192", # Meta + "llama3-8b-8192", # Meta + "mixtral-8x7b-32768", # Mistral + "whisper-large-v3", # OpenAI + "whisper-large-v3-turbo", # OpenAI +] +MODEL_NAMES = GROQ_MODELS # reverse compatibility diff --git a/src/backend/base/langflow/components/models/groq.py b/src/backend/base/langflow/components/models/groq.py index 81a97b6fb0c3..d364fdf83266 100644 --- a/src/backend/base/langflow/components/models/groq.py +++ b/src/backend/base/langflow/components/models/groq.py @@ -7,7 +7,7 @@ from langflow.field_typing import LanguageModel from langflow.inputs.inputs import HandleInput from langflow.io import DropdownInput, FloatInput, IntInput, MessageTextInput, SecretStrInput - +from langflow.base.models.groq_constants import GROQ_MODELS class GroqModel(LCModelComponent): display_name: str = "Groq" @@ -48,8 +48,8 @@ class GroqModel(LCModelComponent): name="model_name", display_name="Model", info="The name of the model to use.", - options=[], - refresh_button=True, + options=GROQ_MODELS, + value="llama-3.1-8b-instant", ), HandleInput( name="output_parser", @@ -60,28 +60,6 @@ class GroqModel(LCModelComponent): ), ] - def get_models(self) -> list[str]: - api_key = self.groq_api_key - base_url = self.groq_api_base or "https://api.groq.com" - url = f"{base_url}/openai/v1/models" - - headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} - - try: - response = requests.get(url, headers=headers, timeout=10) - response.raise_for_status() - model_list = response.json() - return [model["id"] for model in model_list.get("data", [])] - except requests.RequestException as e: - self.status = f"Error fetching models: {e}" - return [] - - @override - def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None): - if field_name in {"groq_api_key", "groq_api_base", "model_name"}: - models = self.get_models() - build_config["model_name"]["options"] = models - return build_config def build_model(self) -> LanguageModel: # type: ignore[type-var] groq_api_key = self.groq_api_key From a9634e451b41f9dae0aebc2bf24ace84b9000683 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 22:39:31 +0000 Subject: [PATCH 2/5] [autofix.ci] apply automated fixes --- .../langflow/base/models/groq_constants.py | 30 +++++++++---------- .../base/langflow/components/models/groq.py | 6 ++-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/backend/base/langflow/base/models/groq_constants.py b/src/backend/base/langflow/base/models/groq_constants.py index c90b015268ff..929976a5f4e9 100644 --- a/src/backend/base/langflow/base/models/groq_constants.py +++ b/src/backend/base/langflow/base/models/groq_constants.py @@ -1,20 +1,20 @@ GROQ_MODELS = [ "distil-whisper-large-v3-en", # HuggingFace - "gemma2-9b-it", # Google - "gemma-7b-it", # Google + "gemma2-9b-it", # Google + "gemma-7b-it", # Google "llama3-groq-70b-8192-tool-use-preview", # Groq - "llama3-groq-8b-8192-tool-use-preview", # Groq - "llama-3.1-70b-versatile", # Meta - "llama-3.1-8b-instant", # Meta - "llama-3.2-1b-preview", # Meta - "llama-3.2-3b-preview", # Meta - "llama-3.2-11b-vision-preview",# Meta - "llama-3.2-90b-vision-preview",# Meta - "llama-guard-3-8b", # Meta - "llama3-70b-8192", # Meta - "llama3-8b-8192", # Meta - "mixtral-8x7b-32768", # Mistral - "whisper-large-v3", # OpenAI - "whisper-large-v3-turbo", # OpenAI + "llama3-groq-8b-8192-tool-use-preview", # Groq + "llama-3.1-70b-versatile", # Meta + "llama-3.1-8b-instant", # Meta + "llama-3.2-1b-preview", # Meta + "llama-3.2-3b-preview", # Meta + "llama-3.2-11b-vision-preview", # Meta + "llama-3.2-90b-vision-preview", # Meta + "llama-guard-3-8b", # Meta + "llama3-70b-8192", # Meta + "llama3-8b-8192", # Meta + "mixtral-8x7b-32768", # Mistral + "whisper-large-v3", # OpenAI + "whisper-large-v3-turbo", # OpenAI ] MODEL_NAMES = GROQ_MODELS # reverse compatibility diff --git a/src/backend/base/langflow/components/models/groq.py b/src/backend/base/langflow/components/models/groq.py index d364fdf83266..979a05581890 100644 --- a/src/backend/base/langflow/components/models/groq.py +++ b/src/backend/base/langflow/components/models/groq.py @@ -1,13 +1,12 @@ -import requests from langchain_groq import ChatGroq from pydantic.v1 import SecretStr -from typing_extensions import override +from langflow.base.models.groq_constants import GROQ_MODELS from langflow.base.models.model import LCModelComponent from langflow.field_typing import LanguageModel from langflow.inputs.inputs import HandleInput from langflow.io import DropdownInput, FloatInput, IntInput, MessageTextInput, SecretStrInput -from langflow.base.models.groq_constants import GROQ_MODELS + class GroqModel(LCModelComponent): display_name: str = "Groq" @@ -60,7 +59,6 @@ class GroqModel(LCModelComponent): ), ] - def build_model(self) -> LanguageModel: # type: ignore[type-var] groq_api_key = self.groq_api_key model_name = self.model_name From bc0e16f3efd4806e54d7d9946d486308a7dc68f3 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Mon, 18 Nov 2024 17:48:11 -0500 Subject: [PATCH 3/5] Update model_input_constants.py remove groq prefix --- src/backend/base/langflow/base/models/model_input_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/base/langflow/base/models/model_input_constants.py b/src/backend/base/langflow/base/models/model_input_constants.py index 00e98095e31a..42a82a8b47db 100644 --- a/src/backend/base/langflow/base/models/model_input_constants.py +++ b/src/backend/base/langflow/base/models/model_input_constants.py @@ -64,7 +64,7 @@ def create_input_fields_dict(inputs, prefix): "prefix": "", "component_class": OpenAIModelComponent(), }, - "Groq": {"fields": GROQ_FIELDS, "inputs": GROQ_INPUTS, "prefix": "groq_", "component_class": GroqModel()}, + "Groq": {"fields": GROQ_FIELDS, "inputs": GROQ_INPUTS, "prefix": "", "component_class": GroqModel()}, "Anthropic": { "fields": ANTHROPIC_FIELDS, "inputs": ANTHROPIC_INPUTS, From da69690f28058af8ea481f52f1287374f10d1313 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Mon, 18 Nov 2024 19:49:29 -0500 Subject: [PATCH 4/5] Update groq.py updated Groq Model list to be also a backup list if the API call fails, also at start. --- .../base/langflow/components/models/groq.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/backend/base/langflow/components/models/groq.py b/src/backend/base/langflow/components/models/groq.py index 979a05581890..df39264df789 100644 --- a/src/backend/base/langflow/components/models/groq.py +++ b/src/backend/base/langflow/components/models/groq.py @@ -1,5 +1,7 @@ +import requests from langchain_groq import ChatGroq from pydantic.v1 import SecretStr +from typing_extensions import override from langflow.base.models.groq_constants import GROQ_MODELS from langflow.base.models.model import LCModelComponent @@ -49,6 +51,7 @@ class GroqModel(LCModelComponent): info="The name of the model to use.", options=GROQ_MODELS, value="llama-3.1-8b-instant", + refresh_button=True, ), HandleInput( name="output_parser", @@ -59,6 +62,30 @@ class GroqModel(LCModelComponent): ), ] + def get_models(self) -> list[str]: + api_key = self.groq_api_key + base_url = self.groq_api_base or "https://api.groq.com" + url = f"{base_url}/openai/v1/models" + + headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} + + try: + response = requests.get(url, headers=headers, timeout=10) + response.raise_for_status() + model_list = response.json() + return [model["id"] for model in model_list.get("data", [])] + except requests.RequestException as e: + self.status = f"Error fetching models: {e}" + return GROQ_MODELS + + @override + def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None): + if field_name in {"groq_api_key", "groq_api_base", "model_name"}: + print("Updating build config in Groq") + models = self.get_models() + build_config["model_name"]["options"] = models + return build_config + def build_model(self) -> LanguageModel: # type: ignore[type-var] groq_api_key = self.groq_api_key model_name = self.model_name @@ -77,3 +104,5 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var] api_key=SecretStr(groq_api_key).get_secret_value(), streaming=stream, ) + + From 1ce5be74fd9cab5bf1cbb8d053e9852a6f690696 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Mon, 18 Nov 2024 19:50:11 -0500 Subject: [PATCH 5/5] Update groq.py format issue solved --- src/backend/base/langflow/components/models/groq.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/backend/base/langflow/components/models/groq.py b/src/backend/base/langflow/components/models/groq.py index df39264df789..f4fda80f7e3d 100644 --- a/src/backend/base/langflow/components/models/groq.py +++ b/src/backend/base/langflow/components/models/groq.py @@ -81,7 +81,6 @@ def get_models(self) -> list[str]: @override def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None): if field_name in {"groq_api_key", "groq_api_base", "model_name"}: - print("Updating build config in Groq") models = self.get_models() build_config["model_name"]["options"] = models return build_config @@ -104,5 +103,3 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var] api_key=SecretStr(groq_api_key).get_secret_value(), streaming=stream, ) - -