pablocst commited on
Commit
26c1ca2
1 Parent(s): f598adb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -45,8 +45,10 @@ def process_response(response, history):
45
  partial_words = ""
46
  for chunk in response.iter_lines():
47
  if chunk:
 
 
48
  try:
49
- chunk_json = json.loads(chunk.decode('utf-8'))
50
  print("Chunk JSON:", chunk_json) # Log para diagn贸stico
51
  if 'choices' in chunk_json and len(chunk_json['choices']) > 0:
52
  chunk_data = chunk_json['choices'][0].get('delta', {})
@@ -59,12 +61,12 @@ def process_response(response, history):
59
  token_counter += 1
60
  except json.JSONDecodeError as e:
61
  print("Error decoding JSON response:", e)
62
- print("Raw chunk:", chunk) # Log do chunk bruto para diagn贸stico
63
- break # ou trate o erro como achar melhor
64
  chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
65
  return chat, history, token_counter
66
 
67
 
 
68
  def setup_ui():
69
  with gr.Blocks() as demo:
70
  with gr.Column():
 
45
  partial_words = ""
46
  for chunk in response.iter_lines():
47
  if chunk:
48
+ # Removendo 'data:' do in铆cio do chunk
49
+ chunk_str = chunk.decode('utf-8').lstrip('data: ')
50
  try:
51
+ chunk_json = json.loads(chunk_str)
52
  print("Chunk JSON:", chunk_json) # Log para diagn贸stico
53
  if 'choices' in chunk_json and len(chunk_json['choices']) > 0:
54
  chunk_data = chunk_json['choices'][0].get('delta', {})
 
61
  token_counter += 1
62
  except json.JSONDecodeError as e:
63
  print("Error decoding JSON response:", e)
64
+ print("Raw chunk:", chunk_str) # Log do chunk bruto para diagn贸stico
 
65
  chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
66
  return chat, history, token_counter
67
 
68
 
69
+
70
  def setup_ui():
71
  with gr.Blocks() as demo:
72
  with gr.Column():