|
|
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} |
|
|
|