Fix endpoint compatibility
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -149,3 +149,6 @@ cython_debug/
|
||||
|
||||
# OS X
|
||||
.DS_Store
|
||||
|
||||
# User custom folders
|
||||
external_component/
|
||||
|
||||
@@ -35,7 +35,7 @@ def create_application() -> FastAPI:
|
||||
application.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_credentials=False, # Changed to False for better compat with allow_origins=["*"]
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# Storyline AI Gateway - Implementation Plan
|
||||
|
||||
## Project Overview
|
||||
A FastAPI-based gateway for e-learning modules (Articulate Storyline) to access LLM services (Gemini, OpenAI) with centralized authentication and rate limiting.
|
||||
|
||||
## Tech Stack
|
||||
- **Framework**: FastAPI
|
||||
- **Server**: Uvicorn
|
||||
- **Rate Limiting**: Slowapi (limiter)
|
||||
- **Auth**: Header-based API Key (`X-API-Key`)
|
||||
- **LLMs**: Google Gemini, OpenAI
|
||||
|
||||
## Directory Structure
|
||||
- `app/main.py`: Application entry point and middleware configuration.
|
||||
- `app/core/`: Configuration and utilities (limiter, settings).
|
||||
- `app/api/deps.py`: Shared dependencies (authentication).
|
||||
- `app/api/router.py`: API versioning and route aggregation.
|
||||
- `app/api/endpoints/`:
|
||||
- `storyline.py`: Generic endpoint.
|
||||
- `gemini.py`: Dedicated Gemini endpoint.
|
||||
- `openai.py`: Dedicated OpenAI endpoint.
|
||||
|
||||
## Configuration
|
||||
Managed via `.env` file:
|
||||
- `API_KEY`: Secret key for Storyline modules.
|
||||
- `GOOGLE_API_KEY`: API key for Google Generative AI.
|
||||
- `OPENAI_API_KEY`: API key for OpenAI.
|
||||
- `PORT`: Server port (default 8000).
|
||||
|
||||
## API Endpoints
|
||||
All endpoints are versioned under `/api/v1`.
|
||||
|
||||
### 1. Gemini Chat
|
||||
- **URL**: `/api/v1/gemini/chat`
|
||||
- **Method**: POST
|
||||
- **Headers**: `X-API-Key: <your_key>`
|
||||
- **Body**: `{"prompt": "string", "context": "string"}`
|
||||
|
||||
### 2. OpenAI Chat
|
||||
- **URL**: `/api/v1/openai/chat`
|
||||
- **Method**: POST
|
||||
- **Headers**: `X-API-Key: <your_key>`
|
||||
- **Body**: `{"prompt": "string", "context": "string"}`
|
||||
|
||||
## Rate Limiting
|
||||
- Applied globally/per endpoint: **20 calls per minute**.
|
||||
|
||||
## Future Steps
|
||||
- Add logging (WandB or file-based).
|
||||
- Implement response caching.
|
||||
- Add more LLM providers (Anthropic, etc.).
|
||||
@@ -1,30 +0,0 @@
|
||||
from sqlalchemy import create_engine, text
|
||||
from app.core.config import settings
|
||||
|
||||
def update_schema():
|
||||
engine = create_engine(settings.DATABASE_URL)
|
||||
with engine.connect() as conn:
|
||||
print("Adding token tracking columns to modules table...")
|
||||
try:
|
||||
conn.execute(text("ALTER TABLE modules ADD COLUMN ingress_tokens INTEGER DEFAULT 0"))
|
||||
print("Added ingress_tokens column.")
|
||||
except Exception as e:
|
||||
print(f"ingress_tokens column might already exist: {e}")
|
||||
|
||||
try:
|
||||
conn.execute(text("ALTER TABLE modules ADD COLUMN egress_tokens INTEGER DEFAULT 0"))
|
||||
print("Added egress_tokens column.")
|
||||
except Exception as e:
|
||||
print(f"egress_tokens column might already exist: {e}")
|
||||
|
||||
try:
|
||||
conn.execute(text("ALTER TABLE modules ADD COLUMN total_tokens INTEGER DEFAULT 0"))
|
||||
print("Added total_tokens column.")
|
||||
except Exception as e:
|
||||
print(f"total_tokens column might already exist: {e}")
|
||||
|
||||
conn.commit()
|
||||
print("Schema update complete.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_schema()
|
||||
Reference in New Issue
Block a user