Unable to use extensions kindly someone help me
import openai
# Function to call the 'why' prompt when a test fails
def call_why_prompt(failed_test_description, expected_value, actual_value):
diagnostic_input = f"Why did the following test fail? Test: {failed_test_description}, Expected: {expected_value}, Got: {actual_value}"
# Call OpenAI's GPT-4 API (you need to replace with your API logic)
response = openai.Completion.create(
engine="gpt-4",
prompt=diagnostic_input,
max_tokens=150
)
# Return the diagnostic response
return response.choices[0].text.strip()
# Main hook function
def extension_hook(hook_name, context):
if hook_name == 'beforeAll':
print(f"Setting up test suite: {context['suite'].get('description', '')}")
elif hook_name == 'afterAll':
print(f"Test suite completed: {context['suite'].get('description', '')}")
print(f"Total tests: {len(context['results'])}")
elif hook_name == 'beforeEach':
print(f"Running test: {context['test'].get('description', '')}")
elif hook_name == 'afterEach':
test_description = context['test'].get('description', '')
success = context['result'].get('success', False)
expected = context['test'].get('expected')
actual = context['result'].get('actual')
if not success:
print(f"Test failed: {test_description}")
diagnostic_response = call_why_prompt(test_description, expected, actual)
print(f"Diagnostic response: {diagnostic_response}")
else:
print(f"Test passed: {test_description}")
python file
extensions:
-
file://path/to/your/extension.py:extension_hook