@@ -100,7 +100,7 @@ def co_v2(
100100 history += f' bot say "{ event ["script" ]} "\n '
101101
102102 elif event ["type" ] == "StartTool" :
103- s = f' await { event [" flow_name" ] } '
103+ s = f" await { event [' flow_name' ] } "
104104 for k , v in event .items ():
105105 if k in [
106106 "type" ,
@@ -385,89 +385,15 @@ def indent(text: str, n_spaces: int) -> str:
385385 return textwrap .indent (text , " " * n_spaces )
386386
387387
388- def user_assistant_sequence_nemollm (events : List [dict ]) -> str :
389- """Filter that turns an array of events into a sequence of user/assistant messages.
390-
391- The output will look like:
392- ```
393- <extra_id_1>User
394- hi
395- <extra_id_1>Assistant
396- Hello there!
397- <extra_id_1>User
398- What can you do?
399- <extra_id_1>Assistant
400- I can help with many things.
401- ```
402- """
403- history_items = []
404- for event in events :
405- if event ["type" ] == "UserMessage" :
406- # Convert text to string regardless of type (handles both text and multimodal)
407- history_items .append ("<extra_id_1>User\n " + str (event ["text" ]))
408- elif event ["type" ] == "StartUtteranceBotAction" :
409- history_items .append ("<extra_id_1>Assistant\n " + event ["script" ])
410-
411- return "\n " .join (history_items )
412-
413-
414388def _previous_line (lines : List [str ], i : int ):
415389 """Returns the previous lines, skipping comments."""
390+
416391 i = i - 1
417392 while i > 0 and lines [i ].strip ().startswith ("#" ):
418393 i -= 1
419394 return lines [i ]
420395
421396
422- def to_messages_nemollm (colang_history : str ) -> str :
423- """Filter that given a history in colang format, returns a messages string
424- in the chat format used by NeMo LLM models."""
425- messages = []
426-
427- # For now, we use a simple heuristic. The line `user "xxx"` gets translated to
428- # a message from the user, and the rest gets translated to messages from the assistant.
429- lines = colang_history .split ("\n " )
430-
431- bot_lines = []
432- for i , line in enumerate (lines ):
433- if line .startswith ('user "' ):
434- # If we have bot lines in the buffer, we first add a bot message.
435- if bot_lines :
436- messages .append ({"type" : "assistant" , "content" : "\n " .join (bot_lines )})
437- bot_lines = []
438-
439- messages .append ({"type" : "user" , "content" : line [6 :- 1 ]})
440-
441- elif line .strip () == "" :
442- # On empty lines, we also reset the bot buffer.
443- if bot_lines :
444- messages .append ({"type" : "assistant" , "content" : "\n " .join (bot_lines )})
445- bot_lines = []
446- else :
447- if i > 0 and _previous_line (lines , i ).startswith ('user "' ):
448- if not line .strip ().startswith ("#" ):
449- line = "User intent: " + line .strip ()
450- elif line .startswith ("user " ):
451- line = "User intent: " + line [5 :].strip ()
452- elif line .startswith ("bot " ):
453- line = "Bot intent: " + line [4 :].strip ()
454- elif line .startswith (' "' ):
455- line = "Bot message: " + line [2 :].strip ()
456- bot_lines .append (line )
457-
458- # Check if there is a last message from the bot.
459- if bot_lines :
460- messages .append ({"type" : "bot" , "content" : "\n " .join (bot_lines )})
461-
462- messages_string = ""
463- for m in messages :
464- if m ["type" ] == "assistant" or m ["type" ] == "bot" :
465- messages_string += "<extra_id_1>Assistant\n " + m ["content" ] + "\n "
466- elif m ["type" ] == "user" :
467- messages_string += "<extra_id_1>User\n " + m ["content" ] + "\n "
468- return messages_string
469-
470-
471397def remove_trailing_new_line (s : str ):
472398 if s .endswith ("\n " ):
473399 s = s [:- 1 ]
0 commit comments