Skip to content

Commit

Permalink
Merge branch 'main' into fix/RemoveGlobalVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristhianzl authored Jul 22, 2024
2 parents e3a7a24 + 4b9dc47 commit 17fab7c
Show file tree
Hide file tree
Showing 67 changed files with 1,053 additions and 1,336 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/typescript_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,30 @@ jobs:
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
shardTotal: [15]
shardIndex:
[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
]
shardTotal: [20]
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key || secrets.OPENAI_API_KEY }}
STORE_API_KEY: ${{ inputs.store_api_key || secrets.STORE_API_KEY }}
Expand Down Expand Up @@ -123,6 +145,7 @@ jobs:
merge-reports:
needs: setup-and-test
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ line-length = 120
[tool.mypy]
plugins = ["pydantic.mypy"]
follow_imports = "silent"
disable_error_code = ["type-var"]

[build-system]
requires = ["poetry-core"]
Expand Down
1 change: 1 addition & 0 deletions src/backend/base/langflow/api/v1/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def save_store_api_key(
# Encrypt the API key
encrypted = auth_utils.encrypt_api_key(api_key, settings_service=settings_service)
current_user.store_api_key = encrypted
db.add(current_user)
db.commit()
return {"detail": "API Key saved"}
except Exception as e:
Expand Down
8 changes: 7 additions & 1 deletion src/backend/base/langflow/api/v1/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,25 @@ async def upload_file(
session: Session = Depends(get_session),
file: UploadFile = File(...),
current_user: User = Depends(get_current_active_user),
folder_id: UUID | None = None,
):
"""Upload flows from a file."""
contents = await file.read()
data = orjson.loads(contents)
response_list = []
if "flows" in data:
flow_list = FlowListCreate(**data)
else:
flow_list = FlowListCreate(flows=[FlowCreate(**data)])
# Now we set the user_id for all flows
for flow in flow_list.flows:
flow.user_id = current_user.id
if folder_id:
flow.folder_id = folder_id
response = create_flow(session=session, flow=flow, current_user=current_user)
response_list.append(response)

return create_flows(session=session, flow_list=flow_list, current_user=current_user)
return response_list


@router.get("/download/", response_model=FlowListRead, status_code=200)
Expand Down
17 changes: 16 additions & 1 deletion src/backend/base/langflow/base/models/model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import json
import warnings
from abc import abstractmethod
from typing import Optional, Union
from typing import Optional, Union, List

from langchain_core.language_models.llms import LLM
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, SystemMessage

from langflow.base.constants import STREAM_INFO_TEXT
from langflow.custom import Component
from langflow.field_typing import LanguageModel
from langflow.inputs import MessageInput, MessageTextInput
from langflow.inputs.inputs import InputTypes, BoolInput
from langflow.schema.message import Message
from langflow.template.field.base import Output

Expand All @@ -17,6 +20,17 @@ class LCModelComponent(Component):
description: str = "Model Description"
trace_type = "llm"

_base_inputs: List[InputTypes] = [
MessageInput(name="input_value", display_name="Input"),
MessageTextInput(
name="system_message",
display_name="System Message",
info="System message to pass to the model.",
advanced=True,
),
BoolInput(name="stream", display_name="Stream", info=STREAM_INFO_TEXT, advanced=True),
]

outputs = [
Output(display_name="Text", name="text_output", method="text_response"),
Output(display_name="Language Model", name="model_output", method="build_model"),
Expand Down Expand Up @@ -142,6 +156,7 @@ def get_chat_result(
messages.append(input_value.to_lc_message())
else:
messages.append(HumanMessage(content=input_value))

inputs: Union[list, dict] = messages or {}
try:
runnable = runnable.with_config( # type: ignore
Expand Down
101 changes: 24 additions & 77 deletions src/backend/base/langflow/components/embeddings/VertexAIEmbeddings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from langflow.base.models.model import LCModelComponent
from langflow.field_typing import Embeddings
from langflow.io import BoolInput, DictInput, FileInput, FloatInput, IntInput, MessageTextInput, Output
from langflow.io import BoolInput, FileInput, FloatInput, IntInput, MessageTextInput, Output


class VertexAIEmbeddingsComponent(LCModelComponent):
Expand All @@ -13,81 +13,22 @@ class VertexAIEmbeddingsComponent(LCModelComponent):
FileInput(
name="credentials",
display_name="Credentials",
info="JSON credentials file. Leave empty to fallback to environment variables",
value="",
file_types=["json"], # Removed the dot
),
DictInput(
name="instance",
display_name="Instance",
advanced=True,
),
MessageTextInput(
name="location",
display_name="Location",
value="us-central1",
advanced=True,
),
IntInput(
name="max_output_tokens",
display_name="Max Output Tokens",
value=128,
),
IntInput(
name="max_retries",
display_name="Max Retries",
value=6,
advanced=True,
),
MessageTextInput(
name="model_name",
display_name="Model Name",
value="textembedding-gecko",
),
IntInput(
name="n",
display_name="N",
value=1,
advanced=True,
),
MessageTextInput(
name="project",
display_name="Project",
advanced=True,
),
IntInput(
name="request_parallelism",
display_name="Request Parallelism",
value=5,
advanced=True,
),
MessageTextInput(
name="stop",
display_name="Stop",
advanced=True,
),
BoolInput(
name="streaming",
display_name="Streaming",
value=False,
advanced=True,
),
FloatInput(
name="temperature",
display_name="Temperature",
value=0.0,
),
IntInput(
name="top_k",
display_name="Top K",
value=40,
advanced=True,
),
FloatInput(
name="top_p",
display_name="Top P",
value=0.95,
advanced=True,
file_types=["json"],
),
MessageTextInput(name="location", display_name="Location", advanced=True),
MessageTextInput(name="project", display_name="Project", info="The project ID.", advanced=True),
IntInput(name="max_output_tokens", display_name="Max Output Tokens", advanced=True),
IntInput(name="max_retries", display_name="Max Retries", value=1, advanced=True),
MessageTextInput(name="model_name", display_name="Model Name", value="textembedding-gecko"),
IntInput(name="n", display_name="N", value=1, advanced=True),
IntInput(name="request_parallelism", value=5, display_name="Request Parallelism", advanced=True),
MessageTextInput(name="stop_sequences", display_name="Stop", advanced=True, is_list=True),
BoolInput(name="streaming", display_name="Streaming", value=False, advanced=True),
FloatInput(name="temperature", value=0.0, display_name="Temperature"),
IntInput(name="top_k", display_name="Top K", advanced=True),
FloatInput(name="top_p", display_name="Top P", value=0.95, advanced=True),
]

outputs = [
Expand All @@ -102,17 +43,23 @@ def build_embeddings(self) -> Embeddings:
"Please install the langchain-google-vertexai package to use the VertexAIEmbeddings component."
)

from google.oauth2 import service_account

if self.credentials:
gcloud_credentials = service_account.Credentials.from_service_account_file(self.credentials)
else:
# will fallback to environment variable or inferred from gcloud CLI
gcloud_credentials = None
return VertexAIEmbeddings(
instance=self.instance,
credentials=self.credentials,
credentials=gcloud_credentials,
location=self.location,
max_output_tokens=self.max_output_tokens,
max_retries=self.max_retries,
model_name=self.model_name,
n=self.n,
project=self.project,
request_parallelism=self.request_parallelism,
stop=self.stop,
stop=self.stop_sequences or None,
streaming=self.streaming,
temperature=self.temperature,
top_k=self.top_k,
Expand Down
13 changes: 2 additions & 11 deletions src/backend/base/langflow/components/models/AmazonBedrockModel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from langchain_aws import ChatBedrock

from langflow.base.constants import STREAM_INFO_TEXT
from langflow.base.models.model import LCModelComponent
from langflow.field_typing import LanguageModel
from langflow.inputs import MessageTextInput
from langflow.io import BoolInput, DictInput, DropdownInput, MessageInput
from langflow.io import DictInput, DropdownInput


class AmazonBedrockComponent(LCModelComponent):
Expand All @@ -13,8 +12,7 @@ class AmazonBedrockComponent(LCModelComponent):
icon = "Amazon"
name = "AmazonBedrockModel"

inputs = [
MessageInput(name="input_value", display_name="Input"),
inputs = LCModelComponent._base_inputs + [
DropdownInput(
name="model_id",
display_name="Model ID",
Expand Down Expand Up @@ -57,13 +55,6 @@ class AmazonBedrockComponent(LCModelComponent):
MessageTextInput(name="region_name", display_name="Region Name", value="us-east-1"),
DictInput(name="model_kwargs", display_name="Model Kwargs", advanced=True, is_list=True),
MessageTextInput(name="endpoint_url", display_name="Endpoint URL", advanced=True),
MessageTextInput(
name="system_message",
display_name="System Message",
info="System message to pass to the model.",
advanced=True,
),
BoolInput(name="stream", display_name="Stream", info=STREAM_INFO_TEXT, advanced=True),
]

def build_model(self) -> LanguageModel: # type: ignore[type-var]
Expand Down
13 changes: 2 additions & 11 deletions src/backend/base/langflow/components/models/AnthropicModel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from langchain_anthropic.chat_models import ChatAnthropic
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 LanguageModel
from langflow.io import BoolInput, DropdownInput, FloatInput, IntInput, MessageTextInput, SecretStrInput
from langflow.io import DropdownInput, FloatInput, IntInput, MessageTextInput, SecretStrInput


class AnthropicModelComponent(LCModelComponent):
Expand All @@ -13,8 +12,7 @@ class AnthropicModelComponent(LCModelComponent):
icon = "Anthropic"
name = "AnthropicModel"

inputs = [
MessageTextInput(name="input_value", display_name="Input"),
inputs = LCModelComponent._base_inputs + [
IntInput(
name="max_tokens",
display_name="Max Tokens",
Expand Down Expand Up @@ -46,13 +44,6 @@ class AnthropicModelComponent(LCModelComponent):
advanced=True,
info="Endpoint of the Anthropic API. Defaults to 'https://api.anthropic.com' if not specified.",
),
BoolInput(name="stream", display_name="Stream", info=STREAM_INFO_TEXT, advanced=True, value=False),
MessageTextInput(
name="system_message",
display_name="System Message",
info="System message to pass to the model.",
advanced=True,
),
MessageTextInput(
name="prefill",
display_name="Prefill",
Expand Down
13 changes: 2 additions & 11 deletions src/backend/base/langflow/components/models/AzureOpenAIModel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from langchain_openai import AzureChatOpenAI
from langflow.base.constants import STREAM_INFO_TEXT
from langflow.base.models.model import LCModelComponent
from langflow.field_typing import LanguageModel
from langflow.inputs import MessageTextInput
from langflow.io import BoolInput, DropdownInput, FloatInput, IntInput, MessageInput, SecretStrInput, StrInput
from langflow.io import DropdownInput, FloatInput, IntInput, SecretStrInput


class AzureChatOpenAIComponent(LCModelComponent):
Expand All @@ -26,7 +25,7 @@ class AzureChatOpenAIComponent(LCModelComponent):
"2024-05-13",
]

inputs = [
inputs = LCModelComponent._base_inputs + [
MessageTextInput(
name="azure_endpoint",
display_name="Azure Endpoint",
Expand All @@ -48,14 +47,6 @@ class AzureChatOpenAIComponent(LCModelComponent):
advanced=True,
info="The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
),
MessageInput(name="input_value", display_name="Input"),
BoolInput(name="stream", display_name="Stream", info=STREAM_INFO_TEXT, advanced=True),
StrInput(
name="system_message",
display_name="System Message",
advanced=True,
info="System message to pass to the model.",
),
]

def build_model(self) -> LanguageModel: # type: ignore[type-var]
Expand Down
Loading

0 comments on commit 17fab7c

Please sign in to comment.