lvwerra HF staff commited on
Commit
20875a0
·
verified ·
1 Parent(s): 2315b1e

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +6 -3
utils.py CHANGED
@@ -14,6 +14,9 @@ with open("llama3_template.jinja", "r") as f:
14
  llama_template = f.read()
15
 
16
 
 
 
 
17
  def parse_exec_result_nb(execution):
18
  """Convert an E2B Execution object to Jupyter notebook cell output format"""
19
  outputs = []
@@ -217,11 +220,12 @@ def update_notebook_display(notebook_data):
217
  return notebook_body
218
 
219
  def run_interactive_notebook(client, model, tokenizer, messages, sbx, max_new_tokens=512):
220
- print("Start!")
221
  notebook_data, code_cell_counter = create_base_notebook(messages)
 
222
  try:
223
  #code_cell_counter = 0
224
- while True:
 
225
  input_tokens = tokenizer.apply_chat_template(
226
  messages,
227
  chat_template=llama_template,
@@ -286,7 +290,6 @@ def run_interactive_notebook(client, model, tokenizer, messages, sbx, max_new_to
286
  yield update_notebook_display(notebook_data), messages
287
 
288
 
289
- print(f"last_tokens: {'|'.join(tokens[-10:])}, n_msg: {len(messages)}")
290
  # Handle code execution
291
  if code_cell:
292
  notebook_data["cells"][-1]["execution_count"] = code_cell_counter
 
14
  llama_template = f.read()
15
 
16
 
17
+ MAX_TURNS = 4
18
+
19
+
20
  def parse_exec_result_nb(execution):
21
  """Convert an E2B Execution object to Jupyter notebook cell output format"""
22
  outputs = []
 
220
  return notebook_body
221
 
222
  def run_interactive_notebook(client, model, tokenizer, messages, sbx, max_new_tokens=512):
 
223
  notebook_data, code_cell_counter = create_base_notebook(messages)
224
+ turns = 0
225
  try:
226
  #code_cell_counter = 0
227
+ while turns <= MAX_TURNS:
228
+ turns += 1
229
  input_tokens = tokenizer.apply_chat_template(
230
  messages,
231
  chat_template=llama_template,
 
290
  yield update_notebook_display(notebook_data), messages
291
 
292
 
 
293
  # Handle code execution
294
  if code_cell:
295
  notebook_data["cells"][-1]["execution_count"] = code_cell_counter