Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
from anthropic import Anthropic
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
# --- CUSTOM ENDPOINTS ---
|
| 10 |
+
# These will be pulled from your Hugging Face "Secrets"
|
| 11 |
+
openai_client = OpenAI(
|
| 12 |
+
api_key=os.getenv("OPENAI_API_KEY"),
|
| 13 |
+
base_url=os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
anthropic_client = Anthropic(
|
| 17 |
+
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
| 18 |
+
base_url=os.getenv("ANTHROPIC_BASE_URL", "https://api.anthropic.com")
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
@app.post("/api/chat")
|
| 22 |
+
async def chat(payload: dict):
|
| 23 |
+
# This is where the GenUI magic happens.
|
| 24 |
+
# Your LLM call logic goes here.
|
| 25 |
+
return {"message": "OpenUI Logic Running"}
|
| 26 |
+
|
| 27 |
+
# Serve the pre-built React UI
|
| 28 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|