sguertl commited on
Commit
3f03ec9
·
verified ·
1 Parent(s): 4eda8f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import InferenceClient
2
+ from fastapi import FastAPI, Request
3
+ from pydantic import BaseModel
4
+ import uvicorn
5
+ import os
6
+
7
+ app = FastAPI()
8
+
9
+ MODEL = "mistralai/Mistral-7B-Instruct-v0.1"
10
+ HF_TOKEN = os.environ["HF_TOKEN"]
11
+
12
+ client = InferenceClient(model=MODEL, token=HF_TOKEN)
13
+
14
+ class Prompt(BaseModel):
15
+ message: str
16
+
17
+ @app.post("/chat")
18
+ async def chat(prompt: Prompt):
19
+ system_prompt = (
20
+ "You are a beginner programming student helping a peer. "
21
+ "Offer hints, ask questions, and support understanding—don’t give full solutions."
22
+ )
23
+ full_prompt = f"<s>[INST] <<SYS>>{system_prompt}<</SYS>>\n{prompt.message} [/INST]"
24
+
25
+ output = client.text_generation(
26
+ prompt=full_prompt,
27
+ max_new_tokens=200,
28
+ temperature=0.7,
29
+ top_p=0.95,
30
+ do_sample=True
31
+ )
32
+ return {"reply": output.strip()}