deepeval
deepeval copied to clipboard
No test cases found error
See this code:
`import json import asyncio from deepeval.metrics import AnswerRelevancyMetric, SummarizationMetric, HallucinationMetric from deepeval.test_case import LLMTestCase from deepeval import assert_test import os import openai # Import OpenAI library
Initialize OpenAI API key
os.environ["OPENAI_API_KEY"] = "MY_OPEN_AI_KEY"
Function to retrieve summary asynchronously (replace with actual implementation)
async def get_summary(input_text): # Call the OpenAI chatbot to generate a response response = openai.Completion.create( engine="text-davinci-003", # Specify the engine to use prompt=input_text, max_tokens=150 # Specify the maximum number of tokens for the response ) return response.choices[0].text.strip()
Function to read questions from JSON file
def read_questions_from_json(file_path): with open(file_path, 'r') as file: data = json.load(file) questions = [item['question'] for item in data['questions']] return questions
Function to perform analysis
async def perform_analysis(test_cases): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop)
for test_case in test_cases:
assert_test(test_case, metrics=[test_case.metric])
async def create_test_cases(medical_questions, answers, context): test_cases = [] tasks = []
for i, prompt in enumerate(medical_questions):
task = asyncio.create_task(get_summary_and_create_test_case(prompt, answers[i], context, test_cases))
tasks.append(task)
await asyncio.gather(*tasks)
return test_cases
Function to retrieve summary asynchronously and create test case
async def get_summary_and_create_test_case(prompt, expected_output, context, test_cases):
actual_output = await get_summary(prompt)
test_case = LLMTestCase(
input=prompt,
actual_output=actual_output,
expected_output=expected_output,
context=context,
metric=HallucinationMetric(threshold=0.7)
)
test_cases.append(test_case)
Main function
async def main(): # Path to the JSON file containing medical questions file_path = "medical_questions.json"
# Read questions from JSON file
medical_questions = read_questions_from_json(file_path)
# Placeholder for expected answers
answers = ["Mock expected summary"] * len(medical_questions)
# Placeholder for context if needed
context = None
# Create test cases asynchronously
test_cases = await create_test_cases(medical_questions, answers, context)
# Perform analysis
await perform_analysis(test_cases)
if name == "main": main() `
OUTPUT :
`plugins: deepeval-0.21.36, anyio-4.3.0, repeat-0.9.3, xdist-3.6.1
collected 0 items
Running teardown with pytest sessionfinish...
=========================================================================== 2 warnings in 0.01s =========================================================================== No test cases found, please try again.`