Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,22 @@
|
|
| 1 |
-
from
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
api_key=os.environ["HF_TOKEN"])
|
| 8 |
MODEL = "Qwen/Qwen3-Next-80B-A3B-Instruct"
|
| 9 |
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
user = request.json["message"]
|
| 15 |
-
history.append({"role": "user", "content": user})
|
| 16 |
-
rsp = client.chat.completions.create(model=MODEL, messages=history)
|
| 17 |
-
bot = rsp.choices[0].message.content
|
| 18 |
-
history.append({"role": "assistant", "content": bot})
|
| 19 |
-
return jsonify({"reply": bot})
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import os, openai
|
| 4 |
|
| 5 |
+
client = openai.OpenAI(base_url="https://router.huggingface.co/v1",
|
| 6 |
+
api_key=os.environ["HF_TOKEN"])
|
|
|
|
| 7 |
MODEL = "Qwen/Qwen3-Next-80B-A3B-Instruct"
|
| 8 |
|
| 9 |
+
app = FastAPI()
|
| 10 |
+
hist = []
|
| 11 |
|
| 12 |
+
class M(BaseModel):
|
| 13 |
+
msg: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
@app.post("/chat")
|
| 16 |
+
def chat(m: M):
|
| 17 |
+
hist.append({"role": "user", "content": m.msg})
|
| 18 |
+
r = client.chat.completions.create(model=MODEL, messages=hist)
|
| 19 |
+
bot = r.choices[0].message.content
|
| 20 |
+
hist.append({"role": "assistant", "content": bot})
|
| 21 |
+
return {"reply": bot}
|
| 22 |
|