dev2089 commited on
Commit
facad14
·
verified ·
1 Parent(s): c8378d8

Upload main.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. main.py +115 -0
main.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Devrayog AI - Main API Server
3
+ FastAPI-based API for Devrayog AI models
4
+ """
5
+
6
+ from fastapi import FastAPI, HTTPException
7
+ from fastapi.middleware.cors import CORSMiddleware
8
+ from pydantic import BaseModel
9
+ from typing import Optional
10
+ import time
11
+ import os
12
+
13
+ app = FastAPI(
14
+ title="Devrayog AI API",
15
+ description="India's First Solo-Built AI - API Server",
16
+ version="0.1.0"
17
+ )
18
+
19
+ # CORS
20
+ app.add_middleware(
21
+ CORSMiddleware,
22
+ allow_origins=["*"],
23
+ allow_credentials=True,
24
+ allow_methods=["*"],
25
+ allow_headers=["*"],
26
+ )
27
+
28
+ # Request/Response models
29
+ class ChatRequest(BaseModel):
30
+ message: str
31
+ model: str = "devrayog-agni"
32
+ max_tokens: int = 512
33
+ temperature: float = 0.7
34
+ system_prompt: Optional[str] = None
35
+
36
+ class ChatResponse(BaseModel):
37
+ response: str
38
+ model: str
39
+ tokens_used: int
40
+ time_taken: float
41
+
42
+ class ModelInfo(BaseModel):
43
+ name: str
44
+ description: str
45
+ parameters: str
46
+ status: str
47
+
48
+ # Routes
49
+ @app.get("/")
50
+ async def root():
51
+ return {
52
+ "name": "Devrayog AI",
53
+ "version": "0.1.0",
54
+ "status": "running",
55
+ "message": "Welcome to Devrayog AI - India's First Solo-Built AI",
56
+ "endpoints": {
57
+ "chat": "/api/v1/chat",
58
+ "models": "/api/v1/models",
59
+ "health": "/health"
60
+ }
61
+ }
62
+
63
+ @app.get("/health")
64
+ async def health():
65
+ return {"status": "healthy", "timestamp": time.time()}
66
+
67
+ @app.get("/api/v1/models")
68
+ async def list_models():
69
+ return {
70
+ "models": [
71
+ {
72
+ "id": "devrayog-agni",
73
+ "name": "Devrayog Agni",
74
+ "description": "Fast and sharp - optimized for quick responses",
75
+ "parameters": "3.8B",
76
+ "status": "coming_soon"
77
+ },
78
+ {
79
+ "id": "devrayog-vayu",
80
+ "name": "Devrayog Vayu",
81
+ "description": "Creative and flowing - optimized for storytelling",
82
+ "parameters": "9B",
83
+ "status": "coming_soon"
84
+ },
85
+ {
86
+ "id": "devrayog-akash",
87
+ "name": "Devrayog Akash",
88
+ "description": "Most powerful - optimized for complex reasoning",
89
+ "parameters": "8B",
90
+ "status": "coming_soon"
91
+ }
92
+ ]
93
+ }
94
+
95
+ @app.post("/api/v1/chat", response_model=ChatResponse)
96
+ async def chat(request: ChatRequest):
97
+ start_time = time.time()
98
+
99
+ # For now, return a placeholder response
100
+ # Once models are deployed, this will call the actual model
101
+ response = f"[Devrayog AI - {request.model}] Thank you for your message: '{request.message}'. This is a placeholder response. The actual model will be deployed soon on Hugging Face."
102
+
103
+ time_taken = time.time() - start_time
104
+
105
+ return ChatResponse(
106
+ response=response,
107
+ model=request.model,
108
+ tokens_used=len(response.split()),
109
+ time_taken=round(time_taken, 3)
110
+ )
111
+
112
+ if __name__ == "__main__":
113
+ import uvicorn
114
+ port = int(os.environ.get("PORT", 8000))
115
+ uvicorn.run(app, host="0.0.0.0", port=port)