lattmamb commited on
Commit
f8ae41a
·
verified ·
1 Parent(s): 991569f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from fastapi import FastAPI, Request
3
+ from fastapi.responses import JSONResponse
4
+ import os
5
+ import requests
6
+
7
+ app = FastAPI()
8
+ LM_API_URL = os.getenv("LM_API_URL", "http://localhost:1234")
9
+
10
+ @app.post("/query")
11
+ async def query(request: Request):
12
+ prompt = (await request.json()).get("prompt", "")
13
+ try:
14
+ response = requests.post(f"{LM_API_URL}/v1/completions", json={
15
+ "model": "local-model",
16
+ "prompt": prompt,
17
+ "max_tokens": 200
18
+ })
19
+ result = response.json().get("choices", [{}])[0].get("text", "").strip()
20
+ return JSONResponse(content={"response": result})
21
+ except Exception as e:
22
+ return JSONResponse(content={"response": f"⚠️ Backend error: {str(e)}"})