Update app.py
Browse files
app.py
CHANGED
|
@@ -27,20 +27,16 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 27 |
)
|
| 28 |
|
| 29 |
@app.post("/generate")
|
| 30 |
-
async def generate_text(
|
| 31 |
"""Gera um texto com base na entrada fornecida."""
|
| 32 |
-
|
| 33 |
-
data = await request.json()
|
| 34 |
-
user_message = data.get("message")
|
| 35 |
-
token = data.get('token','null')
|
| 36 |
|
| 37 |
-
if not
|
| 38 |
raise HTTPException(status_code=400, detail="O campo 'message' 茅 obrigat贸rio.")
|
| 39 |
|
| 40 |
if token != EXPECTED_TOKEN:
|
| 41 |
raise HTTPException(status_code=401, detail="Token inv谩lido")
|
| 42 |
|
| 43 |
-
messages = [{'role': 'user', 'content':
|
| 44 |
|
| 45 |
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(device)
|
| 46 |
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
@app.post("/generate")
|
| 30 |
+
async def generate_text(message: str, token: str):
|
| 31 |
"""Gera um texto com base na entrada fornecida."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
if not message:
|
| 34 |
raise HTTPException(status_code=400, detail="O campo 'message' 茅 obrigat贸rio.")
|
| 35 |
|
| 36 |
if token != EXPECTED_TOKEN:
|
| 37 |
raise HTTPException(status_code=401, detail="Token inv谩lido")
|
| 38 |
|
| 39 |
+
messages = [{'role': 'user', 'content': message}]
|
| 40 |
|
| 41 |
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(device)
|
| 42 |
|