Skip to content

FROM feat/186-add-scalar-swagger-client TO development #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions .cursorindexingignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.env*
**/logs
**/__pycache__
**/__pycache__/*
**/logs/*
**/.venv
**/.venv/*
**/node_modules
**/node_modules/*
**/dist
**/dist/*
**/build
**/build/*
**/env
**/env/*
**/src/public
**/src/public/*
**/src/templates
**/src/templates/*
**/src/static
**/src/static/*
**/src/static/css
**/src/static/css/*
**/src/static/js
**/src/static/js/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
**/logs/
**/sandbox/db/*
**/site
**/docker/searxng/settings.yml.new

backend/src/public
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- bugfix/28-cannot-auth-tools-list (2024-11-30)

### Changed
- feat/186-add-scalar-swagger-client (2025-03-12)
- feat/173-test-a-tool-call (2025-03-04)
- feat/165-oauth-init (2025-03-01)
- feat/153-clear-chat-inputs (2025-02-27)
Expand Down
25 changes: 25 additions & 0 deletions backend/.cursorindexingignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.env*
**/logs
**/__pycache__
**/__pycache__/*
**/logs/*
**/.venv
**/.venv/*
**/node_modules
**/node_modules/*
**/dist
**/dist/*
**/build
**/build/*
**/env
**/env/*
**/src/public
**/src/public/*
**/src/templates
**/src/templates/*
**/src/static
**/src/static/*
**/src/static/css
**/src/static/css/*
**/src/static/js
**/src/static/js/*
52 changes: 52 additions & 0 deletions backend/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,58 @@
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Python: Single Test",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"tests/unit/repos/test_agent_repo.py",
"-v"
],
"console": "integratedTerminal",
"justMyCode": true,
"envFile": "${workspaceFolder}/.env.test"
},
{
"name": "Python: Run Tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"tests/",
"-v"
],
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env.test"
},
{
"name": "Python: Run Unit Tests Only",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"tests/unit/",
"-v"
],
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env.test"
},
{
"name": "Python: Run Integration Tests Only",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"tests/integration/",
"-v"
],
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env.test"
}
]
}
33 changes: 23 additions & 10 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import os
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
import os
from scalar_fastapi import get_scalar_api_reference

from src.routes.v0 import tool, llm, thread, retrieve, source, info, auth, token, storage, settings
from src.routes.v0 import tool, llm, thread, retrieve, source, info, auth, token, storage, settings, agent, model
from src.constants import (
HOST,
PORT,
LOG_LEVEL,
APP_VERSION
APP_VERSION,
APP_ENV
)
from src.utils.migrations import run_migrations

Expand All @@ -24,13 +26,15 @@ async def lifespan(app: FastAPI):
print(f"LOG_LEVEL: {LOG_LEVEL}")
print(f"HOST: {HOST}")
print(f"PORT: {PORT}")
run_migrations()
print(f"APP_ENV: {APP_ENV}")
if APP_ENV == "production" or APP_ENV == "staging":
run_migrations()
yield
# Shutdown
pass

app = FastAPI(
title="Armada by Prompt Engineers AI 🤖",
title="Enso by Prompt Engineers AI 🤖",
version=APP_VERSION,
description=(
"This is a simple API for building chatbots with LangGraph. "
Expand All @@ -43,11 +47,10 @@ async def lifespan(app: FastAPI):
"email": "[email protected]"
},
debug=True,
docs_url="/api",
docs_url=None,
lifespan=lifespan
)


# Add CORS middleware
app.add_middleware(
CORSMiddleware,
Expand All @@ -57,18 +60,28 @@ async def lifespan(app: FastAPI):
allow_headers=["*"],
)


@app.get("/api", include_in_schema=False)
async def scalar_html():
return get_scalar_api_reference(
openapi_url=app.openapi_url,
title=app.title,
)

# Include routers
PREFIX = "/api"
app.include_router(auth, prefix=PREFIX)
app.include_router(info, prefix=PREFIX)
app.include_router(token, prefix=PREFIX)
app.include_router(llm, prefix=PREFIX)
app.include_router(thread, prefix=PREFIX)
app.include_router(tool, prefix=PREFIX)
app.include_router(model, prefix=PREFIX)
app.include_router(settings, prefix=PREFIX)
app.include_router(agent, prefix=PREFIX)
app.include_router(retrieve, prefix=PREFIX)
app.include_router(source, prefix=PREFIX)
app.include_router(token, prefix=PREFIX)
app.include_router(storage, prefix=PREFIX)
app.include_router(settings, prefix=PREFIX)

# Mount specific directories only if they exist
app.mount("/docs", StaticFiles(directory="src/public/docs", html=True), name="docs")
Expand All @@ -79,7 +92,7 @@ async def lifespan(app: FastAPI):
app.mount("/icons", StaticFiles(directory="src/public/icons"), name="icons")

# Function to serve static files with fallback
@app.get("/{filename:path}")
@app.get("/{filename:path}", include_in_schema=False)
async def serve_static_or_index(filename: str, request: Request):
# List of static files to check for at the root
static_files = ["manifest.json", "sw.js", "favicon.ico", "robots.txt", "manifest.webmanifest"]
Expand Down
33 changes: 33 additions & 0 deletions backend/migrations/versions/0005_add_user_id_to_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Add user_id to settings table

Revision ID: 0005_add_user_id_to_settings
Revises: 00000000000004_add_settings_table
Create Date: 2023-02-10 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '0005_add_user_id_to_settings'
down_revision = '00000000000004_add_settings_table'
branch_labels = None
depends_on = None


def upgrade() -> None:
# Add user_id column to settings table
op.add_column('settings',
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True))

# Add index on user_id for faster lookups
op.create_index('idx_settings_user_id', 'settings', ['user_id'])


def downgrade() -> None:
# Remove index first
op.drop_index('idx_settings_user_id')

# Remove the column
op.drop_column('settings', 'user_id')
63 changes: 63 additions & 0 deletions backend/migrations/versions/0006_add_agents_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Create agents table for storing agents

Revision ID: 0006_add_agents_table
Revises: 0005_add_user_id_to_settings
Create Date: 2025-02-10 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '0006_add_agents_table'
down_revision = '0005_add_user_id_to_settings'
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
'agents',
sa.Column(
'id',
postgresql.UUID(as_uuid=True),
server_default=sa.text('gen_random_uuid()'),
primary_key=True
),
sa.Column(
'user_id',
postgresql.UUID(as_uuid=True),
sa.ForeignKey('users.id', ondelete='CASCADE'),
nullable=False
),
sa.Column('name', sa.String(), nullable=False),
sa.Column('slug', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('public', sa.Boolean(), server_default='false', nullable=False),
sa.Column('revision_number', sa.Integer(), nullable=False),
sa.Column(
'created_at',
sa.DateTime(timezone=True),
server_default=sa.text('now()'),
nullable=False
),
sa.Column(
'updated_at',
sa.DateTime(timezone=True),
server_default=sa.text('now()'),
onupdate=sa.text('now()'),
nullable=False
),
# Create a unique constraint on slug
sa.UniqueConstraint('slug', name='uq_agents_slug'),
)

# Add index on slug for faster lookups
op.create_index('idx_agents_slug', 'agents', ['slug'])


def downgrade() -> None:
op.drop_index('idx_agents_slug')
op.drop_table('agents')

Loading