Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -2,6 +2,7 @@ from fastapi import FastAPI, HTTPException
|
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from duckai import DuckAI
|
|
|
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
@@ -22,9 +23,15 @@ async def chat(query: str):
|
|
| 22 |
if not query:
|
| 23 |
raise HTTPException(status_code=400, detail="Query parameter is required")
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
try:
|
| 27 |
-
results =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return {"results": results}
|
| 29 |
except Exception as e1:
|
| 30 |
print(f"Primary model (gpt-4o-mini) failed: {e1}")
|
|
@@ -42,19 +49,11 @@ async def chat(query: str):
|
|
| 42 |
}
|
| 43 |
)
|
| 44 |
|
| 45 |
-
async def chat_with_model(query: str, model: str):
|
| 46 |
-
try:
|
| 47 |
-
duck = DuckAI()
|
| 48 |
-
results = duck.chat(query, model=model)
|
| 49 |
-
return {"results": results}
|
| 50 |
-
except Exception as e:
|
| 51 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 52 |
@app.get("/health")
|
| 53 |
@app.get("/")
|
| 54 |
async def health_check():
|
| 55 |
-
|
| 56 |
return {"status": "healthy"}
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
import uvicorn
|
| 60 |
-
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info", reload=True)
|
|
|
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from duckai import DuckAI
|
| 5 |
+
from g4f.client import Client
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 23 |
if not query:
|
| 24 |
raise HTTPException(status_code=400, detail="Query parameter is required")
|
| 25 |
|
| 26 |
+
client = Client()
|
| 27 |
+
duck = DuckAI() # Initialize DuckAI here
|
| 28 |
+
|
| 29 |
try:
|
| 30 |
+
results = client.chat.completions.create(
|
| 31 |
+
model="gpt-4o-mini",
|
| 32 |
+
messages=[{"role": "user", "content": query}],
|
| 33 |
+
web_search=False
|
| 34 |
+
)
|
| 35 |
return {"results": results}
|
| 36 |
except Exception as e1:
|
| 37 |
print(f"Primary model (gpt-4o-mini) failed: {e1}")
|
|
|
|
| 49 |
}
|
| 50 |
)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
@app.get("/health")
|
| 53 |
@app.get("/")
|
| 54 |
async def health_check():
|
|
|
|
| 55 |
return {"status": "healthy"}
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
import uvicorn
|
| 59 |
+
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info", reload=True)
|