Yhhxhfh commited on
Commit
9eb4861
1 Parent(s): 9415ca2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -105,7 +105,8 @@ async def index():
105
  const userInput = document.getElementById('user-input');
106
 
107
  userInput.addEventListener('keyup', function(event) {
108
- if (event.keyCode === 13) {
 
109
  event.preventDefault();
110
  sendMessage();
111
  }
@@ -121,8 +122,16 @@ async def index():
121
  fetch(`/autocomplete?q=${encodeURIComponent(userMessage)}`)
122
  .then(response => response.json())
123
  .then(data => {
124
- const botMessages = data.result;
125
- appendMessage('bot', botMessages);
 
 
 
 
 
 
 
 
126
  })
127
  .catch(error => {
128
  console.error('Error:', error);
@@ -159,6 +168,11 @@ async def autocomplete(q: str = Query(..., title='query'), background_tasks: Bac
159
  background_tasks.add_task(generate_responses, q)
160
  return {"status": "Processing request, please wait..."}
161
 
 
 
 
 
 
162
  def generate_responses(q):
163
  generated_responses = []
164
  try:
 
105
  const userInput = document.getElementById('user-input');
106
 
107
  userInput.addEventListener('keyup', function(event) {
108
+ // Corrección: usar event.key en lugar de event.keyCode
109
+ if (event.key === 'Enter') {
110
  event.preventDefault();
111
  sendMessage();
112
  }
 
122
  fetch(`/autocomplete?q=${encodeURIComponent(userMessage)}`)
123
  .then(response => response.json())
124
  .then(data => {
125
+ // Esperar a que la respuesta esté lista en Redis
126
+ fetch(`/get_response?q=${encodeURIComponent(userMessage)}`)
127
+ .then(response => response.json())
128
+ .then(data => {
129
+ const botMessage = data.response;
130
+ appendMessage('bot', botMessage);
131
+ })
132
+ .catch(error => {
133
+ console.error('Error:', error);
134
+ });
135
  })
136
  .catch(error => {
137
  console.error('Error:', error);
 
168
  background_tasks.add_task(generate_responses, q)
169
  return {"status": "Processing request, please wait..."}
170
 
171
+ @app.get('/get_response')
172
+ async def get_response(q: str = Query(..., title='query')):
173
+ response = redis_client.hget("responses", q)
174
+ return {"response": response}
175
+
176
  def generate_responses(q):
177
  generated_responses = []
178
  try: