Merge branch 'ij/chatimg' into cz/inspection

This commit is contained in:
italojohnny 2024-05-28 15:59:18 -03:00
commit d575c97d15
349 changed files with 14576 additions and 21293 deletions

View file

@ -22,7 +22,8 @@ from sqlmodel import select
from langflow.main import setup_app
from langflow.services.database.models.folder.utils import create_default_folder_if_it_doesnt_exist
from langflow.services.database.utils import session_getter
from langflow.services.deps import get_db_service
from langflow.services.deps import get_db_service, get_settings_service, session_scope
from langflow.services.settings.constants import DEFAULT_SUPERUSER
from langflow.services.utils import initialize_services
from langflow.utils.logger import configure, logger
from langflow.utils.util import update_settings
@ -83,7 +84,6 @@ def run(
help="Path to the directory containing custom components.",
envvar="LANGFLOW_COMPONENTS_PATH",
),
config: str = typer.Option(Path(__file__).parent / "config.yaml", help="Path to the configuration file."),
# .env file param
env_file: Path = typer.Option(None, help="Path to the .env file containing environment variables."),
log_level: str = typer.Option("critical", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
@ -132,7 +132,6 @@ def run(
load_dotenv(env_file, override=True)
update_settings(
config,
dev=dev,
remove_api_keys=remove_api_keys,
cache=cache,
@ -510,6 +509,66 @@ def migration(
display_results(results)
@app.command()
def api_key(
log_level: str = typer.Option("error", help="Logging level.", envvar="LANGFLOW_LOG_LEVEL"),
):
"""
Creates an API key for the default superuser if AUTO_LOGIN is enabled.
Args:
log_level (str, optional): Logging level. Defaults to "error".
Returns:
None
"""
configure(log_level=log_level)
initialize_services()
settings_service = get_settings_service()
auth_settings = settings_service.auth_settings
if not auth_settings.AUTO_LOGIN:
typer.echo("Auto login is disabled. API keys cannot be created through the CLI.")
return
with session_scope() as session:
from langflow.services.database.models.user.model import User
superuser = session.exec(select(User).where(User.username == DEFAULT_SUPERUSER)).first()
if not superuser:
typer.echo("Default superuser not found. This command requires a superuser and AUTO_LOGIN to be enabled.")
return
from langflow.services.database.models.api_key import ApiKey, ApiKeyCreate
from langflow.services.database.models.api_key.crud import create_api_key, delete_api_key
api_key = session.exec(select(ApiKey).where(ApiKey.user_id == superuser.id)).first()
if api_key:
delete_api_key(session, api_key.id)
api_key_create = ApiKeyCreate(name="CLI")
unmasked_api_key = create_api_key(session, api_key_create, user_id=superuser.id)
session.commit()
# Create a banner to display the API key and tell the user it won't be shown again
api_key_banner(unmasked_api_key)
def api_key_banner(unmasked_api_key):
is_mac = platform.system() == "Darwin"
import pyperclip # type: ignore
pyperclip.copy(unmasked_api_key.api_key)
panel = Panel(
f"[bold]API Key Created Successfully:[/bold]\n\n"
f"[bold blue]{unmasked_api_key.api_key}[/bold blue]\n\n"
"This is the only time the API key will be displayed. \n"
"Make sure to store it in a secure location. \n\n"
f"The API key has been copied to your clipboard. [bold]{['Ctrl','Cmd'][is_mac]} + V[/bold] to paste it.",
box=box.ROUNDED,
border_style="blue",
expand=False,
)
console = Console()
console.print(panel)
def main():
with warnings.catch_warnings():
warnings.simplefilter("ignore")

View file

@ -1,4 +1,3 @@
import os
import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Optional

View file

@ -1,13 +1,12 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from uuid import UUID
from langchain.schema import AgentAction, AgentFinish
from langchain_core.callbacks.base import AsyncCallbackHandler
from loguru import logger
from langflow.api.v1.schemas import ChatResponse, PromptResponse
from langflow.services.deps import get_chat_service, get_socket_service
from langflow.utils.util import remove_ansi_escape_codes
from langchain_core.agents import AgentAction, AgentFinish
if TYPE_CHECKING:
from langflow.services.socket.service import SocketIOService

View file

@ -171,7 +171,7 @@ async def build_vertex(
result_dict,
log_message,
valid,
_,
log_type,
vertex,
) = await graph.build_vertex(
lock=lock,
@ -186,6 +186,7 @@ async def build_vertex(
except Exception as exc:
logger.exception(f"Error building vertex: {exc}")
log_message = format_exception_message(exc)
log_type = type(exc).__name__
valid = False
result_data_response = ResultDataResponse(results={})
@ -193,7 +194,7 @@ async def build_vertex(
# we need to clear the cache
await chat_service.clear_cache(flow_id_str)
log_object = Log(message=log_message)
log_object = Log(message=log_message, type=log_type)
result_data_response.logs.append(log_object)
# Log the vertex build

View file

@ -18,10 +18,9 @@ from langflow.api.v1.schemas import (
UpdateCustomComponentRequest,
UploadFileResponse,
)
from langflow.custom import CustomComponent
from langflow.custom.utils import build_custom_component_template
from langflow.graph.graph.base import Graph
from langflow.graph.schema import RunOutputs
from langflow.interface.custom.custom_component import CustomComponent
from langflow.interface.custom.utils import build_custom_component_template
from langflow.processing.process import process_tweaks, run_graph_internal
from langflow.schema.graph import Tweaks
from langflow.services.auth.utils import api_key_security, get_current_active_user
@ -44,7 +43,7 @@ def get_all(
logger.debug("Building langchain types dict")
try:
all_types_dict = get_all_types_dict(settings_service.settings.COMPONENTS_PATH)
all_types_dict = get_all_types_dict(settings_service.settings.components_path)
return all_types_dict
except Exception as exc:
logger.exception(exc)

View file

@ -38,7 +38,10 @@ def create_flow(
db_flow.updated_at = datetime.now(timezone.utc)
if db_flow.folder_id is None:
default_folder = session.exec(select(Folder).where(Folder.name == DEFAULT_FOLDER_NAME)).first()
# Make sure flows always have a folder
default_folder = session.exec(
select(Folder).where(Folder.name == DEFAULT_FOLDER_NAME, Folder.user_id == current_user.id)
).first()
if default_folder:
db_flow.folder_id = default_folder.id
@ -127,7 +130,7 @@ def update_flow(
if not db_flow:
raise HTTPException(status_code=404, detail="Flow not found")
flow_data = flow.model_dump(exclude_unset=True)
if settings_service.settings.REMOVE_API_KEYS:
if settings_service.settings.remove_api_keys:
flow_data = remove_api_keys(flow_data)
for key, value in flow_data.items():
if value is not None:

View file

@ -3,12 +3,11 @@ from uuid import UUID
import orjson
from fastapi import APIRouter, Depends, File, HTTPException, Response, UploadFile, status
from sqlalchemy import update
from sqlalchemy import or_, update
from sqlmodel import Session, select
from langflow.api.v1.flows import create_flows
from langflow.api.v1.schemas import FlowListCreate, FlowListReadWithFolderName
from langflow.initial_setup.setup import STARTER_FOLDER_NAME
from langflow.services.auth.utils import get_current_active_user
from langflow.services.database.models.flow.model import Flow, FlowCreate, FlowRead
from langflow.services.database.models.folder.constants import DEFAULT_FOLDER_NAME
@ -35,6 +34,18 @@ def create_folder(
try:
new_folder = Folder.model_validate(folder, from_attributes=True)
new_folder.user_id = current_user.id
folder_results = session.exec(
select(Folder).where(
Folder.name.like(f"{new_folder.name}%"), # type: ignore
Folder.user_id == current_user.id,
)
)
existing_folder_names = [folder.name for folder in folder_results]
if existing_folder_names:
new_folder.name = f"{new_folder.name} ({len(existing_folder_names) + 1})"
session.add(new_folder)
session.commit()
session.refresh(new_folder)
@ -63,16 +74,11 @@ def read_folders(
current_user: User = Depends(get_current_active_user),
):
try:
folders = session.exec(select(Folder).where(Folder.user_id == current_user.id)).all()
return folders
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/starter-projects", response_model=FolderReadWithFlows, status_code=200)
def read_starter_folders(*, session: Session = Depends(get_session)):
try:
folders = session.exec(select(Folder).where(Folder.name == STARTER_FOLDER_NAME)).first()
folders = session.exec(
select(Folder).where(
or_(Folder.user_id == current_user.id, Folder.user_id == None) # type: ignore # noqa: E711
)
).all()
return folders
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View file

@ -247,6 +247,7 @@ class VerticesOrderResponse(BaseModel):
class Log(TypedDict):
message: str
type: str
class ResultDataResponse(BaseModel):

View file

@ -54,7 +54,7 @@ def check_if_store_is_enabled(
settings_service=Depends(get_settings_service),
):
return {
"enabled": settings_service.settings.STORE,
"enabled": settings_service.settings.store,
}

View file

@ -1,9 +1,9 @@
from typing import Optional, Union
from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.memory import store_message
from langflow.schema import Record

View file

@ -1,8 +1,8 @@
from typing import Optional
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record

View file

@ -1,6 +1,6 @@
from typing import Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema.schema import Record

View file

@ -1,10 +1,10 @@
from fastapi import HTTPException
from langchain.prompts import PromptTemplate
from loguru import logger
from langflow.api.v1.base import INVALID_NAMES, check_input_variables
from langflow.interface.utils import extract_input_variables_from_prompt
from langflow.template.field.prompt import DefaultPromptField
from langchain_core.prompts import PromptTemplate
def validate_prompt(prompt_template: str, silent_errors: bool = False) -> list[str]:

View file

@ -1,52 +0,0 @@
from typing import Callable, List, Optional, Union
from langchain.agents import AgentExecutor, AgentType, initialize_agent, types
from langflow.field_typing import BaseChatMemory, BaseLanguageModel, Tool
from langflow.interface.custom.custom_component import CustomComponent
class AgentInitializerComponent(CustomComponent):
display_name: str = "Agent Initializer"
description: str = "Initialize a Langchain Agent."
documentation: str = "https://python.langchain.com/docs/modules/agents/agent_types/"
def build_config(self):
agents = list(types.AGENT_TO_CLASS.keys())
# field_type and required are optional
return {
"agent": {"options": agents, "value": agents[0], "display_name": "Agent Type"},
"max_iterations": {"display_name": "Max Iterations", "value": 10},
"memory": {"display_name": "Memory"},
"tools": {"display_name": "Tools"},
"llm": {"display_name": "Language Model"},
"code": {"advanced": True},
}
def build(
self,
agent: str,
llm: BaseLanguageModel,
tools: List[Tool],
max_iterations: int,
memory: Optional[BaseChatMemory] = None,
) -> Union[AgentExecutor, Callable]:
agent = AgentType(agent)
if memory:
return initialize_agent(
tools=tools,
llm=llm,
agent=agent,
memory=memory,
return_intermediate_steps=True,
handle_parsing_errors=True,
max_iterations=max_iterations,
)
return initialize_agent(
tools=tools,
llm=llm,
agent=agent,
return_intermediate_steps=True,
handle_parsing_errors=True,
max_iterations=max_iterations,
)

View file

@ -1,10 +1,9 @@
from langchain.agents import AgentExecutor, create_json_agent
from langchain.agents import AgentExecutor
from langchain_community.agent_toolkits import create_json_agent
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
from langflow.field_typing import (
BaseLanguageModel,
)
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class JsonAgentComponent(CustomComponent):

View file

@ -1,102 +0,0 @@
from typing import List, Optional
from langchain.agents.agent import AgentExecutor
from langchain.agents.agent_toolkits.conversational_retrieval.openai_functions import _get_default_system_message
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
from langchain.memory.token_buffer import ConversationTokenBufferMemory
from langchain.prompts import SystemMessagePromptTemplate
from langchain.prompts.chat import MessagesPlaceholder
from langchain.schema.memory import BaseMemory
from langchain.tools import Tool
from langchain_openai import ChatOpenAI
from langflow.field_typing.range_spec import RangeSpec
from langflow.interface.custom.custom_component import CustomComponent
from pydantic.v1 import SecretStr
class ConversationalAgent(CustomComponent):
display_name: str = "OpenAI Conversational Agent"
description: str = "Conversational Agent that can use OpenAI's function calling API"
icon = "OpenAI"
def build_config(self):
openai_function_models = [
"gpt-4-turbo-preview",
"gpt-4-0125-preview",
"gpt-4-1106-preview",
"gpt-4-vision-preview",
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo-1106",
]
return {
"tools": {"display_name": "Tools"},
"memory": {"display_name": "Memory"},
"system_message": {"display_name": "System Message"},
"max_token_limit": {"display_name": "Max Token Limit"},
"model_name": {
"display_name": "Model Name",
"options": openai_function_models,
"value": openai_function_models[0],
},
"code": {"show": False},
"temperature": {
"display_name": "Temperature",
"value": 0.2,
"rangeSpec": RangeSpec(min=0, max=2, step=0.1),
},
}
def build(
self,
model_name: str,
openai_api_key: str,
tools: List[Tool],
openai_api_base: Optional[str] = None,
memory: Optional[BaseMemory] = None,
system_message: Optional[SystemMessagePromptTemplate] = None,
max_token_limit: int = 2000,
temperature: float = 0.9,
) -> AgentExecutor:
if openai_api_key:
api_key = SecretStr(openai_api_key)
else:
api_key = None
llm = ChatOpenAI(
model=model_name,
api_key=api_key,
base_url=openai_api_base,
max_tokens=max_token_limit,
temperature=temperature,
)
if not memory:
memory_key = "chat_history"
memory = ConversationTokenBufferMemory(
memory_key=memory_key,
return_messages=True,
output_key="output",
llm=llm,
max_token_limit=max_token_limit,
)
else:
memory_key = memory.memory_key # type: ignore
_system_message = system_message or _get_default_system_message()
prompt = OpenAIFunctionsAgent.create_prompt(
system_message=_system_message, # type: ignore
extra_prompt_messages=[MessagesPlaceholder(variable_name=memory_key)],
)
agent = OpenAIFunctionsAgent(
llm=llm,
tools=tools,
prompt=prompt, # type: ignore
)
return AgentExecutor(
agent=agent,
tools=tools, # type: ignore
memory=memory,
verbose=True,
return_intermediate_steps=True,
handle_parsing_errors=True,
)

View file

@ -1,12 +1,12 @@
from typing import Callable, Union
from langchain.agents import AgentExecutor
from langchain_community.utilities import SQLDatabase
from langchain_community.agent_toolkits import SQLDatabaseToolkit
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities import SQLDatabase
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class SQLAgentComponent(CustomComponent):

View file

@ -3,8 +3,8 @@ from typing import Callable, Union
from langchain.agents import AgentExecutor, create_vectorstore_agent
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreToolkit
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class VectorStoreAgentComponent(CustomComponent):

View file

@ -4,7 +4,7 @@ from langchain.agents import create_vectorstore_router_agent
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreRouterToolkit
from langchain_core.language_models.base import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class VectorStoreRouterAgentComponent(CustomComponent):

View file

@ -1,17 +1,13 @@
from .AgentInitializer import AgentInitializerComponent
from .CSVAgent import CSVAgentComponent
from .JsonAgent import JsonAgentComponent
from .OpenAIConversationalAgent import ConversationalAgent
from .SQLAgent import SQLAgentComponent
from .VectorStoreAgent import VectorStoreAgentComponent
from .VectorStoreRouterAgent import VectorStoreRouterAgentComponent
from .XMLAgent import XMLAgentComponent
__all__ = [
"AgentInitializerComponent",
"CSVAgentComponent",
"JsonAgentComponent",
"ConversationalAgent",
"SQLAgentComponent",
"VectorStoreAgentComponent",
"VectorStoreRouterAgentComponent",

View file

@ -2,8 +2,8 @@ from typing import Optional
from langchain.chains import ConversationChain
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
from langflow.interface.custom.custom_component import CustomComponent
class ConversationChainComponent(CustomComponent):

View file

@ -1,11 +1,11 @@
from typing import Optional
from langchain.chains.llm import LLMChain
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
from langflow.interface.custom.custom_component import CustomComponent
from langchain_core.prompts import PromptTemplate
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
class LLMChainComponent(CustomComponent):
display_name = "LLMChain"

View file

@ -1,7 +1,7 @@
from langchain.chains import LLMCheckerChain
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, Text
from langflow.interface.custom.custom_component import CustomComponent
class LLMCheckerChainComponent(CustomComponent):

View file

@ -2,8 +2,8 @@ from typing import Optional
from langchain.chains import LLMChain, LLMMathChain
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, Text
from langflow.interface.custom.custom_component import CustomComponent
class LLMMathChainComponent(CustomComponent):

View file

@ -3,8 +3,8 @@ from typing import Optional
from langchain.chains.retrieval_qa.base import RetrievalQA
from langchain_core.documents import Document
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, BaseRetriever, Text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema.schema import Record

View file

@ -3,8 +3,8 @@ from typing import Optional
from langchain.chains import RetrievalQAWithSourcesChain
from langchain_core.documents import Document
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, BaseRetriever, Text
from langflow.interface.custom.custom_component import CustomComponent
class RetrievalQAWithSourcesChainComponent(CustomComponent):

View file

@ -5,8 +5,8 @@ from langchain_community.utilities.sql_database import SQLDatabase
from langchain_core.prompts import PromptTemplate
from langchain_core.runnables import Runnable
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, Text
from langflow.interface.custom.custom_component import CustomComponent
class SQLGeneratorComponent(CustomComponent):

View file

@ -3,7 +3,8 @@ import json
from typing import List, Optional
import httpx
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,7 @@
from typing import Any, Dict, List, Optional
from langflow.base.data.utils import parallel_load_records, parse_text_file_to_record, retrieve_file_paths
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -2,7 +2,7 @@ from pathlib import Path
from typing import Any, Dict
from langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -2,7 +2,7 @@ from typing import Any, Dict
from langchain_community.document_loaders.web_base import WebBaseLoader
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,9 +1,9 @@
from typing import Optional
from langchain.embeddings.base import Embeddings
from langchain_community.embeddings import BedrockEmbeddings
from langchain_core.embeddings import Embeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class AmazonBedrockEmeddingsComponent(CustomComponent):

View file

@ -1,7 +1,8 @@
from langchain.embeddings.base import Embeddings
from langchain_community.embeddings import AzureOpenAIEmbeddings
from langchain_core.embeddings import Embeddings
from langchain_openai import AzureOpenAIEmbeddings
from pydantic.v1 import SecretStr
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class AzureOpenAIEmbeddingsComponent(CustomComponent):
@ -52,12 +53,16 @@ class AzureOpenAIEmbeddingsComponent(CustomComponent):
api_version: str,
api_key: str,
) -> Embeddings:
if api_key:
azure_api_key = SecretStr(api_key)
else:
azure_api_key = None
try:
embeddings = AzureOpenAIEmbeddings(
azure_endpoint=azure_endpoint,
azure_deployment=azure_deployment,
api_version=api_version,
api_key=api_key,
api_key=azure_api_key,
)
except Exception as e:

View file

@ -2,7 +2,7 @@ from typing import Dict, Optional
from langchain_community.embeddings.huggingface import HuggingFaceEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class HuggingFaceEmbeddingsComponent(CustomComponent):

View file

@ -3,7 +3,7 @@ from typing import Dict, Optional
from langchain_community.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
from pydantic.v1.types import SecretStr
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class HuggingFaceInferenceAPIEmbeddingsComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from langchain_mistralai.embeddings import MistralAIEmbeddings
from pydantic.v1 import SecretStr
from langchain_mistralai.embeddings import MistralAIEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings

View file

@ -1,9 +1,9 @@
from typing import Optional
from langchain.embeddings.base import Embeddings
from langchain_community.embeddings import OllamaEmbeddings
from langchain_core.embeddings import Embeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class OllamaEmbeddingsComponent(CustomComponent):

View file

@ -1,10 +1,10 @@
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
from langchain_openai.embeddings.base import OpenAIEmbeddings
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
from langflow.field_typing import Embeddings, NestedDict
from langflow.interface.custom.custom_component import CustomComponent
class OpenAIEmbeddingsComponent(CustomComponent):
@ -94,7 +94,6 @@ class OpenAIEmbeddingsComponent(CustomComponent):
allowed_special: List[str] = [],
disallowed_special: List[str] = ["all"],
chunk_size: int = 1000,
client: Optional[Any] = None,
deployment: str = "text-embedding-ada-002",
embedding_ctx_length: int = 8191,
max_retries: int = 6,
@ -126,7 +125,6 @@ class OpenAIEmbeddingsComponent(CustomComponent):
allowed_special=set(allowed_special),
disallowed_special="all",
chunk_size=chunk_size,
client=client,
deployment=deployment,
embedding_ctx_length=embedding_ctx_length,
max_retries=max_retries,

View file

@ -2,7 +2,7 @@ from typing import List, Optional
from langchain_google_vertexai import VertexAIEmbeddings
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class VertexAIEmbeddingsComponent(CustomComponent):

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.memory import delete_messages, get_messages

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,6 +1,6 @@
from typing import List
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,6 +1,6 @@
from typing import Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,8 @@
from typing import Union
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.schema import Record
class PassComponent(CustomComponent):

View file

@ -1,8 +1,8 @@
from typing import Callable
from langflow.custom import CustomComponent
from langflow.custom.utils import get_function
from langflow.field_typing import Code
from langflow.interface.custom.custom_component import CustomComponent
from langflow.interface.custom.utils import get_function
class PythonFunctionComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from langchain_core.runnables import Runnable
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.interface.custom.custom_component import CustomComponent
class RunnableExecComponent(CustomComponent):

View file

@ -1,8 +1,8 @@
from langchain_community.tools.sql_database.tool import QuerySQLDataBaseTool
from langchain_community.utilities import SQLDatabase
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.interface.custom.custom_component import CustomComponent
class SQLExecutorComponent(CustomComponent):

View file

@ -1,7 +1,7 @@
from typing import Optional
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record
from langflow.utils.util import unescape_string

View file

@ -1,6 +1,6 @@
from typing import List, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.memory import get_messages, store_message
from langflow.schema import Record

View file

@ -1,8 +1,8 @@
from typing import Optional, Union
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.schema import Record
class TextOperatorComponent(CustomComponent):

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import Text

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import Text

View file

@ -1,6 +1,6 @@
# from langflow.field_typing import Data
from langflow.custom import CustomComponent
from langflow.schema import Record
from langflow.interface.custom.custom_component import CustomComponent
class Component(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import List
from langchain_core.documents import Document
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,7 @@
import uuid
from typing import Any, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class UUIDGeneratorComponent(CustomComponent):

View file

@ -1,6 +1,6 @@
from typing import List, Optional
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.memory import get_messages
from langflow.schema import Record

View file

@ -1,6 +1,6 @@
from langflow.custom import CustomComponent
from langflow.field_typing import Text
from langflow.helpers.record import records_to_text
from langflow.interface.custom.custom_component import CustomComponent
from langflow.schema import Record

View file

@ -1,4 +1,4 @@
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.schema import Record

View file

@ -1,7 +1,7 @@
from langchain_core.prompts import PromptTemplate
from langflow.custom import CustomComponent
from langflow.field_typing import Prompt, TemplateField, Text
from langflow.interface.custom.custom_component import CustomComponent
class PromptComponent(CustomComponent):

View file

@ -3,7 +3,7 @@
# We need to make sure this class is importable from the context where this code will be running.
from langchain_community.utilities.bing_search import BingSearchAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class BingSearchAPIWrapperComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.google_search import GoogleSearchAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class GoogleSearchAPIWrapperComponent(CustomComponent):

View file

@ -4,7 +4,7 @@ from typing import Dict
# If this class does not exist, you would need to create it or import the appropriate class from another module
from langchain_community.utilities.google_serper import GoogleSerperAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class GoogleSerperAPIWrapperComponent(CustomComponent):

View file

@ -13,7 +13,7 @@
from langchain_core.documents import Document
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.services.database.models.base import orjson_dumps

View file

@ -1,6 +1,6 @@
from langchain_experimental.sql.base import SQLDatabase
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class SQLDatabaseComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Dict, Optional
from langchain_community.utilities.searx_search import SearxSearchWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class SearxSearchWrapperComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.serpapi import SerpAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class SerpAPIWrapperComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.wikipedia import WikipediaAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
# Assuming WikipediaAPIWrapper is a class that needs to be imported.
# The import statement is not included as it is not provided in the JSON

View file

@ -2,7 +2,7 @@ from typing import Callable, Union
from langchain_community.utilities.wolfram_alpha import WolframAlphaAPIWrapper
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
# Since all the fields in the JSON have show=False, we will only create a basic component
# without any configurable fields.

View file

@ -51,9 +51,7 @@ class AstraDBMessageReaderComponent(BaseMemoryComponent):
Returns:
list[Record]: A list of Record objects representing the search results.
"""
memory: AstraDBChatMessageHistory = cast(
AstraDBChatMessageHistory, kwargs.get("memory")
)
memory: AstraDBChatMessageHistory = cast(AstraDBChatMessageHistory, kwargs.get("memory"))
if not memory:
raise ValueError("AstraDBChatMessageHistory instance is required.")
@ -72,9 +70,7 @@ class AstraDBMessageReaderComponent(BaseMemoryComponent):
namespace: Optional[str] = None,
) -> list[Record]:
try:
from langchain_community.chat_message_histories.astradb import (
AstraDBChatMessageHistory,
)
pass
except ImportError:
raise ImportError(
"Could not import langchain Astra DB integration package. "

View file

@ -5,7 +5,7 @@ from langflow.field_typing import Text
from langflow.schema.schema import Record
from langchain_core.messages import BaseMessage
from langchain_community.chat_message_histories.astradb import AstraDBChatMessageHistory
from langchain_astradb import AstraDBChatMessageHistory
class AstraDBMessageWriterComponent(BaseMemoryComponent):
@ -74,13 +74,15 @@ class AstraDBMessageWriterComponent(BaseMemoryComponent):
if memory is None:
raise ValueError("AstraDBChatMessageHistory instance is required.")
text_list = [BaseMessage(
content=text,
sender=sender,
sender_name=sender_name,
metadata=metadata,
session_id=session_id,
)]
text_list = [
BaseMessage(
content=text,
sender=sender,
sender_name=sender_name,
metadata=metadata,
session_id=session_id,
)
]
memory.add_messages(text_list)
@ -94,9 +96,7 @@ class AstraDBMessageWriterComponent(BaseMemoryComponent):
namespace: Optional[str] = None,
) -> Record:
try:
from langchain_community.chat_message_histories.astradb import (
AstraDBChatMessageHistory,
)
pass
except ImportError:
raise ImportError(
"Could not import langchain Astra DB integration package. "

View file

@ -116,19 +116,18 @@ class ZepMessageReaderComponent(BaseMemoryComponent):
url: Optional[Text] = None,
api_key: Optional[Text] = None,
query: Optional[Text] = None,
search_scope: SearchScope = SearchScope.messages,
search_type: SearchType = SearchType.similarity,
search_scope: str = SearchScope.messages,
search_type: str = SearchType.similarity,
limit: Optional[int] = None,
) -> list[Record]:
try:
from zep_python import ZepClient
from zep_python.langchain import ZepChatMessageHistory
# Monkeypatch API_BASE_PATH to
# avoid 404
# This is a workaround for the local Zep instance
# cloud Zep works with v2
import zep_python.zep_client
from zep_python import ZepClient
from zep_python.langchain import ZepChatMessageHistory
zep_python.zep_client.API_BASE_PATH = api_base_path
except ImportError:

View file

@ -1,8 +1,9 @@
from typing import Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.bedrock import Bedrock
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class AmazonBedrockComponent(CustomComponent):

View file

@ -1,10 +1,10 @@
from typing import Optional
from langchain.llms.base import BaseLanguageModel
from langchain_anthropic import ChatAnthropic
from langchain_core.language_models import BaseLanguageModel
from pydantic.v1 import SecretStr
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class ChatAntropicSpecsComponent(CustomComponent):
@ -35,8 +35,8 @@ class ChatAntropicSpecsComponent(CustomComponent):
},
"max_tokens": {
"display_name": "Max Tokens",
"field_type": "int",
"value": 256,
"advanced": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"temperature": {
"display_name": "Temperature",

View file

@ -1,9 +1,10 @@
from typing import Optional
from langchain.llms.base import BaseLanguageModel
from langchain_community.chat_models.azure_openai import AzureChatOpenAI
from langchain_core.language_models import BaseLanguageModel
from langchain_openai import AzureChatOpenAI
from pydantic.v1 import SecretStr
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class AzureChatOpenAISpecsComponent(CustomComponent):
@ -65,11 +66,8 @@ class AzureChatOpenAISpecsComponent(CustomComponent):
},
"max_tokens": {
"display_name": "Max Tokens",
"value": 1000,
"required": False,
"field_type": "int",
"advanced": True,
"info": "Maximum number of tokens to generate.",
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"code": {"show": False},
}
@ -84,15 +82,19 @@ class AzureChatOpenAISpecsComponent(CustomComponent):
temperature: float = 0.7,
max_tokens: Optional[int] = 1000,
) -> BaseLanguageModel:
if api_key:
azure_api_key = SecretStr(api_key)
else:
azure_api_key = None
try:
llm = AzureChatOpenAI(
model=model,
azure_endpoint=azure_endpoint,
azure_deployment=azure_deployment,
api_version=api_version,
api_key=api_key,
api_key=azure_api_key,
temperature=temperature,
max_tokens=max_tokens,
max_tokens=max_tokens or None,
)
except Exception as e:
raise ValueError("Could not connect to AzureOpenAI API.") from e

View file

@ -1,10 +1,11 @@
from typing import Optional
from langchain_community.chat_models.baidu_qianfan_endpoint import QianfanChatEndpoint
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class QianfanChatEndpointComponent(CustomComponent):

View file

@ -2,7 +2,7 @@ from typing import Optional
from langchain_community.llms.baidu_qianfan_endpoint import QianfanLLMEndpoint
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel

View file

@ -46,9 +46,8 @@ class AnthropicLLM(CustomComponent):
},
"max_tokens": {
"display_name": "Max Tokens",
"field_type": "int",
"advanced": True,
"value": 256,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"temperature": {
"display_name": "Temperature",

View file

@ -1,8 +1,9 @@
from typing import Any, Dict, Optional
from langchain_community.chat_models.litellm import ChatLiteLLM, ChatLiteLLMException
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class ChatLiteLLMComponent(CustomComponent):
@ -81,12 +82,9 @@ class ChatLiteLLMComponent(CustomComponent):
"default": 1,
},
"max_tokens": {
"display_name": "Max tokens",
"field_type": "int",
"advanced": False,
"required": False,
"default": 256,
"info": "The maximum number of tokens to generate for each chat completion.",
"display_name": "Max Tokens",
"advanced": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"max_retries": {
"display_name": "Max retries",

View file

@ -77,7 +77,7 @@ class MistralAIModelComponent(CustomComponent):
output = ChatMistralAI(
model_name=model,
api_key=(SecretStr(mistral_api_key) if mistral_api_key else None),
max_tokens=max_tokens,
max_tokens=max_tokens or None,
temperature=temperature,
endpoint=mistral_api_base,
)

View file

@ -1,11 +1,11 @@
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
# from langchain_community.chat_models import ChatOllama
from langchain_community.chat_models import ChatOllama
from langchain_core.language_models.chat_models import BaseChatModel
# from langchain.chat_models import ChatOllama
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
# from langchain.callbacks.manager import CallbackManager
@ -182,7 +182,7 @@ class ChatOllamaComponent(CustomComponent):
num_ctx: Optional[int] = None,
num_gpu: Optional[int] = None,
format: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict] = None,
num_thread: Optional[int] = None,
repeat_penalty: Optional[float] = None,
stop: Optional[List[str]] = None,

View file

@ -3,10 +3,9 @@ from typing import Optional
from langchain_openai import ChatOpenAI
from pydantic.v1 import SecretStr
from langflow.base.models.openai_constants import MODEL_NAMES
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, NestedDict
from langflow.interface.custom.custom_component import CustomComponent
class ChatOpenAIComponent(CustomComponent):
@ -18,8 +17,8 @@ class ChatOpenAIComponent(CustomComponent):
return {
"max_tokens": {
"display_name": "Max Tokens",
"advanced": False,
"required": False,
"advanced": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"model_kwargs": {
"display_name": "Model Kwargs",
@ -52,7 +51,7 @@ class ChatOpenAIComponent(CustomComponent):
def build(
self,
max_tokens: Optional[int] = 256,
max_tokens: Optional[int] = 0,
model_kwargs: NestedDict = {},
model_name: str = "gpt-4o",
openai_api_base: Optional[str] = None,
@ -66,7 +65,7 @@ class ChatOpenAIComponent(CustomComponent):
else:
api_key = None
return ChatOpenAI(
max_tokens=max_tokens,
max_tokens=max_tokens or None,
model_kwargs=model_kwargs,
model=model_name,
base_url=openai_api_base,

View file

@ -1,10 +1,9 @@
from typing import List, Optional
from typing import Optional
from langchain_community.chat_models.vertexai import ChatVertexAI
from langchain_core.messages.base import BaseMessage
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
class ChatVertexAIComponent(CustomComponent):
@ -65,7 +64,6 @@ class ChatVertexAIComponent(CustomComponent):
self,
credentials: Optional[str],
project: str,
examples: Optional[List[BaseMessage]] = [],
location: str = "us-central1",
max_output_tokens: int = 128,
model_name: str = "chat-bison",
@ -76,7 +74,6 @@ class ChatVertexAIComponent(CustomComponent):
) -> BaseLanguageModel:
return ChatVertexAI(
credentials=credentials,
examples=examples,
location=location,
max_output_tokens=max_output_tokens,
model_name=model_name,

View file

@ -1,7 +1,10 @@
from langchain_community.llms.cohere import Cohere
from langchain_core.language_models.base import BaseLanguageModel
from typing import Optional
from langflow.interface.custom.custom_component import CustomComponent
from langchain_cohere import ChatCohere
from langchain_core.language_models.base import BaseLanguageModel
from pydantic.v1 import SecretStr
from langflow.custom import CustomComponent
class CohereComponent(CustomComponent):
@ -13,14 +16,22 @@ class CohereComponent(CustomComponent):
def build_config(self):
return {
"cohere_api_key": {"display_name": "Cohere API Key", "type": "password", "password": True},
"max_tokens": {"display_name": "Max Tokens", "default": 256, "type": "int", "show": True},
"max_tokens": {
"display_name": "Max Tokens",
"advanced": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"temperature": {"display_name": "Temperature", "default": 0.75, "type": "float", "show": True},
}
def build(
self,
cohere_api_key: str,
max_tokens: int = 256,
max_tokens: Optional[int] = 256,
temperature: float = 0.75,
) -> BaseLanguageModel:
return Cohere(cohere_api_key=cohere_api_key, max_tokens=max_tokens, temperature=temperature) # type: ignore
if cohere_api_key:
api_key = SecretStr(cohere_api_key)
else:
api_key = None
return ChatCohere(cohere_api_key=api_key, max_tokens=max_tokens or None, temperature=temperature) # type: ignore

View file

@ -3,8 +3,8 @@ from typing import Optional
from langchain_google_genai import ChatGoogleGenerativeAI # type: ignore
from pydantic.v1.types import SecretStr
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, RangeSpec
from langflow.interface.custom.custom_component import CustomComponent
class GoogleGenerativeAIComponent(CustomComponent):

View file

@ -1,9 +1,9 @@
from typing import Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.huggingface_endpoint import HuggingFaceEndpoint
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class HuggingFaceEndpointsComponent(CustomComponent):

View file

@ -1,9 +1,9 @@
from typing import List, Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.ollama import Ollama
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class OllamaLLM(CustomComponent):

View file

@ -1,9 +1,9 @@
from typing import Dict, Optional
from langflow.field_typing import BaseLanguageModel
from langchain_community.llms.vertexai import VertexAI
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class VertexAIComponent(CustomComponent):

View file

@ -49,9 +49,8 @@ class AnthropicLLM(LCModelComponent):
},
"max_tokens": {
"display_name": "Max Tokens",
"field_type": "int",
"advanced": True,
"value": 256,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"temperature": {
"display_name": "Temperature",

View file

@ -74,9 +74,8 @@ class AzureChatOpenAIComponent(LCModelComponent):
},
"max_tokens": {
"display_name": "Max Tokens",
"value": 1000,
"advanced": True,
"info": "Maximum number of tokens to generate.",
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"code": {"show": False},
"input_value": {"display_name": "Input"},
@ -117,7 +116,7 @@ class AzureChatOpenAIComponent(LCModelComponent):
api_version=api_version,
api_key=secret_api_key,
temperature=temperature,
max_tokens=max_tokens,
max_tokens=max_tokens or None,
)
except Exception as e:
raise ValueError("Could not connect to AzureOpenAI API.") from e

View file

@ -93,9 +93,7 @@ class ChatLiteLLMModelComponent(LCModelComponent):
},
"max_tokens": {
"display_name": "Max tokens",
"field_type": "int",
"advanced": False,
"required": False,
"default": 256,
"info": "The maximum number of tokens to generate for each chat completion.",
},

View file

@ -1,10 +1,10 @@
from typing import Optional
from langchain_community.chat_models.cohere import ChatCohere
from pydantic.v1 import SecretStr
from langflow.field_typing import Text
from langflow.base.constants import STREAM_INFO_TEXT
from langflow.base.models.model import LCModelComponent
from langchain_cohere import ChatCohere
class CohereComponent(LCModelComponent):
@ -34,9 +34,7 @@ class CohereComponent(LCModelComponent):
"max_tokens": {
"display_name": "Max Tokens",
"advanced": True,
"default": 256,
"type": "int",
"show": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"temperature": {
"display_name": "Temperature",

View file

@ -31,6 +31,7 @@ class MistralAIModelComponent(LCModelComponent):
"max_tokens": {
"display_name": "Max Tokens",
"advanced": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"model_name": {
"display_name": "Model Name",
@ -125,7 +126,7 @@ class MistralAIModelComponent(LCModelComponent):
api_key = None
chat_model = ChatMistralAI(
max_tokens=max_tokens,
max_tokens=max_tokens or None,
model_name=model_name,
endpoint=mistral_api_base,
api_key=api_key,

View file

@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional
# from langchain_community.chat_models import ChatOllama
from langchain_community.chat_models import ChatOllama
@ -229,7 +229,7 @@ class ChatOllamaComponent(LCModelComponent):
num_ctx: Optional[int] = None,
num_gpu: Optional[int] = None,
format: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict] = None,
num_thread: Optional[int] = None,
repeat_penalty: Optional[float] = None,
stop: Optional[List[str]] = None,

View file

@ -32,6 +32,7 @@ class OpenAIModelComponent(LCModelComponent):
"max_tokens": {
"display_name": "Max Tokens",
"advanced": True,
"info": "The maximum number of tokens to generate. Set to 0 for unlimited tokens.",
},
"model_kwargs": {
"display_name": "Model Kwargs",
@ -93,7 +94,7 @@ class OpenAIModelComponent(LCModelComponent):
api_key = None
output = ChatOpenAI(
max_tokens=max_tokens,
max_tokens=max_tokens or None,
model_kwargs=model_kwargs,
model=model_name,
base_url=openai_api_base,

View file

@ -1,6 +1,5 @@
from typing import List, Optional
from typing import Optional
from langchain_core.messages.base import BaseMessage
from langflow.base.constants import STREAM_INFO_TEXT
from langflow.base.models.model import LCModelComponent
@ -93,7 +92,6 @@ class ChatVertexAIComponent(LCModelComponent):
input_value: Text,
credentials: Optional[str],
project: str,
examples: Optional[List[BaseMessage]] = [],
location: str = "us-central1",
max_output_tokens: int = 128,
model_name: str = "chat-bison",
@ -112,7 +110,6 @@ class ChatVertexAIComponent(LCModelComponent):
)
output = ChatVertexAI(
credentials=credentials,
examples=examples,
location=location,
max_output_tokens=max_output_tokens,
model_name=model_name,

View file

@ -1,9 +1,9 @@
from typing import Optional
from langchain.schema import BaseRetriever
from langchain_community.retrievers import AmazonKendraRetriever
from langchain_core.retrievers import BaseRetriever
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class AmazonKendraRetrieverComponent(CustomComponent):

View file

@ -1,10 +1,10 @@
from typing import Optional
from langchain.schema import BaseRetriever
from langchain_community.retrievers import MetalRetriever
from langchain_core.retrievers import BaseRetriever
from metal_sdk.metal import Metal # type: ignore
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
class MetalRetrieverComponent(CustomComponent):

View file

@ -2,8 +2,8 @@ from typing import Optional
from langchain.retrievers import MultiQueryRetriever
from langflow.field_typing import BaseRetriever, PromptTemplate, BaseLanguageModel
from langflow.interface.custom.custom_component import CustomComponent
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseRetriever, PromptTemplate, Text
class MultiQueryRetrieverComponent(CustomComponent):
@ -41,10 +41,13 @@ class MultiQueryRetrieverComponent(CustomComponent):
self,
llm: BaseLanguageModel,
retriever: BaseRetriever,
prompt: Optional[PromptTemplate] = None,
prompt: Optional[Text] = None,
parser_key: str = "lines",
) -> MultiQueryRetriever:
if not prompt:
return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, parser_key=parser_key)
else:
return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, prompt=prompt, parser_key=parser_key)
prompt_template = PromptTemplate.from_template(prompt)
return MultiQueryRetriever.from_llm(
llm=llm, retriever=retriever, prompt=prompt_template, parser_key=parser_key
)

Some files were not shown because too many files have changed in this diff Show more