Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
107 lines (98 loc) · 3 KB
/
Copy pathmain.py
File metadata and controls
107 lines (98 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Minimal FastAPI app for testing authentication
"""
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
app = FastAPI()
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5100", "http://127.0.0.1:5100"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class LoginRequest(BaseModel):
email: str
password: str
class User(BaseModel):
id: int
email: str
full_name: str
is_active: bool
created_at: str
class LoginResponse(BaseModel):
access_token: str
token_type: str
user: User
@app.get("/")
def root():
return {"message": "CenAI API is running"}
@app.get("/health")
def health():
return {"status": "healthy"}
@app.post("/api/v1/auth/login", response_model=LoginResponse)
def login(credentials: LoginRequest):
"""Login endpoint"""
if credentials.email == "admin@cenai.com" and credentials.password == "admin123":
return LoginResponse(
access_token="mock_token_admin_123456789",
token_type="bearer",
user=User(
id=1,
email="admin@cenai.com",
full_name="CenAI Admin",
is_active=True,
created_at="2025-10-04T00:00:00"
)
)
elif credentials.email == "user@cenai.com" and credentials.password == "user123":
return LoginResponse(
access_token="mock_token_user_123456789",
token_type="bearer",
user=User(
id=2,
email="user@cenai.com",
full_name="CenAI User",
is_active=True,
created_at="2025-10-04T00:00:00"
)
)
else:
raise HTTPException(status_code=401, detail="Invalid credentials")
@app.get("/api/v1/galaxies")
def get_galaxies():
"""Get all galaxies"""
return [
{
"id": 1,
"name": "ChatGPT Galaxy",
"description": "OpenAI GPT models for general conversations",
"icon": "🤖",
"color": "#10a37f",
"system_prompt": "You are a helpful AI assistant.",
"is_active": True,
"created_at": "2025-09-30T00:00:00"
},
{
"id": 2,
"name": "Claude Galaxy",
"description": "Anthropic Claude models for thoughtful responses",
"icon": "🎭",
"color": "#d4a574",
"system_prompt": "You are Claude, an AI assistant created by Anthropic.",
"is_active": True,
"created_at": "2025-09-30T00:00:00"
},
{
"id": 3,
"name": "Local AI Galaxy",
"description": "Local AI models via Ollama",
"icon": "🏠",
"color": "#6366f1",
"system_prompt": "You are a helpful local AI assistant.",
"is_active": True,
"created_at": "2025-09-30T00:00:00"
}
]