johann22 commited on
Commit
9355e8a
1 Parent(s): 5ff0b0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -21
app.py CHANGED
@@ -51,16 +51,15 @@ def run_gpt(
51
  stop_tokens,
52
  max_tokens,
53
  purpose,
54
- task,
55
- temperature=0.9, top_p=0.95, repetition_penalty=1.0,
56
  ):
57
  seed = random.randint(1,1111111111111111)
58
  print (seed)
59
  generate_kwargs = dict(
60
- temperature=temperature,
61
  max_new_tokens=1048,
62
- top_p=top_p,
63
- repetition_penalty=repetition_penalty,
64
  do_sample=True,
65
  seed=seed,
66
  )
@@ -88,19 +87,19 @@ def run_gpt(
88
  return resp
89
 
90
 
91
- def compress_history(purpose, task, history, directory,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
92
  resp = run_gpt(
93
  COMPRESS_HISTORY_PROMPT,
94
  stop_tokens=["observation:", "task:", "action:", "thought:"],
95
  max_tokens=512,
96
  purpose=purpose,
97
  task=task,
98
- history=history,temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty,
99
  )
100
  history = "observation: {}\n".format(resp)
101
  return history
102
 
103
- def call_search(purpose, task, history, directory, action_input,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
104
  print("CALLING SEARCH")
105
  try:
106
 
@@ -120,14 +119,14 @@ def call_search(purpose, task, history, directory, action_input,temperature=0.9,
120
  history += "observation: {}'\n".format(e)
121
  return "MAIN", None, history, task
122
 
123
- def call_main(purpose, task, history, directory, action_input,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
124
  resp = run_gpt(
125
  ACTION_PROMPT,
126
  stop_tokens=["observation:", "task:"],
127
  max_tokens=1048,
128
  purpose=purpose,
129
  task=task,
130
- history=history,temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty,
131
  )
132
  lines = resp.strip().strip("\n").split("\n")
133
  for line in lines:
@@ -156,14 +155,14 @@ def call_main(purpose, task, history, directory, action_input,temperature=0.9, t
156
  return "MAIN", None, history, task
157
 
158
 
159
- def call_set_task(purpose, task, history, directory, action_input,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
160
  task = run_gpt(
161
  TASK_PROMPT,
162
  stop_tokens=[],
163
  max_tokens=64,
164
  purpose=purpose,
165
  task=task,
166
- history=history,temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty,
167
  ).strip("\n")
168
  history += "observation: task has been updated to: {}\n".format(task)
169
  return "MAIN", None, history, task
@@ -180,7 +179,7 @@ NAME_TO_FUNC = {
180
  }
181
 
182
 
183
- def run_action(purpose, task, history, directory, action_name, action_input,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
184
  try:
185
  if "RESPONSE" in action_name or "COMPLETE" in action_name:
186
  action_name="COMPLETE"
@@ -199,13 +198,13 @@ def run_action(purpose, task, history, directory, action_name, action_input,temp
199
  assert action_name in NAME_TO_FUNC
200
 
201
  print("RUN: ", action_name, action_input)
202
- return NAME_TO_FUNC[action_name](purpose, task, history, directory, action_input,temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty,)
203
  except Exception as e:
204
  history += "observation: the previous command did not produce any useful output, I need to check the commands syntax, or use a different command\n"
205
 
206
  return "MAIN", None, history, task
207
 
208
- def run(purpose,history,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
209
 
210
  #print(purpose)
211
  #print(hist)
@@ -234,7 +233,7 @@ def run(purpose,history,temperature=0.9, top_p=0.95, repetition_penalty=1.0,):
234
  history,
235
  directory,
236
  action_name,
237
- action_input,temperature=temperature, top_p=top_p, repetition_penalty=repetition_penalty,
238
  )
239
  yield (history)
240
  #yield ("",[(purpose,history)])
@@ -296,6 +295,17 @@ def generate(
296
 
297
 
298
  additional_inputs=[
 
 
 
 
 
 
 
 
 
 
 
299
  gr.Slider(
300
  label="Temperature",
301
  value=0.9,
@@ -305,6 +315,16 @@ additional_inputs=[
305
  interactive=True,
306
  info="Higher values produce more diverse outputs",
307
  ),
 
 
 
 
 
 
 
 
 
 
308
  gr.Slider(
309
  label="Top-p (nucleus sampling)",
310
  value=0.90,
@@ -348,8 +368,6 @@ with gr.Blocks() as ifacea:
348
  gr.HTML("""TEST""")
349
  ifacea.launch()
350
  ).launch()
351
-
352
-
353
  with gr.Blocks() as iface:
354
  #chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
355
  chatbot=gr.Chatbot()
@@ -363,10 +381,8 @@ iface.launch()
363
  '''
364
  gr.ChatInterface(
365
  fn=run,
366
- additional_inputs=additional_inputs,
367
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
368
  title="Mixtral 46.7B\nMicro-Agent\nInternet Search <br> development test",
369
  examples=examples,
370
  concurrency_limit=20,
371
- ).launch(show_api=False)
372
-
 
51
  stop_tokens,
52
  max_tokens,
53
  purpose,
54
+ **prompt_kwargs,
 
55
  ):
56
  seed = random.randint(1,1111111111111111)
57
  print (seed)
58
  generate_kwargs = dict(
59
+ temperature=1.0,
60
  max_new_tokens=1048,
61
+ top_p=0.99,
62
+ repetition_penalty=1.0,
63
  do_sample=True,
64
  seed=seed,
65
  )
 
87
  return resp
88
 
89
 
90
+ def compress_history(purpose, task, history, directory):
91
  resp = run_gpt(
92
  COMPRESS_HISTORY_PROMPT,
93
  stop_tokens=["observation:", "task:", "action:", "thought:"],
94
  max_tokens=512,
95
  purpose=purpose,
96
  task=task,
97
+ history=history,
98
  )
99
  history = "observation: {}\n".format(resp)
100
  return history
101
 
102
+ def call_search(purpose, task, history, directory, action_input):
103
  print("CALLING SEARCH")
104
  try:
105
 
 
119
  history += "observation: {}'\n".format(e)
120
  return "MAIN", None, history, task
121
 
122
+ def call_main(purpose, task, history, directory, action_input):
123
  resp = run_gpt(
124
  ACTION_PROMPT,
125
  stop_tokens=["observation:", "task:"],
126
  max_tokens=1048,
127
  purpose=purpose,
128
  task=task,
129
+ history=history,
130
  )
131
  lines = resp.strip().strip("\n").split("\n")
132
  for line in lines:
 
155
  return "MAIN", None, history, task
156
 
157
 
158
+ def call_set_task(purpose, task, history, directory, action_input):
159
  task = run_gpt(
160
  TASK_PROMPT,
161
  stop_tokens=[],
162
  max_tokens=64,
163
  purpose=purpose,
164
  task=task,
165
+ history=history,
166
  ).strip("\n")
167
  history += "observation: task has been updated to: {}\n".format(task)
168
  return "MAIN", None, history, task
 
179
  }
180
 
181
 
182
+ def run_action(purpose, task, history, directory, action_name, action_input):
183
  try:
184
  if "RESPONSE" in action_name or "COMPLETE" in action_name:
185
  action_name="COMPLETE"
 
198
  assert action_name in NAME_TO_FUNC
199
 
200
  print("RUN: ", action_name, action_input)
201
+ return NAME_TO_FUNC[action_name](purpose, task, history, directory, action_input)
202
  except Exception as e:
203
  history += "observation: the previous command did not produce any useful output, I need to check the commands syntax, or use a different command\n"
204
 
205
  return "MAIN", None, history, task
206
 
207
+ def run(purpose,history):
208
 
209
  #print(purpose)
210
  #print(hist)
 
233
  history,
234
  directory,
235
  action_name,
236
+ action_input,
237
  )
238
  yield (history)
239
  #yield ("",[(purpose,history)])
 
295
 
296
 
297
  additional_inputs=[
298
+ gr.Dropdown(
299
+ label="Agents",
300
+ choices=[s for s in agents],
301
+ value=agents[0],
302
+ interactive=True,
303
+ ),
304
+ gr.Textbox(
305
+ label="System Prompt",
306
+ max_lines=1,
307
+ interactive=True,
308
+ ),
309
  gr.Slider(
310
  label="Temperature",
311
  value=0.9,
 
315
  interactive=True,
316
  info="Higher values produce more diverse outputs",
317
  ),
318
+
319
+ gr.Slider(
320
+ label="Max new tokens",
321
+ value=1048*10,
322
+ minimum=0,
323
+ maximum=1048*10,
324
+ step=64,
325
+ interactive=True,
326
+ info="The maximum numbers of new tokens",
327
+ ),
328
  gr.Slider(
329
  label="Top-p (nucleus sampling)",
330
  value=0.90,
 
368
  gr.HTML("""TEST""")
369
  ifacea.launch()
370
  ).launch()
 
 
371
  with gr.Blocks() as iface:
372
  #chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
373
  chatbot=gr.Chatbot()
 
381
  '''
382
  gr.ChatInterface(
383
  fn=run,
 
384
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
385
  title="Mixtral 46.7B\nMicro-Agent\nInternet Search <br> development test",
386
  examples=examples,
387
  concurrency_limit=20,
388
+ ).launch(show_api=False)