Skip to content

Commit

Permalink
Python test creates a Json result
Browse files Browse the repository at this point in the history
  • Loading branch information
javipacheco committed Nov 20, 2023
1 parent 8883c8b commit b7803a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Binary file not shown.
30 changes: 28 additions & 2 deletions evaluator/evalTest/test_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@
if metric == "AnswerRelevancyMetric":
metricObj = AnswerRelevancyMetric(minimum_score=minimumScore)

jsonResponse = {
"description": appDescription,
}

jsonItemResultResponses = []

for x in range(numberOfOutputs):
jsonItemResponse = {
"description": outputs[x],

}
cases = []
for item in data['items']:
context = []
Expand All @@ -41,15 +51,31 @@
results = execute_test(cases, [metricObj])
print(f"Results: {outputs[x]}:")
totalScore = 0

jsonResultResponses = []

for r in results:
# print_test_result(r)
jsonResultResponse = {
"input": r.input,
"output": r.actual_output,
"score": float(r.metrics[0].score)
}
jsonResultResponses.append(jsonResultResponse)
totalScore += r.metrics[0].score
print(f"- -> {r.metrics[0].score}")
print(f"- {r.input} -> {r.metrics[0].score}")
avg = totalScore / len(results)
jsonItemResponse["tests"] = jsonResultResponses
jsonItemResponse["avg"] = avg
jsonItemResultResponses.append(jsonItemResponse)
print()
print(f"Average: {avg}:")
print()

jsonResponse["results"] = jsonItemResultResponses

with open("results.json", "w") as outfile:
json.dump(jsonResponse, outfile)

print()

f.close()

0 comments on commit b7803a1

Please sign in to comment.