Add GroqLogo and GroqIcon components (#1853)
* Update package.json format command to include only specific directories * Add GroqLogo component and GroqIcon to the project * Update dependencies and add GroqModelSpecs component * Fix nullable column issue in langflow/alembic/versions/6e7b581b5648_fix_nullable.py * Add GroqModelSpecs component and update dependencies * Update GroqModelSpecs and GroqModel display names * chore: Add langchain-pinecone dependency and update constants.py
This commit is contained in:
parent
21be1268ae
commit
a037bf9978
14 changed files with 528 additions and 238 deletions
|
|
@ -22,7 +22,7 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||
def upgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
inspector = Inspector.from_engine(conn) # type: ignore
|
||||
table_names = inspector.get_table_names()
|
||||
# table_names = inspector.get_table_names()
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
columns = inspector.get_columns("apikey")
|
||||
column_names = {column["name"]: column for column in columns}
|
||||
|
|
@ -42,7 +42,7 @@ def upgrade() -> None:
|
|||
def downgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
inspector = Inspector.from_engine(conn) # type: ignore
|
||||
table_names = inspector.get_table_names()
|
||||
# table_names = inspector.get_table_names()
|
||||
columns = inspector.get_columns("apikey")
|
||||
column_names = {column["name"]: column for column in columns}
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
|
|
|
|||
1
src/backend/base/langflow/base/models/groq_constants.py
Normal file
1
src/backend/base/langflow/base/models/groq_constants.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
MODEL_NAMES = ["llama3-8b-8192", "llama3-70b-8192", "mixtral-8x7b-32768", "gemma-7b-it"]
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
from typing import Optional
|
||||
|
||||
from langchain_groq import ChatGroq
|
||||
from pydantic.v1 import SecretStr
|
||||
|
||||
from langflow.base.constants import STREAM_INFO_TEXT
|
||||
from langflow.base.models.groq_constants import MODEL_NAMES
|
||||
from langflow.base.models.model import LCModelComponent
|
||||
from langflow.field_typing import BaseLanguageModel
|
||||
|
||||
|
||||
class GroqModelSpecs(LCModelComponent):
|
||||
display_name: str = "Groq"
|
||||
description: str = "Generate text using Groq."
|
||||
icon = "Groq"
|
||||
|
||||
field_order = [
|
||||
"groq_api_key",
|
||||
"model",
|
||||
"max_output_tokens",
|
||||
"temperature",
|
||||
"top_k",
|
||||
"top_p",
|
||||
"n",
|
||||
"input_value",
|
||||
"system_message",
|
||||
"stream",
|
||||
]
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"groq_api_key": {
|
||||
"display_name": "Groq API Key",
|
||||
"info": "API key for the Groq API.",
|
||||
"password": True,
|
||||
},
|
||||
"groq_api_base": {
|
||||
"display_name": "Groq API Base",
|
||||
"info": "Base URL path for API requests, leave blank if not using a proxy or service emulator.",
|
||||
"advanced": True,
|
||||
},
|
||||
"max_tokens": {
|
||||
"display_name": "Max Output Tokens",
|
||||
"info": "The maximum number of tokens to generate.",
|
||||
"advanced": True,
|
||||
},
|
||||
"temperature": {
|
||||
"display_name": "Temperature",
|
||||
"info": "Run inference with this temperature. Must by in the closed interval [0.0, 1.0].",
|
||||
},
|
||||
"n": {
|
||||
"display_name": "N",
|
||||
"info": "Number of chat completions to generate for each prompt. Note that the API may not return the full n completions if duplicates are generated.",
|
||||
"advanced": True,
|
||||
},
|
||||
"model_name": {
|
||||
"display_name": "Model",
|
||||
"info": "The name of the model to use. Supported examples: gemini-pro",
|
||||
"options": MODEL_NAMES,
|
||||
},
|
||||
"stream": {
|
||||
"display_name": "Stream",
|
||||
"info": STREAM_INFO_TEXT,
|
||||
"advanced": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
groq_api_key: str,
|
||||
model_name: str,
|
||||
groq_api_base: Optional[str] = None,
|
||||
max_tokens: Optional[int] = None,
|
||||
temperature: float = 0.1,
|
||||
n: Optional[int] = 1,
|
||||
stream: bool = False,
|
||||
) -> BaseLanguageModel:
|
||||
return ChatGroq(
|
||||
model_name=model_name,
|
||||
max_tokens=max_tokens or None, # type: ignore
|
||||
temperature=temperature,
|
||||
groq_api_base=groq_api_base,
|
||||
n=n or 1,
|
||||
groq_api_key=SecretStr(groq_api_key),
|
||||
streaming=stream,
|
||||
)
|
||||
95
src/backend/base/langflow/components/models/GroqModel.py
Normal file
95
src/backend/base/langflow/components/models/GroqModel.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
from typing import Optional
|
||||
|
||||
from langchain_groq import ChatGroq
|
||||
from langflow.base.models.groq_constants import MODEL_NAMES
|
||||
from pydantic.v1 import SecretStr
|
||||
|
||||
from langflow.base.constants import STREAM_INFO_TEXT
|
||||
from langflow.base.models.model import LCModelComponent
|
||||
from langflow.field_typing import Text
|
||||
|
||||
|
||||
class GroqModel(LCModelComponent):
|
||||
display_name: str = "Groq"
|
||||
description: str = "Generate text using Groq."
|
||||
icon = "Groq"
|
||||
|
||||
field_order = [
|
||||
"groq_api_key",
|
||||
"model",
|
||||
"max_output_tokens",
|
||||
"temperature",
|
||||
"top_k",
|
||||
"top_p",
|
||||
"n",
|
||||
"input_value",
|
||||
"system_message",
|
||||
"stream",
|
||||
]
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"groq_api_key": {
|
||||
"display_name": "Groq API Key",
|
||||
"info": "API key for the Groq API.",
|
||||
"password": True,
|
||||
},
|
||||
"groq_api_base": {
|
||||
"display_name": "Groq API Base",
|
||||
"info": "Base URL path for API requests, leave blank if not using a proxy or service emulator.",
|
||||
"advanced": True,
|
||||
},
|
||||
"max_tokens": {
|
||||
"display_name": "Max Output Tokens",
|
||||
"info": "The maximum number of tokens to generate.",
|
||||
"advanced": True,
|
||||
},
|
||||
"temperature": {
|
||||
"display_name": "Temperature",
|
||||
"info": "Run inference with this temperature. Must by in the closed interval [0.0, 1.0].",
|
||||
},
|
||||
"n": {
|
||||
"display_name": "N",
|
||||
"info": "Number of chat completions to generate for each prompt. Note that the API may not return the full n completions if duplicates are generated.",
|
||||
"advanced": True,
|
||||
},
|
||||
"model_name": {
|
||||
"display_name": "Model",
|
||||
"info": "The name of the model to use. Supported examples: gemini-pro",
|
||||
"options": MODEL_NAMES,
|
||||
},
|
||||
"input_value": {"display_name": "Input", "info": "The input to the model."},
|
||||
"stream": {
|
||||
"display_name": "Stream",
|
||||
"info": STREAM_INFO_TEXT,
|
||||
"advanced": True,
|
||||
},
|
||||
"system_message": {
|
||||
"display_name": "System Message",
|
||||
"info": "System message to pass to the model.",
|
||||
"advanced": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
groq_api_key: str,
|
||||
model_name: str,
|
||||
input_value: Text,
|
||||
groq_api_base: Optional[str] = None,
|
||||
max_tokens: Optional[int] = None,
|
||||
temperature: float = 0.1,
|
||||
n: Optional[int] = 1,
|
||||
stream: bool = False,
|
||||
system_message: Optional[str] = None,
|
||||
) -> Text:
|
||||
output = ChatGroq(
|
||||
model_name=model_name,
|
||||
max_tokens=max_tokens or None, # type: ignore
|
||||
temperature=temperature,
|
||||
groq_api_base=groq_api_base,
|
||||
n=n or 1,
|
||||
groq_api_key=SecretStr(groq_api_key),
|
||||
streaming=stream,
|
||||
)
|
||||
return self.get_chat_result(output, stream, input_value, system_message)
|
||||
|
|
@ -12,6 +12,7 @@ VARIABLES_TO_GET_FROM_ENVIRONMENT = [
|
|||
"ASTRA_DB_APPLICATION_TOKEN",
|
||||
"ASTRA_DB_API_ENDPOINT",
|
||||
"COHERE_API_KEY",
|
||||
"GROQ_API_KEY",
|
||||
"HUGGINGFACEHUB_API_TOKEN",
|
||||
"PINECONE_API_KEY",
|
||||
"SEARCHAPI_API_KEY",
|
||||
|
|
|
|||
17
src/backend/base/poetry.lock
generated
17
src/backend/base/poetry.lock
generated
|
|
@ -1090,13 +1090,13 @@ extended-testing = ["aiosqlite (>=0.19.0,<0.20.0)", "aleph-alpha-client (>=2.15.
|
|||
|
||||
[[package]]
|
||||
name = "langchain-core"
|
||||
version = "0.1.51"
|
||||
version = "0.1.52"
|
||||
description = "Building applications with LLMs through composability"
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.8.1"
|
||||
files = [
|
||||
{file = "langchain_core-0.1.51-py3-none-any.whl", hash = "sha256:3058bdb04d43a8eaae2e249365fe2e8d0356a09c7b2c1afa1a8100f8888da4fa"},
|
||||
{file = "langchain_core-0.1.51.tar.gz", hash = "sha256:f7ea116f939be9e74c385baf95d6c84cd7a402b59c2c1893fc054bf98abbefc2"},
|
||||
{file = "langchain_core-0.1.52-py3-none-any.whl", hash = "sha256:62566749c92e8a1181c255c788548dc16dbc319d896cd6b9c95dc17af9b2a6db"},
|
||||
{file = "langchain_core-0.1.52.tar.gz", hash = "sha256:084c3fc452f5a6966c28ab3ec5dbc8b8d26fc3f63378073928f4e29d90b6393f"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
|
@ -2555,17 +2555,18 @@ full = ["httpx (>=0.22.0)", "itsdangerous", "jinja2", "python-multipart (>=0.0.7
|
|||
|
||||
[[package]]
|
||||
name = "tenacity"
|
||||
version = "8.2.3"
|
||||
version = "8.3.0"
|
||||
description = "Retry code until it succeeds"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "tenacity-8.2.3-py3-none-any.whl", hash = "sha256:ce510e327a630c9e1beaf17d42e6ffacc88185044ad85cf74c0a8887c6a0f88c"},
|
||||
{file = "tenacity-8.2.3.tar.gz", hash = "sha256:5398ef0d78e63f40007c1fb4c0bff96e1911394d2fa8d194f77619c05ff6cc8a"},
|
||||
{file = "tenacity-8.3.0-py3-none-any.whl", hash = "sha256:3649f6443dbc0d9b01b9d8020a9c4ec7a1ff5f6f3c6c8a036ef371f573fe9185"},
|
||||
{file = "tenacity-8.3.0.tar.gz", hash = "sha256:953d4e6ad24357bceffbc9707bc74349aca9d245f68eb65419cf0c249a1949a2"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
doc = ["reno", "sphinx", "tornado (>=4.5)"]
|
||||
doc = ["reno", "sphinx"]
|
||||
test = ["pytest", "tornado (>=4.5)", "typeguard"]
|
||||
|
||||
[[package]]
|
||||
name = "typer"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue