Refactor "created_at" column type for consistency and fix cancel middleware (#2316) (#2320)

* chore: update linting workflows to include dev branch in merge_group

* Update README.md

Add 1.0 banner

* Update README.md

* chore: update package versions in pyproject.toml files

* Refactor "created_at" column type for consistency and fix cancel middleware (#2316)

* chore: update linting workflows to include dev branch in merge_group

* Update README.md

Add 1.0 banner

* Update README.md

* chore: update package versions in pyproject.toml files

* refactor: update "created_at" column type to use the "sa" module for consistency

* Update README.md

Add 1.0 banner

* chore: Remove unused import in ToolCallingAgent.py

* fix: adapt RequestCancelledMiddleware to handle cancelled requests

* chore: Remove unused import in test_helper_components.py

* refactor: Declare queue variable with explicit type in RequestCancelledMiddleware

---------

Co-authored-by: Rodrigo Nader <rodrigosilvanader@gmail.com>

* chore: Update AstraDB.py imports and method signature for search_documents

* chore: Update package versions in pyproject.toml files

* chore: Update run-name in release.yml for Langflow Release

* fix: add call to _add_documents_to_vector_store in AstraDB component

---------

Co-authored-by: Rodrigo Nader <rodrigosilvanader@gmail.com>
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-24 13:15:54 -07:00 committed by GitHub
commit d85657f214
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 126 additions and 79 deletions

View file

@ -34,7 +34,7 @@ def upgrade() -> None:
sa.Column("provider", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column("created_at", sqlmodel.sql.sqltypes.DateTime(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)

View file

@ -2,7 +2,6 @@ from typing import Dict, List, cast
from langchain.agents import AgentExecutor, BaseSingleActionAgent
from langchain.agents.tool_calling_agent.base import create_tool_calling_agent
from langchain_core.messages import BaseMessage
from langchain_core.prompts import ChatPromptTemplate
from langflow.custom import Component

View file

@ -3,13 +3,13 @@ from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent
from langflow.io import (
BoolInput,
DataInput,
DropdownInput,
HandleInput,
IntInput,
MultilineInput,
SecretStrInput,
StrInput,
DataInput,
)
from langflow.schema import Data
@ -196,6 +196,10 @@ class AstraVectorStoreComponent(LCVectorStoreComponent):
except Exception as e:
raise ValueError(f"Error initializing AstraDBVectorStore: {str(e)}") from e
if hasattr(self, "ingest_data") and self.ingest_data:
logger.debug("Ingesting data into the Vector Store.")
self._add_documents_to_vector_store(vector_store)
self.status = self._astradb_collection_to_data(vector_store.collection)
return vector_store
@ -216,7 +220,7 @@ class AstraVectorStoreComponent(LCVectorStoreComponent):
else:
logger.debug("No documents to add to the Vector Store.")
def search_documents(self):
def search_documents(self) -> list[Data]:
vector_store = self.build_vector_store()
logger.debug(f"Search input: {self.search_input}")

View file

@ -6,7 +6,7 @@ from typing import Optional
from urllib.parse import urlencode
import nest_asyncio # type: ignore
from fastapi import FastAPI, Request
from fastapi import FastAPI, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
@ -32,22 +32,17 @@ from langflow.utils.logger import configure
warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20)
class RequestCancelledMiddleware:
class RequestCancelledMiddleware(BaseHTTPMiddleware):
def __init__(self, app):
self.app = app
super().__init__(app)
async def __call__(self, scope, receive, send):
if scope["type"] != "http":
await self.app(scope, receive, send)
return
async def dispatch(self, request: Request, call_next):
queue: asyncio.Queue = asyncio.Queue()
# Let's make a shared queue for the request messages
queue = asyncio.Queue()
async def message_poller(sentinel, handler_task):
async def message_poller(sentinel, handler_task, request):
nonlocal queue
while True:
message = await receive()
message = await request.receive
if message["type"] == "http.disconnect":
handler_task.cancel()
return sentinel # Break the loop
@ -56,13 +51,14 @@ class RequestCancelledMiddleware:
await queue.put(message)
sentinel = object()
handler_task = asyncio.create_task(self.app(scope, queue.get, send))
asyncio.create_task(message_poller(sentinel, handler_task))
handler_task = asyncio.create_task(call_next(request))
asyncio.create_task(message_poller(sentinel, handler_task, request))
try:
return await handler_task
response = await handler_task
return response
except asyncio.CancelledError:
pass
return Response("Request was cancelled", status_code=499)
class JavaScriptMIMETypeMiddleware(BaseHTTPMiddleware):

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "langflow-base"
version = "0.0.77"
version = "0.0.78"
description = "A Python package with a built-in web application"
authors = ["Langflow <contact@langflow.org>"]
maintainers = [