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