Skip to content

Commit

Permalink
Merge pull request #84 from VivekSinghDS/hotfix/qa-test-methods
Browse files Browse the repository at this point in the history
Hotfix/qa test methods
  • Loading branch information
benjaminye committed Mar 11, 2024
2 parents 0fccb8f + 56a2ada commit 5f1e1f5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
21 changes: 14 additions & 7 deletions toolkit/src/qa/qa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import ABC, abstractmethod
from typing import Union, List, Tuple, Dict


import pandas as pd
from toolkit.src.ui.rich_ui import RichUI
import statistics

class LLMQaTest(ABC):
@property
Expand Down Expand Up @@ -37,7 +38,6 @@ def run_tests(self) -> Dict[str, List[Union[float, int, bool]]]:
test_results[test.test_name] = metrics

self.test_results = test_results

return test_results

@property
Expand All @@ -46,9 +46,16 @@ def test_results(self):


def print_test_results(self):
# TODO: format these!
print(self.test_results)

result_dictionary = self.test_results()
column_data = {key: [value for value in result_dictionary[key]] for key in result_dictionary}
mean_values = {key: statistics.mean(column_data[key]) for key in column_data}
median_values = {key: statistics.median(column_data[key]) for key in column_data}
stdev_values = {key: statistics.stdev(column_data[key]) for key in column_data}
# Use the RichUI class to display the table
RichUI.display_table(result_dictionary, mean_values, median_values, stdev_values)

def save_test_results(self, path:str):
# TODO: save these!
pass
resultant_dataframe = pd.DataFrame(self.test_results())
resultant_dataframe.to_csv(path, index = False)

24 changes: 24 additions & 0 deletions toolkit/src/ui/rich_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,27 @@ def after_qa():
@staticmethod
def qa_found():
pass

@staticmethod
def qa_display_table(self, result_dictionary, mean_values, median_values, stdev_values):

# Create a table
table = Table(show_header=True, header_style="bold", title="Test Results")

# Add columns to the table
table.add_column("Metric", style="cyan")
table.add_column("Mean", style="magenta")
table.add_column("Median", style="green")
table.add_column("Standard Deviation", style="yellow")

# Add data rows to the table
for key in result_dictionary:
table.add_row(
key,
f"{mean_values[key]:.4f}",
f"{median_values[key]:.4f}",
f"{stdev_values[key]:.4f}"
)

# Print the table
console.print(table)
4 changes: 4 additions & 0 deletions toolkit/src/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ def after_qa(cls):
@abstractstaticmethod
def qa_found(cls):
pass

@abstractstaticmethod
def qa_display_table(cls):
pass

0 comments on commit 5f1e1f5

Please sign in to comment.