Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from llama_cpp import Llama
|
| 4 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
@@ -116,23 +116,23 @@ def generate_chat_response(request, model_data):
|
|
| 116 |
try:
|
| 117 |
user_input = normalize_input(request.message)
|
| 118 |
response = model(user_input, top_k=request.top_k, top_p=request.top_p, temperature=request.temperature)
|
| 119 |
-
return
|
| 120 |
except Exception:
|
| 121 |
pass
|
| 122 |
|
|
|
|
| 123 |
@spaces.GPU(duration=0)
|
| 124 |
async def generate(request: ChatRequest):
|
| 125 |
try:
|
| 126 |
responses = []
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
pass
|
| 136 |
|
| 137 |
if not responses:
|
| 138 |
raise HTTPException(status_code=500, detail="Error: No responses generated.")
|
|
@@ -147,11 +147,12 @@ async def generate(request: ChatRequest):
|
|
| 147 |
pass
|
| 148 |
|
| 149 |
@app.api_route("/{method_name:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
| 150 |
-
async def handle_request(method_name: str):
|
| 151 |
try:
|
| 152 |
-
|
|
|
|
| 153 |
except Exception:
|
| 154 |
-
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
| 157 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from llama_cpp import Llama
|
| 4 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
|
| 116 |
try:
|
| 117 |
user_input = normalize_input(request.message)
|
| 118 |
response = model(user_input, top_k=request.top_k, top_p=request.top_p, temperature=request.temperature)
|
| 119 |
+
return response
|
| 120 |
except Exception:
|
| 121 |
pass
|
| 122 |
|
| 123 |
+
@app.post("/generate")
|
| 124 |
@spaces.GPU(duration=0)
|
| 125 |
async def generate(request: ChatRequest):
|
| 126 |
try:
|
| 127 |
responses = []
|
| 128 |
+
models = global_data['models']
|
| 129 |
+
for model_data in models:
|
| 130 |
+
response = generate_chat_response(request, model_data)
|
| 131 |
+
if response:
|
| 132 |
+
responses.append({
|
| 133 |
+
"model": model_data['name'],
|
| 134 |
+
"response": response
|
| 135 |
+
})
|
|
|
|
| 136 |
|
| 137 |
if not responses:
|
| 138 |
raise HTTPException(status_code=500, detail="Error: No responses generated.")
|
|
|
|
| 147 |
pass
|
| 148 |
|
| 149 |
@app.api_route("/{method_name:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
| 150 |
+
async def handle_request(method_name: str, request: Request):
|
| 151 |
try:
|
| 152 |
+
body = await request.json()
|
| 153 |
+
return {"message": "Request handled successfully", "body": body}
|
| 154 |
except Exception:
|
| 155 |
+
pass
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
| 158 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|