Spaces:
Runtime error
Runtime error
Commit
·
fe9a872
1
Parent(s):
f28d088
- __pycache__/main.cpython-310.pyc +0 -0
- app.py +9 -2
- main.py +7 -7
__pycache__/main.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-310.pyc and b/__pycache__/main.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -93,6 +93,11 @@ if st.session_state.open_router_key and st.session_state.openai_api_key:
|
|
| 93 |
if "user_questions" not in st.session_state:
|
| 94 |
st.session_state.user_questions = []
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Workflow Selection
|
| 97 |
workflow = st.radio("Select Workflow:", ["Use Predefined Questions", "Use User-Defined Questions"])
|
| 98 |
|
|
@@ -139,6 +144,8 @@ if st.session_state.open_router_key and st.session_state.openai_api_key:
|
|
| 139 |
else:
|
| 140 |
max_threads = None # For sequential mode
|
| 141 |
|
|
|
|
|
|
|
| 142 |
# Benchmark Execution
|
| 143 |
if st.button("Start Benchmark"):
|
| 144 |
if not selected_questions:
|
|
@@ -152,9 +159,9 @@ if st.session_state.open_router_key and st.session_state.openai_api_key:
|
|
| 152 |
|
| 153 |
# Benchmarking logic using the chosen execution mode
|
| 154 |
if execution_mode == "Sequential":
|
| 155 |
-
question_results = benchmark_model_sequential(model_name, selected_questions, st.session_state.open_router_key, st.session_state.openai_api_key,judge_model_name)
|
| 156 |
else: # Multithreaded
|
| 157 |
-
question_results = benchmark_model_multithreaded(model_name, selected_questions, st.session_state.open_router_key, st.session_state.openai_api_key, max_threads, judge_model_name)
|
| 158 |
|
| 159 |
results.extend(question_results)
|
| 160 |
|
|
|
|
| 93 |
if "user_questions" not in st.session_state:
|
| 94 |
st.session_state.user_questions = []
|
| 95 |
|
| 96 |
+
# Threshold Sliders
|
| 97 |
+
st.subheader("Threshold Sliders")
|
| 98 |
+
coherence_threshold = st.slider("Coherence Threshold (0-5):", 0, 5, 3)
|
| 99 |
+
novelty_threshold = st.slider("Novelty Threshold (0-1):", 0.0, 1.0, 0.1)
|
| 100 |
+
|
| 101 |
# Workflow Selection
|
| 102 |
workflow = st.radio("Select Workflow:", ["Use Predefined Questions", "Use User-Defined Questions"])
|
| 103 |
|
|
|
|
| 144 |
else:
|
| 145 |
max_threads = None # For sequential mode
|
| 146 |
|
| 147 |
+
|
| 148 |
+
|
| 149 |
# Benchmark Execution
|
| 150 |
if st.button("Start Benchmark"):
|
| 151 |
if not selected_questions:
|
|
|
|
| 159 |
|
| 160 |
# Benchmarking logic using the chosen execution mode
|
| 161 |
if execution_mode == "Sequential":
|
| 162 |
+
question_results = benchmark_model_sequential(model_name, selected_questions, st.session_state.open_router_key, st.session_state.openai_api_key,judge_model_name,coherence_threshold,novelty_threshold)
|
| 163 |
else: # Multithreaded
|
| 164 |
+
question_results = benchmark_model_multithreaded(model_name, selected_questions, st.session_state.open_router_key, st.session_state.openai_api_key, max_threads, judge_model_name, coherence_threshold,novelty_threshold)
|
| 165 |
|
| 166 |
results.extend(question_results)
|
| 167 |
|
main.py
CHANGED
|
@@ -33,7 +33,7 @@ def evaluate_answer(question, new_answer, open_router_key, openai_api_key, judge
|
|
| 33 |
return None
|
| 34 |
|
| 35 |
|
| 36 |
-
def process_question(question, model_name, open_router_key, openai_api_key, result_queue, judge_model_name):
|
| 37 |
start_time = time.time()
|
| 38 |
previous_answers = []
|
| 39 |
question_novelty = 0
|
|
@@ -48,12 +48,12 @@ def process_question(question, model_name, open_router_key, openai_api_key, resu
|
|
| 48 |
if coherence_score is None:
|
| 49 |
break
|
| 50 |
|
| 51 |
-
if coherence_score <=
|
| 52 |
break
|
| 53 |
|
| 54 |
novelty_score = get_novelty_score(new_answer, previous_answers, openai_api_key)
|
| 55 |
|
| 56 |
-
if novelty_score <
|
| 57 |
break
|
| 58 |
|
| 59 |
|
|
@@ -126,7 +126,7 @@ def get_novelty_score(new_answer: str, previous_answers: list, openai_api_key):
|
|
| 126 |
return novelty
|
| 127 |
|
| 128 |
|
| 129 |
-
def benchmark_model_multithreaded(model_name, questions, open_router_key, openai_api_key, max_threads=None, judge_model_name=None):
|
| 130 |
novelty_score = 0
|
| 131 |
results = []
|
| 132 |
result_queue = queue.Queue() # Create a queue for communication
|
|
@@ -140,7 +140,7 @@ def benchmark_model_multithreaded(model_name, questions, open_router_key, openai
|
|
| 140 |
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 141 |
# Submit tasks to the thread pool
|
| 142 |
future_to_question = {
|
| 143 |
-
executor.submit(process_question, question, model_name, open_router_key, openai_api_key, result_queue, judge_model_name): question
|
| 144 |
for question in questions
|
| 145 |
}
|
| 146 |
|
|
@@ -185,12 +185,12 @@ def benchmark_model_multithreaded(model_name, questions, open_router_key, openai
|
|
| 185 |
return results
|
| 186 |
|
| 187 |
|
| 188 |
-
def benchmark_model_sequential(model_name, questions, open_router_key, openai_api_key, judge_model_name):
|
| 189 |
novelty_score = 0
|
| 190 |
results = []
|
| 191 |
|
| 192 |
for i, question in enumerate(questions):
|
| 193 |
-
for result in process_question(question, model_name, open_router_key, openai_api_key, None, judge_model_name):
|
| 194 |
if result["type"] == "answer":
|
| 195 |
st.write(f"**Question:** {result['question']}")
|
| 196 |
st.write(f"**New Answer:**\n{result['answer']}")
|
|
|
|
| 33 |
return None
|
| 34 |
|
| 35 |
|
| 36 |
+
def process_question(question, model_name, open_router_key, openai_api_key, result_queue, judge_model_name,coherence_threshold,novelty_threshold):
|
| 37 |
start_time = time.time()
|
| 38 |
previous_answers = []
|
| 39 |
question_novelty = 0
|
|
|
|
| 48 |
if coherence_score is None:
|
| 49 |
break
|
| 50 |
|
| 51 |
+
if coherence_score <= coherence_threshold:
|
| 52 |
break
|
| 53 |
|
| 54 |
novelty_score = get_novelty_score(new_answer, previous_answers, openai_api_key)
|
| 55 |
|
| 56 |
+
if novelty_score < novelty_threshold:
|
| 57 |
break
|
| 58 |
|
| 59 |
|
|
|
|
| 126 |
return novelty
|
| 127 |
|
| 128 |
|
| 129 |
+
def benchmark_model_multithreaded(model_name, questions, open_router_key, openai_api_key, max_threads=None, judge_model_name=None,coherence_threshold=None,novelty_threshold=None):
|
| 130 |
novelty_score = 0
|
| 131 |
results = []
|
| 132 |
result_queue = queue.Queue() # Create a queue for communication
|
|
|
|
| 140 |
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 141 |
# Submit tasks to the thread pool
|
| 142 |
future_to_question = {
|
| 143 |
+
executor.submit(process_question, question, model_name, open_router_key, openai_api_key, result_queue, judge_model_name,coherence_threshold,novelty_threshold): question
|
| 144 |
for question in questions
|
| 145 |
}
|
| 146 |
|
|
|
|
| 185 |
return results
|
| 186 |
|
| 187 |
|
| 188 |
+
def benchmark_model_sequential(model_name, questions, open_router_key, openai_api_key, judge_model_name,coherence_threshold,novelty_threshold):
|
| 189 |
novelty_score = 0
|
| 190 |
results = []
|
| 191 |
|
| 192 |
for i, question in enumerate(questions):
|
| 193 |
+
for result in process_question(question, model_name, open_router_key, openai_api_key, None, judge_model_name,coherence_threshold,novelty_threshold):
|
| 194 |
if result["type"] == "answer":
|
| 195 |
st.write(f"**Question:** {result['question']}")
|
| 196 |
st.write(f"**New Answer:**\n{result['answer']}")
|