artintel235 commited on
Commit
a8c126e
·
verified ·
1 Parent(s): c5802f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -44,20 +44,34 @@ async def generate_command(
44
  genai.configure(api_key=GEMINI_API_KEY)
45
  model = genai.GenerativeModel("gemini-2.0-flash-exp")
46
  response = model.generate_content(prompt, stream=True)
 
47
  current_message_content = ""
 
48
  for part in response:
49
  text_chunk = part.text
50
 
51
  if len(current_message_content) + len(text_chunk) <= 2000:
52
  current_message_content += text_chunk
 
 
 
 
53
  else:
54
  # Send the current message
55
- await interaction.followup.send(content=current_message_content)
 
 
 
56
  current_message_content = text_chunk # Start new message with the current chunk
 
 
57
 
58
  # Send any remaining content
59
  if current_message_content:
60
- await interaction.followup.send(content=current_message_content)
 
 
 
61
  except Exception as e:
62
  print(e)
63
 
 
44
  genai.configure(api_key=GEMINI_API_KEY)
45
  model = genai.GenerativeModel("gemini-2.0-flash-exp")
46
  response = model.generate_content(prompt, stream=True)
47
+ current_message = None # Initialize outside the loop to keep track of current message
48
  current_message_content = ""
49
+
50
  for part in response:
51
  text_chunk = part.text
52
 
53
  if len(current_message_content) + len(text_chunk) <= 2000:
54
  current_message_content += text_chunk
55
+ if current_message:
56
+ await current_message.edit(content=current_message_content)
57
+ else:
58
+ current_message = await interaction.followup.send(content=current_message_content)
59
  else:
60
  # Send the current message
61
+ if current_message:
62
+ await current_message.edit(content=current_message_content)
63
+ else:
64
+ await interaction.followup.send(content=current_message_content)
65
  current_message_content = text_chunk # Start new message with the current chunk
66
+ current_message = await interaction.followup.send(content=current_message_content)
67
+
68
 
69
  # Send any remaining content
70
  if current_message_content:
71
+ if current_message:
72
+ await current_message.edit(content=current_message_content)
73
+ else:
74
+ await interaction.followup.send(content=current_message_content)
75
  except Exception as e:
76
  print(e)
77