forked from composable-models/llm_multiagent_debate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
296 lines (251 loc) · 10.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import pandas as pd
import gradio as gr
import json
from simplemath import gen_math_gradio
from gsm import gen_gsm_gradio
from mmlu import gen_mmlu_gradio
from biography import gen_conversation_gradio
from pathlib import Path
from glob import glob
BASE_DIR = Path(__file__).resolve().parent
# List of available models
available_models = [
"gpt-3.5-turbo",
"gpt-4",
"gpt-4-turbo",
"gpt-4o",
"gpt-4o-mini",
]
def read_jsonl(path: str):
with open(path) as fh:
return [json.loads(line) for line in fh.readlines() if line]
# Load GSM questions from test.jsonl for dropdown
gsm_questions = [
q["question"] for q in read_jsonl(BASE_DIR / "gsm" / "data" / "test.jsonl")
]
# Function to get CSV file names and map to categories for MMLU
def get_mmlu_categories():
csv_files = glob(str(BASE_DIR / "mmlu" / "data" / "test" / "*.csv"))
categories = [
Path(f).stem for f in csv_files
] # Get the file name without extension
return categories, csv_files
# Function to load questions from a selected CSV file
def load_questions_from_csv(csv_file):
df = pd.read_csv(csv_file)
questions = df.iloc[
:, 0
].tolist() # Assuming the first column contains the questions
return questions
# Load MMLU categories
mmlu_categories, mmlu_csv_files = get_mmlu_categories()
def load_people_from_article():
with open(BASE_DIR / "biography" / "article.json", "r") as f:
data = json.load(f)
return list(data.keys()) # Return the names of people from the keys
people_list = load_people_from_article()
# Build the Gradio interface using Tabs
with gr.Blocks() as demo:
gr.Markdown(
"# GPT Multi Agents Debate WebUI",
)
with gr.Tabs():
with gr.Tab("Math"):
with gr.Row():
# Sliders for input configurations
agents_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Agents"
)
rounds_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Rounds"
)
evals_slider = gr.Slider(
minimum=1,
maximum=100,
step=1,
value=1,
label="Number of Evaluations",
)
# Dropdown for model selection
model_dropdown = gr.Dropdown(
choices=available_models,
value=available_models[0],
label="Select OpenAI Model",
)
# Dataframe output for agent interaction history
answer_history = gr.Dataframe(
headers=["Evaluation", "Agent", "Role", "Content"],
label="Agent Interaction History",
interactive=False, # Ensure it's non-interactive to allow styling
)
# Submit button to trigger the function
submit_button = gr.Button("Submit")
# Link the button click to the main function from gen_math_gradio
submit_button.click(
fn=gen_math_gradio.main,
inputs=[agents_slider, rounds_slider, evals_slider, model_dropdown],
outputs=[answer_history],
)
with gr.Tab("GSM"):
with gr.Row():
# Sliders for GSM input configurations
gsm_agents_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Agents"
)
gsm_rounds_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Rounds"
)
gsm_evals_slider = gr.Slider(
minimum=1,
maximum=100,
step=1,
value=1,
label="Number of Evaluations",
)
# Dropdown for GSM model selection
gsm_model_dropdown = gr.Dropdown(
choices=available_models,
value=available_models[0],
label="Select OpenAI Model",
)
# New Dropdown for selecting GSM questions from test.jsonl
gsm_question_dropdown = gr.Dropdown(
choices=gsm_questions,
label="Select GSM Question",
)
# Dataframe output for GSM agent interaction history
gsm_answer_history = gr.Dataframe(
headers=["Evaluation", "Agent", "Role", "Content"],
label="GSM Agent Interaction History",
interactive=False,
)
# Submit button to trigger the function for GSM
gsm_submit_button = gr.Button("Submit")
# Link the button click to the main function from gen_gsm_gradio
gsm_submit_button.click(
fn=gen_gsm_gradio.main,
inputs=[
gsm_agents_slider,
gsm_rounds_slider,
gsm_evals_slider,
gsm_model_dropdown,
gsm_question_dropdown,
],
outputs=[gsm_answer_history],
)
# MMLU Tab for Massive Multitask Language Understanding
with gr.Tab("MMLU"):
with gr.Row():
# Sliders for MMLU input configurations
mmlu_agents_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Agents"
)
mmlu_rounds_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Rounds"
)
mmlu_evals_slider = gr.Slider(
minimum=1,
maximum=100,
step=1,
value=1,
label="Number of Evaluations",
)
# Dropdown for MMLU model selection
mmlu_model_dropdown = gr.Dropdown(
choices=available_models,
value=available_models[0],
label="Select OpenAI Model",
)
# Dropdown for MMLU category (CSV file names)
mmlu_category_dropdown = gr.Dropdown(
choices=mmlu_categories,
label="Select MMLU Category",
)
# Dropdown for MMLU questions (this will be populated dynamically)
mmlu_question_dropdown = gr.Dropdown(
choices=[],
label="Select MMLU Question",
)
# Function to update questions when a category is selected
def update_questions(selected_category):
csv_file = mmlu_csv_files[mmlu_categories.index(selected_category)]
questions = load_questions_from_csv(csv_file)
return gr.update(
choices=questions
) # Use gr.update to update the dropdown
# Update the question dropdown when a category is selected
mmlu_category_dropdown.change(
fn=update_questions,
inputs=[mmlu_category_dropdown],
outputs=[mmlu_question_dropdown],
)
# Textbox output for MMLU agent interaction history (Changed to a Textbox for better readability)
mmlu_answer_history = gr.Textbox(
label="MMLU Agent Interaction History",
lines=10,
interactive=False,
)
# Submit button to trigger the function for MMLU
mmlu_submit_button = gr.Button("Submit")
# Link the button click to the main function from gen_mmlu_gradio
mmlu_submit_button.click(
fn=gen_mmlu_gradio.main,
inputs=[
mmlu_agents_slider,
mmlu_rounds_slider,
mmlu_evals_slider,
mmlu_model_dropdown,
mmlu_category_dropdown, # Added category dropdown input
mmlu_question_dropdown, # Added question dropdown input
],
outputs=[mmlu_answer_history],
)
# Gradio UI for Biography
with gr.Tab("Biography"):
with gr.Row():
# Sliders for Biography input configurations
bio_agents_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Agents"
)
bio_rounds_slider = gr.Slider(
minimum=1, maximum=5, step=1, value=2, label="Number of Rounds"
)
bio_evals_slider = gr.Slider(
minimum=1,
maximum=40,
step=1,
value=1,
label="Number of Evaluations",
)
# Dropdown for biography model selection
bio_model_dropdown = gr.Dropdown(
choices=available_models,
value=available_models[0],
label="Select OpenAI Model",
)
# New Dropdown for selecting a person from article.json
bio_people_dropdown = gr.Dropdown(
choices=people_list, # Populate dropdown with the names from article.json
label="Select Person for Biography",
)
# Dataframe output for biography agent interaction history
bio_answer_history = gr.Dataframe(
headers=["Person", "Agent", "Role", "Content"],
label="Biography Agent Interaction History",
interactive=False,
)
# Submit button to trigger the function for Biography
bio_submit_button = gr.Button("Submit")
# Link the button click to the main function from get_conversation_gradio
bio_submit_button.click(
fn=gen_conversation_gradio.main,
inputs=[
bio_agents_slider,
bio_rounds_slider,
bio_evals_slider,
bio_model_dropdown,
bio_people_dropdown, # Pass the selected person to the main function
],
outputs=[bio_answer_history],
)
demo.launch()