zelk12 commited on
Commit
2b70838
·
verified ·
1 Parent(s): e8d2b37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -55,18 +55,29 @@ def stream_gemini_response(user_message: str, messages: list) -> Iterator[list]:
55
  thinking_complete = False
56
 
57
  # Add initial thinking message
 
 
 
 
 
 
 
 
 
 
 
58
  messages.append(
59
  ChatMessage(
60
  role="assistant",
61
- content="",
62
- metadata={"title": "⚙️ Thinking: *The thoughts produced by the model are experimental"}
63
  )
64
  )
 
 
65
 
66
  for chunk in response:
67
  parts = chunk.candidates[0].content.parts
68
  current_chunk = parts[0].text
69
- # thinking_complete = True
70
 
71
  if len(parts) == 2 and not thinking_complete:
72
  # Complete thought and start response
@@ -105,7 +116,7 @@ def stream_gemini_response(user_message: str, messages: list) -> Iterator[list]:
105
  else:
106
  # Stream thinking
107
  thought_buffer += current_chunk
108
- print(f"\n=== Thinking Chunk ===\n{current_chunk}" + f" = {len(parts)} : {thinking_complete} =")
109
 
110
  messages[-1] = ChatMessage(
111
  role="assistant",
 
55
  thinking_complete = False
56
 
57
  # Add initial thinking message
58
+ #messages.append(
59
+ # ChatMessage(
60
+ # role="assistant",
61
+ # content="",
62
+ # metadata={"title": "⚙️ Thinking: *The thoughts produced by the model are experimental"}
63
+ # )
64
+ #)
65
+
66
+ response_buffer = parts[1].text
67
+ print(f"\n=== Starting Response ===\n{response_buffer}")
68
+
69
  messages.append(
70
  ChatMessage(
71
  role="assistant",
72
+ content=response_buffer
 
73
  )
74
  )
75
+
76
+ thinking_complete = True
77
 
78
  for chunk in response:
79
  parts = chunk.candidates[0].content.parts
80
  current_chunk = parts[0].text
 
81
 
82
  if len(parts) == 2 and not thinking_complete:
83
  # Complete thought and start response
 
116
  else:
117
  # Stream thinking
118
  thought_buffer += current_chunk
119
+ print(f"\n=== Thinking Chunk ===\n{current_chunk}")
120
 
121
  messages[-1] = ChatMessage(
122
  role="assistant",