Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/routes/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from api.loaders.postgres_loader import PostgresLoader
from api.loaders.mysql_loader import MySQLLoader

from api.routes.tokens import UNAUTHORIZED_RESPONSE

database_router = APIRouter(tags=["Database Connection"])

# Use the same delimiter as in the JavaScript frontend for streaming chunks
Expand All @@ -27,7 +29,7 @@ class DatabaseConnectionRequest(BaseModel):
url: str

@database_router.post("/database", operation_id="connect_database", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def connect_database(request: Request, db_request: DatabaseConnectionRequest):
Expand Down
17 changes: 10 additions & 7 deletions api/routes/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
from api.loaders.mysql_loader import MySQLLoader
from api.memory.graphiti_tool import MemoryTool

from api.routes.tokens import UNAUTHORIZED_RESPONSE

# Use the same delimiter as in the JavaScript
MESSAGE_DELIMITER = "|||FALKORDB_MESSAGE_BOUNDARY|||"

graphs_router = APIRouter(tags=["Graphs & Databases"])

GENERAL_PREFIX = os.getenv("GENERAL_PREFIX")


class GraphData(BaseModel):
"""Graph data model.

Expand Down Expand Up @@ -110,7 +113,7 @@ def _graph_name(request: Request, graph_id:str) -> str:
return f"{request.state.user_id}_{graph_id}"

@graphs_router.get("", operation_id="list_databases", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def list_graphs(request: Request):
Expand All @@ -132,7 +135,7 @@ async def list_graphs(request: Request):
return JSONResponse(content=filtered_graphs)

@graphs_router.get("/{graph_id}/data", operation_id="database_schema", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def get_graph_data(request: Request, graph_id: str): # pylint: disable=too-many-locals,too-many-branches
Expand Down Expand Up @@ -231,7 +234,7 @@ async def get_graph_data(request: Request, graph_id: str): # pylint: disable=to


@graphs_router.post("", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def load_graph(request: Request, data: GraphData = None, file: UploadFile = File(None)): # pylint: disable=unused-argument
Expand Down Expand Up @@ -267,7 +270,7 @@ async def load_graph(request: Request, data: GraphData = None, file: UploadFile
raise HTTPException(status_code=415, detail="Unsupported Content-Type")

@graphs_router.post("/{graph_id}", operation_id="query_database", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def query_graph(request: Request, graph_id: str, chat_data: ChatRequest): # pylint: disable=too-many-statements
Expand Down Expand Up @@ -661,7 +664,7 @@ async def generate(): # pylint: disable=too-many-locals,too-many-branches,too-m


@graphs_router.post("/{graph_id}/confirm", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def confirm_destructive_operation(
Expand Down Expand Up @@ -825,7 +828,7 @@ async def generate_confirmation():


@graphs_router.post("/{graph_id}/refresh", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def refresh_graph_schema(request: Request, graph_id: str):
Expand Down Expand Up @@ -856,7 +859,7 @@ async def refresh_graph_schema(request: Request, graph_id: str):
raise HTTPException(status_code=500, detail="Internal server error while refreshing schema") # pylint: disable=raise-missing-from

@graphs_router.delete("/{graph_id}", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def delete_graph(request: Request, graph_id: str):
Expand Down
7 changes: 4 additions & 3 deletions api/routes/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from api.auth.user_management import token_required
from api.extensions import db

UNAUTHORIZED_RESPONSE = {"description": "Unauthorized - Please log in or provide a valid API token"}

# Router
tokens_router = APIRouter(tags=["API Tokens"])
Expand All @@ -25,7 +26,7 @@ class TokenListResponse(BaseModel):
tokens: List[TokenListItem]

@tokens_router.post("/generate", response_model=TokenListItem, responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def generate_token(request: Request) -> TokenListItem:
Expand Down Expand Up @@ -70,7 +71,7 @@ async def generate_token(request: Request) -> TokenListItem:
) from e

@tokens_router.get("/list", response_model=TokenListResponse, responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def list_tokens(request: Request) -> TokenListResponse:
Expand Down Expand Up @@ -110,7 +111,7 @@ async def list_tokens(request: Request) -> TokenListResponse:
) from e

@tokens_router.delete("/{token_id}", responses={
401: {"description": "Unauthorized - Please log in or provide a valid API token"}
401: UNAUTHORIZED_RESPONSE
})
@token_required
async def delete_token(request: Request, token_id: str) -> JSONResponse:
Expand Down
11 changes: 11 additions & 0 deletions apprunner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 1.0
runtime: python3
build:
commands:
build:
- pip install pipenv
- pipenv install --deploy --ignore-pipfile
run:
command: pipenv run uvicorn main:app --host 0.0.0.0 --port 8000
network:
port: 8000
Loading