Open GantaVenkataKousik opened 6 months ago
Hey @GantaVenkataKousik there is some formatting errors in your code can you double check your backticks. You're getting this error because you're using assert_test
outside of a test file (?) or test function (?) (can't tell properly because of the formatting). Please read the docs to learn how to use the assert_test
function properly: https://docs.confident-ai.com/docs/getting-started#create-your-first-metric
Hey @GantaVenkataKousik there is some formatting errors in your code can you double check your backticks. You're getting this error because you're using
assert_test
outside of a test file (?) or test function (?) (can't tell properly because of the formatting). Please read the docs to learn how to use theassert_test
function properly: https://docs.confident-ai.com/docs/getting-started#create-your-first-metric
I have reviewed the documentation, but I'm still unable to identify the issue. These are the screenshots of the code .
Hey @GantaVenkataKousik I missed your message, can you come to our discord for faster response times? https://discord.com/invite/a3K9c8GRGt
assert_test
is not meant to be used in a for loop, nor is it meant to be used outside of deepeval test run. come to discord to talk more
Hey @GantaVenkataKousik I missed your message, can you come to our discord for faster response times? https://discord.com/invite/a3K9c8GRGt
assert_test
is not meant to be used in a for loop, nor is it meant to be used outside of deepeval test run. come to discord to talk more
Sure , I will join discord .
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
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)
async def create_test_cases(medical_questions, answers, context): test_cases = [] tasks = []
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
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.`