Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import time
|
2 |
from fastapi import FastAPI, Request, HTTPException
|
3 |
from pydantic import BaseModel
|
4 |
-
from
|
5 |
import uvicorn
|
6 |
|
7 |
app = FastAPI()
|
8 |
-
|
9 |
API_PREFIX = "/"
|
10 |
|
11 |
# Middleware for logging request time
|
@@ -48,89 +48,18 @@ async def chat_completions(request: ChatCompletionRequest):
|
|
48 |
try:
|
49 |
# Only using DuckAI directly
|
50 |
content = " ".join([msg.get("content", "") for msg in request.messages])
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
56 |
return response
|
57 |
|
58 |
except Exception as e:
|
59 |
raise HTTPException(status_code=500, detail=str(e))
|
60 |
|
61 |
-
def create_complete_response(text: str, model: str) -> dict:
|
62 |
-
"""Create a complete non-streaming response"""
|
63 |
-
return {
|
64 |
-
"id": "chatcmpl-123",
|
65 |
-
"object": "chat.completion",
|
66 |
-
"created": int(time.time()),
|
67 |
-
"model": model,
|
68 |
-
"usage": {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0},
|
69 |
-
"choices": [
|
70 |
-
{
|
71 |
-
"message": {"content": text, "role": "assistant"},
|
72 |
-
"index": 0,
|
73 |
-
"finish_reason": "stop",
|
74 |
-
},
|
75 |
-
],
|
76 |
-
}
|
77 |
-
|
78 |
-
@app.get("/in/10th")
|
79 |
-
async def get_tenth_class_data():
|
80 |
-
return {
|
81 |
-
"class": "10",
|
82 |
-
"subjects": [
|
83 |
-
{
|
84 |
-
"name": "English",
|
85 |
-
"chapters": [
|
86 |
-
{"id": "eng-1", "name": "Prose: A Letter to God", "level": "easy"},
|
87 |
-
{"id": "eng-2", "name": "Poem: Dust of Snow", "level": "medium"},
|
88 |
-
{"id": "eng-3", "name": "Prose: Nelson Mandela", "level": "hard"},
|
89 |
-
{"id": "eng-4", "name": "Poem: Fire and Ice", "level": "medium"},
|
90 |
-
{"id": "eng-5", "name": "Prose: From the Diary of Anne Frank", "level": "easy"}
|
91 |
-
]
|
92 |
-
},
|
93 |
-
{
|
94 |
-
"name": "Math",
|
95 |
-
"chapters": [
|
96 |
-
{"id": "math-1", "name": "Real Numbers", "level": "medium"},
|
97 |
-
{"id": "math-2", "name": "Polynomials", "level": "medium"},
|
98 |
-
{"id": "math-3", "name": "Pair of Linear Equations in Two Variables", "level": "hard"},
|
99 |
-
{"id": "math-4", "name": "Quadratic Equations", "level": "hard"},
|
100 |
-
{"id": "math-5", "name": "Arithmetic Progressions", "level": "easy"}
|
101 |
-
]
|
102 |
-
},
|
103 |
-
{
|
104 |
-
"name": "Science",
|
105 |
-
"chapters": [
|
106 |
-
{"id": "sci-1", "name": "Chemical Reactions and Equations", "level": "easy"},
|
107 |
-
{"id": "sci-2", "name": "Acids, Bases and Salts", "level": "medium"},
|
108 |
-
{"id": "sci-3", "name": "Metals and Non-Metals", "level": "medium"},
|
109 |
-
{"id": "sci-4", "name": "Life Processes", "level": "hard"},
|
110 |
-
{"id": "sci-5", "name": "Electricity", "level": "medium"}
|
111 |
-
]
|
112 |
-
},
|
113 |
-
{
|
114 |
-
"name": "History",
|
115 |
-
"chapters": [
|
116 |
-
{"id": "hist-1", "name": "The Rise of Nationalism in Europe", "level": "hard"},
|
117 |
-
{"id": "hist-2", "name": "Nationalism in India", "level": "medium"},
|
118 |
-
{"id": "hist-3", "name": "The Making of a Global World", "level": "medium"},
|
119 |
-
{"id": "hist-4", "name": "The Age of Industrialization", "level": "hard"},
|
120 |
-
{"id": "hist-5", "name": "Print Culture and the Modern World", "level": "easy"}
|
121 |
-
]
|
122 |
-
},
|
123 |
-
{
|
124 |
-
"name": "Hindi",
|
125 |
-
"chapters": [
|
126 |
-
{"id": "hin-1", "name": "पाठ: पद", "level": "easy"},
|
127 |
-
{"id": "hin-2", "name": "पाठ: सूरदास", "level": "medium"},
|
128 |
-
{"id": "hin-3", "name": "पाठ: तुलसीदास", "level": "hard"},
|
129 |
-
{"id": "hin-4", "name": "पाठ: साखी", "level": "medium"},
|
130 |
-
{"id": "hin-5", "name": "पाठ: आत्मकथ्य", "level": "easy"}
|
131 |
-
]
|
132 |
-
}
|
133 |
-
]
|
134 |
-
}
|
135 |
if __name__ == "__main__":
|
136 |
-
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
|
|
1 |
import time
|
2 |
from fastapi import FastAPI, Request, HTTPException
|
3 |
from pydantic import BaseModel
|
4 |
+
from g4f.client import Client
|
5 |
import uvicorn
|
6 |
|
7 |
app = FastAPI()
|
8 |
+
|
9 |
API_PREFIX = "/"
|
10 |
|
11 |
# Middleware for logging request time
|
|
|
48 |
try:
|
49 |
# Only using DuckAI directly
|
50 |
content = " ".join([msg.get("content", "") for msg in request.messages])
|
51 |
+
|
52 |
+
client = Client()
|
53 |
+
response = client.chat.completions.create(
|
54 |
+
model=request.model,
|
55 |
+
messages=[{"role": "user", "content": content}],
|
56 |
+
web_search=False
|
57 |
+
)
|
58 |
+
|
59 |
return response
|
60 |
|
61 |
except Exception as e:
|
62 |
raise HTTPException(status_code=500, detail=str(e))
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
if __name__ == "__main__":
|
65 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|