from functools import reduce
from helper.token_counter import count_tokens

# model = whisper.load_model("base")
# file_path = "audio-samples/mynameisjeff.wav"
# audio_file = AudioSegment.from_file(file_path)
# if os.path.exists(file_path):
#     result = model.transcribe(file_path, fp16=False, language='English', verbose=True)
#     print(result["text"])
# else:
#     print("File not found:", file_path)

messages = [
    {
        "role": "system",
        "content": "You are a IELTS examiner.",
    },
    {
        "role": "system",
        "content": f"The question you have to grade is of type and is the following: ",
    },
    {
        "role": "system",
        "content": "Please provide a JSON object response with the overall grade and breakdown grades, "
                   "formatted as follows: {'overall': 7.0, 'task_response': {'Task Achievement': 8.0, "
                   "'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': "
                   "6.0}}",
    },
    {
        "role": "user",
        "content": f"Evaluate this answer according to ielts grading system:",
    },
]
token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'],
                     map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0)

print(token_count)
