Update app.py
Browse files12345678910111213141516111718192021222324252627282930from fastapi import FastAPIfrom pydantic import BaseModelfrom transformers import pipeline
app = FastAPI()
pipe = pipeline( "text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
class Req(BaseModel): message: str
@app.post("/chat")def chat(req: Req): return {"reply": f"AI says: {req.message}"} prompt = f"<s>[INST] {req.message} [/INST]"
out = pipe( prompt, max_new_tokens=100, temperature=0.7 )
text = out[0]["generated_text"]
# remove prompt from output reply = text.split("[/INST]")[-1].strip()
return {"reply": reply}app.py+20-1