llm.py:
def get_session_id():
    return str(uuid.uuid4())

def save_context(session_id, new_entry, context_type='short'):
    if context_type == 'short':
        if session_id not in session_contexts_short:
            session_contexts_short[session_id] = []
        session_contexts_short[session_id].append(new_entry)
    elif context_type == 'long':
        if session_id not in session_contexts_long:
            session_contexts_long[session_id] = []
        session_contexts_long[session_id].append(new_entry)
    elif context_type == 'chat':
        if session_id not in session_contexts_chat:
            session_contexts_chat[session_id] = []
        session_contexts_chat[session_id].append(new_entry)

def get_context(session_id, context_type='short'):
    if context_type == 'short':
        return session_contexts_short.get(session_id, [])
    elif context_type == 'long':
        return session_contexts_long.get(session_id, [])
    elif context_type == 'chat':
        return session_contexts_chat.get(session_id, [])

def clear_context(session_id, context_type='short'):
    if context_type == 'short' and session_id in session_contexts_short:
        del session_contexts_short[session_id]
    elif context_type == 'long' and session_id in session_contexts_long:
        del session_contexts_long[session_id]
    elif context_type == 'chat' and session_id in session_contexts_chat:
        del session_contexts_chat[session_id]def get_session_id():
    return str(uuid.uuid4())

def save_context(session_id, new_entry, context_type='short'):
    if context_type == 'short':
        if session_id not in session_contexts_short:
            session_contexts_short[session_id] = []
        session_contexts_short[session_id].append(new_entry)
    elif context_type == 'long':
        if session_id not in session_contexts_long:
            session_contexts_long[session_id] = []
        session_contexts_long[session_id].append(new_entry)
    elif context_type == 'chat':
        if session_id not in session_contexts_chat:
            session_contexts_chat[session_id] = []
        session_contexts_chat[session_id].append(new_entry)

def get_context(session_id, context_type='short'):
    if context_type == 'short':
        return session_contexts_short.get(session_id, [])
    elif context_type == 'long':
        return session_contexts_long.get(session_id, [])
    elif context_type == 'chat':
        return session_contexts_chat.get(session_id, [])

def clear_context(session_id, context_type='short'):
    if context_type == 'short' and session_id in session_contexts_short:
        del session_contexts_short[session_id]
    elif context_type == 'long' and session_id in session_contexts_long:
        del session_contexts_long[session_id]
    elif context_type == 'chat' and session_id in session_contexts_chat:
        del session_contexts_chat[session_id]

simple_ui.py:

while True:
    event, values = WINDOW.read()
    if event == sg.WIN_CLOSED:
        break
    if event == '-SHORT_MODEL-' or event == '-LONG_MODEL-':
        short_model_choice = values['-SHORT_MODEL-']
        long_model_choice = values['-LONG_MODEL-']
        llm.save_answer_model_choice(short_model_choice, long_model_choice)
        print(f"Модель для короткого ответа переключена на: {short_model_choice}")
        print(f"Модель для длинного ответа переключена на: {long_model_choice}")
    elif event == '-MODEL-':
        model_choice = values['-MODEL-']
        llm.save_model_choice(model_choice)
        llm.load_model(model_choice)
        print(f"Модель Whisper переключена на: {model_choice}")
    elif event == '-CHAT_MODEL-':
        chat_model_choice = values['-CHAT_MODEL-']
        llm.save_chat_model_choice(chat_model_choice)
        print(f"Модель чата переключена на: {chat_model_choice}")
    elif event == "-WHISPER COMPLETED-":
        audio_transcript = values["-WHISPER COMPLETED-"]
        analyzed_text_label.update(audio_transcript)
        quick_chat_gpt_answer.update("Генерация ответа...")
        WINDOW.perform_long_operation(
            lambda: llm.generate_answer(session_id, audio_transcript, short_answer=True, retries=3, timeout=5),
            "-CHAT_GPT SHORT ANSWER-",
        )
        full_chat_gpt_answer.update("Генерация ответа...")
        WINDOW.perform_long_operation(
            lambda: llm.generate_answer(session_id, audio_transcript, short_answer=False, retries=3, timeout=7),
            "-CHAT_GPT LONG ANSWER-",
        )
    elif event == "-CHAT_GPT SHORT ANSWER-":
        quick_chat_gpt_answer.update(values["-CHAT_GPT SHORT ANSWER-"])
    elif event == "-CHAT_GPT LONG ANSWER-":
        if values.get("-CHAT_GPT LONG ANSWER-"):
            full_chat_gpt_answer.update(values["-CHAT_GPT LONG ANSWER-"])
        current_context = llm.get_context(session_id, context_type='long')
        context_display.update(
            "\n".join(
                f"Вопрос: {entry['content']}"
                for i, entry in enumerate(current_context) if entry['role'] == 'user' and current_context[i - 1]['content'] != entry['content']
            )
        )
        if count_words(current_context) > CONTEXT_WARNING_THRESHOLD:
            sg.Popup("Предупреждение", "Контекст диалога стал слишком большим. Рекомендуется очистить контекст для улучшения производительности.")
    elif event == "Очистить контекст":
        llm.clear_context(session_id, context_type='short')
        llm.clear_context(session_id, context_type='long')
        quick_chat_gpt_answer.update("")
        full_chat_gpt_answer.update("")
        context_display.update("")
        logger.debug("Контекст очищен.")
    elif event == "Отправить":
        query = values["-QUERY-"]
        WINDOW.perform_long_operation(lambda: llm.chat_with_ai(session_id, query), "-CHAT_RESPONSE-")
    elif event == "-CHAT_RESPONSE-":
        response = values["-CHAT_RESPONSE-"]
        WINDOW["-RESPONSE-"].update(response)
    elif event == "-CLEAR_CHAT_CONTEXT-":
        llm.clear_chat_context(session_id)
        WINDOW["-RESPONSE-"].update("Контекст чата очищен.")
# Layout for the second tab
tab2_layout = [
    [sg.Text("Введите запрос:", font=("Helvetica", 12, "bold"), text_color="lightblue")],
    [sg.Multiline(key="-QUERY-", size=(APPLICATION_WIDTH, 5), expand_x=True)],
    [sg.Button("Отправить", font=("Helvetica", 12, "bold"), button_color=("white", "green"), size=(10, 1), pad=(10, 10), expand_x=True)],
    [sg.Text("Ответ:", font=("Helvetica", 12, "bold"), text_color="lightblue")],
    [sg.Multiline(key="-RESPONSE-", size=(APPLICATION_WIDTH, 10), disabled=True, expand_x=True, expand_y=True)],
    [sg.Button("Очистить контекст", key="-CLEAR_CHAT_CONTEXT-", font=("Helvetica", 12, "bold"), button_color=("white", "red"), size=(20, 1), pad=(10, 10), expand_x=True)]
]

есть интерфейс для общения с ии, он сохраняет контекст. сделай, чтоб в форме ответа отображался вопрос и ответ для каждого запроса в контексте