DerivedFunction1 commited on
Commit
f22b35d
·
1 Parent(s): 6a3abc5
Files changed (1) hide show
  1. bob_agents.py +8 -7
bob_agents.py CHANGED
@@ -204,16 +204,17 @@ def build_refusal_message(
204
 
205
  misdirection_topic_string = _generate_misdirection_topic_string(lang)
206
 
207
- # Yield the source first to mimic streaming
208
- yield source
209
-
210
  translated = _translate_refusal_with_gemma(source, lang)
211
 
212
- # Only append if translated content exists and is different from source
213
- if translated and translated.strip() != source.strip():
214
- yield f"\n{translated}"
 
 
215
 
216
- final_refusal_text = f"{source}\n{translated}\n\nPerhaps I can help you with {misdirection_topic_string}?" if translated and translated.strip() != source.strip() else f"{source}\n\nPerhaps I can help you with {misdirection_topic_string}?"
 
 
217
  cache = _refusal_cache_for_language(session_state, lang)
218
  if final_refusal_text not in cache:
219
  cache.append(final_refusal_text)
 
204
 
205
  misdirection_topic_string = _generate_misdirection_topic_string(lang)
206
 
 
 
 
207
  translated = _translate_refusal_with_gemma(source, lang)
208
 
209
+ # Determine the primary refusal message: use translated if different and valid, else use source.
210
+ primary_refusal = translated if translated and translated.strip() != source.strip() else source
211
+
212
+ # Construct the final message including misdirection
213
+ final_refusal_text = f"{primary_refusal}\n\nPerhaps I can help you with {misdirection_topic_string}?"
214
 
215
+ # Yield the complete refusal message
216
+ yield final_refusal_text
217
+
218
  cache = _refusal_cache_for_language(session_state, lang)
219
  if final_refusal_text not in cache:
220
  cache.append(final_refusal_text)