Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import hf_hub_download
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
MODEL_PATH = hf_hub_download(
|
| 8 |
+
repo_id="bartowski/Qwen2.5-Coder-3B-Instruct-abliterated-GGUF",
|
| 9 |
+
filename="Qwen2.5-Coder-3B-Instruct-abliterated-Q4_K_M.gguf"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
llm = Llama(model_path=MODEL_PATH, n_ctx=2048, n_threads=2, chat_format="chatml")
|
| 13 |
+
|
| 14 |
+
app = FastAPI()
|
| 15 |
+
|
| 16 |
+
class ChatRequest(BaseModel):
|
| 17 |
+
model: str = "local"
|
| 18 |
+
messages: list
|
| 19 |
+
temperature: float = 0.7
|
| 20 |
+
max_tokens: int = 1024
|
| 21 |
+
|
| 22 |
+
@app.get("/health")
|
| 23 |
+
def health():
|
| 24 |
+
return {"status": "ok"}
|
| 25 |
+
|
| 26 |
+
@app.post("/v1/chat/completions")
|
| 27 |
+
def chat(req: ChatRequest):
|
| 28 |
+
out = llm.create_chat_completion(
|
| 29 |
+
messages=req.messages,
|
| 30 |
+
temperature=req.temperature,
|
| 31 |
+
max_tokens=req.max_tokens
|
| 32 |
+
)
|
| 33 |
+
return out
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|