jorgencio commited on
Commit
d8ba489
·
1 Parent(s): 73d70b7

arreglando error 422 creol

Browse files
Files changed (2) hide show
  1. app.py +6 -2
  2. templates/chat.html +2 -0
app.py CHANGED
@@ -54,8 +54,12 @@ model = AutoModelForCausalLM.from_pretrained(
54
  torch_dtype=torch.float16 # Usa FP16 para eficiencia en GPUs
55
  )
56
 
57
- @app.post("/personajes/{personaje}/chat", response_class=HTMLResponse)
58
  async def chat_with_character(request: Request, personaje: str, user_input: str = Body(...)):
 
 
 
 
59
  # Crear el prompt dinámico con el formato esperado
60
  prompt = f"""<|im_start|>system
61
  You are {personaje}, a sexy girl who has been dating the user for 2 months.<|im_end|>
@@ -83,4 +87,4 @@ You are {personaje}, a sexy girl who has been dating the user for 2 months.<|im_
83
  response_text = generated_response.split("<|im_start|>assistant")[1].strip().split("<|im_end|>")[0].strip()
84
 
85
  # Devolver la respuesta al usuario
86
- return {"response": response_text}
 
54
  torch_dtype=torch.float16 # Usa FP16 para eficiencia en GPUs
55
  )
56
 
57
+ @app.post("/personajes/{personaje}/chat")
58
  async def chat_with_character(request: Request, personaje: str, user_input: str = Body(...)):
59
+ # Verificar que el user_input no esté vacío
60
+ if not user_input:
61
+ return JSONResponse(status_code=422, content={"message": "user_input is required"})
62
+
63
  # Crear el prompt dinámico con el formato esperado
64
  prompt = f"""<|im_start|>system
65
  You are {personaje}, a sexy girl who has been dating the user for 2 months.<|im_end|>
 
87
  response_text = generated_response.split("<|im_start|>assistant")[1].strip().split("<|im_end|>")[0].strip()
88
 
89
  # Devolver la respuesta al usuario
90
+ return JSONResponse(content={"response": response_text})
templates/chat.html CHANGED
@@ -131,10 +131,12 @@ document.getElementById("chat-form").addEventListener("submit", async function(e
131
  headers: { "Content-Type": "application/json" },
132
  body: JSON.stringify({ user_input: userInput })
133
  });
 
134
  const data = await response.json();
135
  console.log(data.response);
136
  });
137
 
 
138
  </script>
139
 
140
  </body>
 
131
  headers: { "Content-Type": "application/json" },
132
  body: JSON.stringify({ user_input: userInput })
133
  });
134
+
135
  const data = await response.json();
136
  console.log(data.response);
137
  });
138
 
139
+
140
  </script>
141
 
142
  </body>