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

arreglando error 422 creo

Browse files
Files changed (2) hide show
  1. app.py +3 -3
  2. templates/chat.html +12 -11
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, Request, Form
2
  from fastapi.responses import HTMLResponse, JSONResponse
3
  from fastapi.templating import Jinja2Templates
4
  from fastapi.staticfiles import StaticFiles
@@ -55,7 +55,7 @@ model = AutoModelForCausalLM.from_pretrained(
55
  )
56
 
57
  @app.post("/personajes/{personaje}/chat", response_class=HTMLResponse)
58
- async def chat_with_character(request: Request, personaje: str, user_input: str):
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 +83,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}
 
1
+ from fastapi import FastAPI, Request, Form , Body
2
  from fastapi.responses import HTMLResponse, JSONResponse
3
  from fastapi.templating import Jinja2Templates
4
  from fastapi.staticfiles import StaticFiles
 
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
  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}
templates/chat.html CHANGED
@@ -123,17 +123,18 @@ body {
123
  <button type="submit">Send</button>
124
  </form>
125
  <script>
126
- document.getElementById("chat-form").addEventListener("submit", async function(e) {
127
- e.preventDefault();
128
- const userInput = document.getElementById("user-input").value;
129
- const response = await fetch(`/personajes/{{ character_name }}/chat`, {
130
- method: "POST",
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
  </script>
138
 
139
  </body>
 
123
  <button type="submit">Send</button>
124
  </form>
125
  <script>
126
+ document.getElementById("chat-form").addEventListener("submit", async function(e) {
127
+ e.preventDefault();
128
+ const userInput = document.getElementById("user-input").value;
129
+ const response = await fetch(`/personajes/{{ character_name }}/chat`, {
130
+ method: "POST",
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>