mateoluksenberg commited on
Commit
0cd233e
·
verified ·
1 Parent(s): 09f0255

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -273,9 +273,15 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
273
 
274
  thread.join()
275
 
 
 
 
 
 
 
276
  try:
277
  json_content = json.loads(buffer)
278
- formatted_text = "\n".join(f"{key}: {value}" for key, value in json_content.items())
279
  except json.JSONDecodeError:
280
  formatted_text = buffer
281
 
@@ -286,6 +292,19 @@ def simple_chat(message, temperature: float = 0.8, max_length: int = 4096, top_p
286
 
287
  return PlainTextResponse(formatted_text)
288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  @app.post("/chat/")
291
  async def test_endpoint(
 
273
 
274
  thread.join()
275
 
276
+ # try:
277
+ # json_content = json.loads(buffer)
278
+ # formatted_text = "\n".join(f"{key}: {value}" for key, value in json_content.items())
279
+ # except json.JSONDecodeError:
280
+ # formatted_text = buffer
281
+
282
  try:
283
  json_content = json.loads(buffer)
284
+ formatted_text = format_json_to_text(json_content)
285
  except json.JSONDecodeError:
286
  formatted_text = buffer
287
 
 
292
 
293
  return PlainTextResponse(formatted_text)
294
 
295
+ def format_json_to_text(json_content):
296
+ """
297
+ Formatea un diccionario JSON a texto plano sin comillas alrededor de los valores.
298
+ """
299
+ formatted_lines = []
300
+ for key, value in json_content.items():
301
+ # Si el valor es numérico, elimina las comillas
302
+ if isinstance(value, str) and (',' in value or '.' in value):
303
+ formatted_lines.append(f"{key}: {value}")
304
+ else:
305
+ formatted_lines.append(f"{key}: {value}")
306
+ return "\n".join(formatted_lines)
307
+
308
 
309
  @app.post("/chat/")
310
  async def test_endpoint(