import os
import time

from functions import func_map

from llm import LLMModel, llm_model_path, FCModel, fc_model_path
llm_model = LLMModel(llm_model_path)
fc_model = FCModel(fc_model_path)

from asr import ASRModel, record_audio
asr_model = ASRModel()

if __name__ == '__main__':
    try:
        while True:
            audio_file = record_audio()
            text = asr_model.generate(audio_file)
            print('user: ', text)

            t1 = time.time()
            function_called = fc_model.func_response(text, func_map)
            print('used time:', time.time() - t1)
            if function_called:
                continue

            llm_output = llm_model.generate(text)
            for output_text in llm_output:
                print(output_text, end='', flush=True)

    except KeyboardInterrupt:
        print("process was interrupted by user.")
