Skip to content

Commit

Permalink
Merge branch 'main' into docker-build-simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
phact authored Oct 29, 2024
2 parents 210073b + ccba14b commit 446d466
Show file tree
Hide file tree
Showing 69 changed files with 1,797 additions and 1,090 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"GitHub.vscode-pull-request-github"
]
}
},
"tasks": {
"test": "make unit_tests"
}

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
Expand Down
Binary file added localhost-19-2.db
Binary file not shown.
22 changes: 4 additions & 18 deletions src/backend/base/langflow/api/v1/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@router.get("/")
def get_api_keys_route(
async def get_api_keys_route(
db: DbSession,
current_user: CurrentActiveUser,
) -> ApiKeysResponse:
Expand All @@ -33,7 +33,7 @@ def get_api_keys_route(


@router.post("/")
def create_api_key_route(
async def create_api_key_route(
req: ApiKeyCreate,
current_user: CurrentActiveUser,
db: DbSession,
Expand All @@ -46,7 +46,7 @@ def create_api_key_route(


@router.delete("/{api_key_id}", dependencies=[Depends(auth_utils.get_current_active_user)])
def delete_api_key_route(
async def delete_api_key_route(
api_key_id: UUID,
db: DbSession,
):
Expand All @@ -58,7 +58,7 @@ def delete_api_key_route(


@router.post("/store")
def save_store_api_key(
async def save_store_api_key(
api_key_request: ApiKeyCreateRequest,
response: Response,
current_user: CurrentActiveUser,
Expand Down Expand Up @@ -90,17 +90,3 @@ def save_store_api_key(
raise HTTPException(status_code=400, detail=str(e)) from e

return {"detail": "API Key saved"}


@router.delete("/store")
def delete_store_api_key(
current_user: CurrentActiveUser,
db: DbSession,
):
try:
current_user.store_api_key = None
db.commit()
except Exception as e:
raise HTTPException(status_code=400, detail=str(e)) from e

return {"detail": "API Key deleted"}
5 changes: 3 additions & 2 deletions src/backend/base/langflow/api/v1/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from langflow.graph.graph.base import Graph
from langflow.graph.utils import log_vertex_build
from langflow.schema.schema import OutputValue
from langflow.services.cache.utils import CacheMiss
from langflow.services.chat.service import ChatService
from langflow.services.deps import get_chat_service, get_session, get_telemetry_service
from langflow.services.telemetry.schema import ComponentPayload, PlaygroundPayload
Expand Down Expand Up @@ -493,7 +494,7 @@ async def build_vertex(
error_message = None
try:
cache = await chat_service.get_cache(flow_id_str)
if not cache:
if isinstance(cache, CacheMiss):
# If there's no cache
logger.warning(f"No cache found for {flow_id_str}. Building graph starting at {vertex_id}")
graph: Graph = await build_graph_from_db(
Expand Down Expand Up @@ -621,7 +622,7 @@ async def _stream_vertex(flow_id: str, vertex_id: str, chat_service: ChatService
yield str(StreamData(event="error", data={"error": str(exc)}))
return

if not cache:
if isinstance(cache, CacheMiss):
# If there's no cache
msg = f"No cache found for {flow_id}."
logger.error(msg)
Expand Down
10 changes: 6 additions & 4 deletions src/backend/base/langflow/api/v1/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
get_task_service,
get_telemetry_service,
)
from langflow.services.settings.feature_flags import FEATURE_FLAGS
from langflow.services.telemetry.schema import RunPayload
from langflow.utils.constants import SIDEBAR_CATEGORIES
from langflow.utils.version import get_version_info
Expand Down Expand Up @@ -548,7 +549,7 @@ async def create_upload_file(

# get endpoint to return version of langflow
@router.get("/version")
def get_version():
async def get_version():
return get_version_info()


Expand Down Expand Up @@ -624,16 +625,17 @@ async def custom_component_update(


@router.get("/config", response_model=ConfigResponse)
def get_config():
async def get_config():
try:
from langflow.services.deps import get_settings_service

settings_service: SettingsService = get_settings_service()
return settings_service.settings.model_dump()

return {"feature_flags": FEATURE_FLAGS, **settings_service.settings.model_dump()}
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc


@router.get("/sidebar_categories")
def get_sidebar_categories() -> SidebarCategoriesResponse:
async def get_sidebar_categories() -> SidebarCategoriesResponse:
return SidebarCategoriesResponse(categories=SIDEBAR_CATEGORIES)
14 changes: 7 additions & 7 deletions src/backend/base/langflow/api/v1/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


@router.post("/", response_model=FlowRead, status_code=201)
def create_flow(
async def create_flow(
*,
session: DbSession,
flow: FlowCreate,
Expand Down Expand Up @@ -124,7 +124,7 @@ def create_flow(


@router.get("/", response_model=list[FlowRead] | Page[FlowRead] | list[FlowHeader], status_code=200)
def read_flows(
async def read_flows(
*,
current_user: CurrentActiveUser,
session: DbSession,
Expand Down Expand Up @@ -226,7 +226,7 @@ def _read_flow(


@router.get("/{flow_id}", response_model=FlowRead, status_code=200)
def read_flow(
async def read_flow(
*,
session: DbSession,
flow_id: UUID,
Expand All @@ -239,7 +239,7 @@ def read_flow(


@router.patch("/{flow_id}", response_model=FlowRead, status_code=200)
def update_flow(
async def update_flow(
*,
session: DbSession,
flow_id: UUID,
Expand Down Expand Up @@ -320,7 +320,7 @@ async def delete_flow(


@router.post("/batch/", response_model=list[FlowRead], status_code=201)
def create_flows(
async def create_flows(
*,
session: DbSession,
flow_list: FlowListCreate,
Expand Down Expand Up @@ -357,7 +357,7 @@ async def upload_file(
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 = await create_flow(session=session, flow=flow, current_user=current_user)
response_list.append(response)

return response_list
Expand Down Expand Up @@ -442,7 +442,7 @@ async def download_multiple_file(


@router.get("/basic_examples/", response_model=list[FlowRead], status_code=200)
def read_basic_examples(
async def read_basic_examples(
*,
session: DbSession,
):
Expand Down
8 changes: 4 additions & 4 deletions src/backend/base/langflow/api/v1/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


@router.post("/", response_model=FolderRead, status_code=201)
def create_folder(
async def create_folder(
*,
session: DbSession,
folder: FolderCreate,
Expand Down Expand Up @@ -82,7 +82,7 @@ def create_folder(


@router.get("/", response_model=list[FolderRead], status_code=200)
def read_folders(
async def read_folders(
*,
session: DbSession,
current_user: CurrentActiveUser,
Expand All @@ -100,7 +100,7 @@ def read_folders(


@router.get("/{folder_id}", response_model=FolderWithPaginatedFlows | FolderReadWithFlows, status_code=200)
def read_folder(
async def read_folder(
*,
session: DbSession,
folder_id: str,
Expand Down Expand Up @@ -145,7 +145,7 @@ def read_folder(


@router.patch("/{folder_id}", response_model=FolderRead, status_code=200)
def update_folder(
async def update_folder(
*,
session: DbSession,
folder_id: str,
Expand Down
2 changes: 2 additions & 0 deletions src/backend/base/langflow/api/v1/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from langflow.services.database.models.base import orjson_dumps
from langflow.services.database.models.flow import FlowCreate, FlowRead
from langflow.services.database.models.user import UserRead
from langflow.services.settings.feature_flags import FeatureFlags
from langflow.services.tracing.schema import Log
from langflow.utils.util_strings import truncate_long_strings

Expand Down Expand Up @@ -350,6 +351,7 @@ class FlowDataRequest(BaseModel):


class ConfigResponse(BaseModel):
feature_flags: FeatureFlags
frontend_timeout: int
auto_saving: bool
auto_saving_interval: int
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/api/v1/starter_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@router.get("/", dependencies=[Depends(get_current_active_user)], status_code=200)
def get_starter_projects() -> list[GraphDump]:
async def get_starter_projects() -> list[GraphDump]:
"""Get a list of starter projects."""
from langflow.initial_setup.load import get_starter_projects_dump

Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/api/v1/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_optional_user_store_api_key(user: CurrentActiveUser):


@router.get("/check/")
def check_if_store_is_enabled():
async def check_if_store_is_enabled():
return {
"enabled": get_settings_service().settings.store,
}
Expand Down
12 changes: 6 additions & 6 deletions src/backend/base/langflow/api/v1/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@router.post("/", response_model=UserRead, status_code=201)
def add_user(
async def add_user(
user: UserCreate,
session: DbSession,
) -> User:
Expand All @@ -46,15 +46,15 @@ def add_user(


@router.get("/whoami", response_model=UserRead)
def read_current_user(
async def read_current_user(
current_user: CurrentActiveUser,
) -> User:
"""Retrieve the current user's data."""
return current_user


@router.get("/", dependencies=[Depends(get_current_active_superuser)])
def read_all_users(
async def read_all_users(
*,
skip: int = 0,
limit: int = 10,
Expand All @@ -74,7 +74,7 @@ def read_all_users(


@router.patch("/{user_id}", response_model=UserRead)
def patch_user(
async def patch_user(
user_id: UUID,
user_update: UserUpdate,
user: CurrentActiveUser,
Expand All @@ -101,7 +101,7 @@ def patch_user(


@router.patch("/{user_id}/reset-password", response_model=UserRead)
def reset_password(
async def reset_password(
user_id: UUID,
user_update: UserUpdate,
user: CurrentActiveUser,
Expand All @@ -124,7 +124,7 @@ def reset_password(


@router.delete("/{user_id}")
def delete_user(
async def delete_user(
user_id: UUID,
current_user: Annotated[User, Depends(get_current_active_superuser)],
session: DbSession,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/base/langflow/api/v1/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@router.post("/code", status_code=200)
def post_validate_code(code: Code) -> CodeValidationResponse:
async def post_validate_code(code: Code) -> CodeValidationResponse:
try:
errors = validate_code(code.code)
return CodeValidationResponse(
Expand All @@ -23,7 +23,7 @@ def post_validate_code(code: Code) -> CodeValidationResponse:


@router.post("/prompt", status_code=200)
def post_validate_prompt(prompt_request: ValidatePromptRequest) -> PromptValidationResponse:
async def post_validate_prompt(prompt_request: ValidatePromptRequest) -> PromptValidationResponse:
try:
if not prompt_request.frontend_node:
return PromptValidationResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/backend/base/langflow/api/v1/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@router.post("/", response_model=VariableRead, status_code=201)
def create_variable(
async def create_variable(
*,
session: DbSession,
variable: VariableCreate,
Expand Down Expand Up @@ -48,7 +48,7 @@ def create_variable(


@router.get("/", response_model=list[VariableRead], status_code=200)
def read_variables(
async def read_variables(
*,
session: DbSession,
current_user: CurrentActiveUser,
Expand All @@ -65,7 +65,7 @@ def read_variables(


@router.patch("/{variable_id}", response_model=VariableRead, status_code=200)
def update_variable(
async def update_variable(
*,
session: DbSession,
variable_id: UUID,
Expand All @@ -92,7 +92,7 @@ def update_variable(


@router.delete("/{variable_id}", status_code=204)
def delete_variable(
async def delete_variable(
*,
session: DbSession,
variable_id: UUID,
Expand Down
4 changes: 3 additions & 1 deletion src/backend/base/langflow/base/astra_assistants/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
from astra_assistants import OpenAIWithDefaultKey, patch
from astra_assistants.tools.tool_interface import ToolInterface

from langflow.services.cache.utils import CacheMiss

client_lock = threading.Lock()
client = None


def get_patched_openai_client(shared_component_cache):
os.environ["ASTRA_ASSISTANTS_QUIET"] = "true"
client = shared_component_cache.get("client")
if client is None:
if isinstance(client, CacheMiss):
client = patch(OpenAIWithDefaultKey())
shared_component_cache.set("client", client)
return client
Expand Down
Loading

0 comments on commit 446d466

Please sign in to comment.