Add variables_router to APIRouter
This commit is contained in:
parent
2ba305bc7a
commit
6d258a78ea
3 changed files with 50 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ from langflow.api.v1 import (
|
|||
store_router,
|
||||
users_router,
|
||||
validate_router,
|
||||
variables_router,
|
||||
)
|
||||
|
||||
router = APIRouter(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import operator
|
||||
from pathlib import Path
|
||||
from typing import (TYPE_CHECKING, Any, Callable, ClassVar, List, Optional,
|
||||
Sequence, Union)
|
||||
from typing import TYPE_CHECKING, Any, Callable, ClassVar, List, Optional, Sequence, Union
|
||||
from uuid import UUID
|
||||
|
||||
import yaml
|
||||
|
|
@ -12,14 +11,14 @@ from sqlmodel import select
|
|||
|
||||
from langflow.interface.custom.code_parser.utils import (
|
||||
extract_inner_type_from_generic_alias,
|
||||
extract_union_types_from_generic_alias)
|
||||
extract_union_types_from_generic_alias,
|
||||
)
|
||||
from langflow.interface.custom.custom_component.component import Component
|
||||
from langflow.schema import Record
|
||||
from langflow.schema.dotdict import dotdict
|
||||
from langflow.services.database.models.flow import Flow
|
||||
from langflow.services.database.utils import session_getter
|
||||
from langflow.services.deps import get_db_service, get_storage_service, get_variable_service
|
||||
get_variable_service)
|
||||
from langflow.services.storage.service import StorageService
|
||||
from langflow.utils import validate
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
from datetime import UTC, datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from sqlmodel import Field, Relationship, SQLModel
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.database.models.user.model import User
|
||||
|
||||
|
||||
def utc_now():
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
class VariableBase(SQLModel):
|
||||
name: Optional[str] = Field(None, description="Name of the variable")
|
||||
value: Optional[str] = Field(None, description="Encrypted value of the variable")
|
||||
type: Optional[str] = Field(None, description="Type of the variable")
|
||||
|
||||
|
||||
class Variable(VariableBase, table=True):
|
||||
id: Optional[UUID] = Field(default_factory=uuid4, primary_key=True, description="Unique ID for the variable")
|
||||
# name is unique per user
|
||||
created_at: datetime = Field(default_factory=utc_now, description="Creation time of the variable")
|
||||
updated_at: Optional[datetime] = Field(None, description="Last update time of the variable")
|
||||
# foreign key to user table
|
||||
user_id: UUID = Field(description="User ID associated with this variable", foreign_key="user.id")
|
||||
user: "User" = Relationship(back_populates="variables")
|
||||
|
||||
|
||||
class VariableCreate(VariableBase):
|
||||
# AcceptedProviders is a custom Enum
|
||||
type: Optional[str] = Field(None, description="Type of the variable")
|
||||
|
||||
|
||||
class VariableRead(SQLModel):
|
||||
id: UUID
|
||||
name: Optional[str] = Field(None, description="Name of the variable")
|
||||
type: Optional[str] = Field(None, description="Type of the variable")
|
||||
|
||||
|
||||
class VariableUpdate(SQLModel):
|
||||
id: UUID # Include the ID for updating
|
||||
name: Optional[str] = Field(None, description="Name of the variable")
|
||||
value: Optional[str] = Field(None, description="Encrypted value of the variable")
|
||||
Loading…
Add table
Add a link
Reference in a new issue