Update app.py
Browse files5 unmodified lines67891011121314151617181920212223242526272829305 unmodified linespipe = pipeline("text-generation",model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")class Req(BaseModel):message: str@app.post("/chat")def chat(req: Req):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 outputreply = text.split("[/INST]")[-1].strip()return {"reply": reply}5 unmodified lines6789101112131415161718192021222324252627282930313233343536373839404142434445465 unmodified linespipe = pipeline("text-generation",model="microsoft/phi-3-mini-4k-instruct",device_map="auto")class Req(BaseModel):message: strdef build_prompt(user_msg: str) -> str:return ("<|system|>\n""You are a helpful, clear, and concise assistant. ""Give accurate and well-structured answers. Avoid unnecessary fluff.""<|end|>\n""<|user|>\n"f"{user_msg}""<|end|>\n""<|assistant|>\n")@app.post("/chat")def chat(req: Req):prompt = build_prompt(req.message)out = pipe(prompt,max_new_tokens=200,temperature=0.6,top_p=0.9,do_sample=True,repetition_penalty=1.1,eos_token_id=pipe.tokenizer.eos_token_id)text = out[0]["generated_text"]reply = text.split("<|assistant|>")[-1].strip()return {"reply": reply}
app.py+22-6