Отвечай на вопросы, используя следующий контекст:
import gradio as gr
from context.db_loader import SQLiteContextLoader
from context.faiss_loader import FaissContextLoader
from models.gpt4o import ModelClient
import constants
from helpers import load_json_file


class NeuroRavenApp:
    def __init__(self):
        self.system_prompt = None
        self.current_theme = None
        self.client = ModelClient()
        self.context_loader = SQLiteContextLoader()
        self.vector_context_loader = FaissContextLoader()
        self.conversation_themes = self.get_conversation_themes()
        if constants.NO_CONTEXT not in self.conversation_themes:
            self.conversation_themes.append(constants.NO_CONTEXT)

    @staticmethod
    def get_conversation_themes():
        themes = load_json_file(constants.CONVERSATION_THEMES_JSON)
        return themes

    def handle_query(self, message, history, context_theme, should_save):
        if context_theme == "VectorBasedTheme":
            if should_save:
                self.vector_context_loader.save_document(context_theme, message)
                return constants.MESSAGE_SAVED_TO_CONTEXT

            context = self.vector_context_loader.load_context(context_theme)
            self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
        else:
            # Существующая логика для SQLite
            if should_save and isinstance(self.context_loader, SQLiteContextLoader):
                if context_theme == constants.NO_CONTEXT:
                    return constants.ERROR_CANNOT_SAVE_MESSAGE
                self.context_loader.save_message(context_theme, message)
                self.current_theme = None
                return constants.MESSAGE_SAVED_TO_CONTEXT

            if context_theme != self.current_theme:
                context = self.context_loader.load_context(context_theme)
                if context:
                    self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
                else:
                    self.system_prompt = constants.DEFAULT_SYSTEM_PROMPT
                self.current_theme = context_theme

        response = self.client.get_response(
            message=message,
            history=history,
            sys_prompt=self.system_prompt
        )
        return response

    def launch_app(self):
        gr.ChatInterface(
            fn=self.handle_query,
            chatbot=gr.Chatbot(height=500),
            textbox=gr.Textbox(
                placeholder=constants.INPUT_PLACEHOLDER,
                container=False,
                scale=7
            ),
            title="NeuroRaven",
            theme="soft",
            retry_btn=None,
            clear_btn=constants.CLEAR_BUTTON_LABEL,
            additional_inputs=[
                gr.Dropdown(
                    self.conversation_themes,
                    label=constants.SELECT_CONTEXT_THEME_LABEL,
                    value=constants.NO_CONTEXT
                ),
                gr.Checkbox(
                    label=constants.SAVE_MESSAGE_LABEL,
                    value=False
                )
            ],
            css="footer{display:none !important}"
        ).launch(server_name=constants.SERVER_NAME, server_port=constants.SERVER_PORT)


if __name__ == "__main__":
    app = NeuroRavenApp()
    app.launch_app()
import gradio as gr
from context.db_loader import SQLiteContextLoader
from context.faiss_loader import FaissContextLoader
from models.gpt4o import ModelClient
import constants
from helpers import load_json_file


class NeuroRavenApp:
    def __init__(self):
        self.system_prompt = None
        self.current_theme = None
        self.client = ModelClient()
        self.context_loader = SQLiteContextLoader()
        self.vector_context_loader = FaissContextLoader()
        self.conversation_themes = self.get_conversation_themes()
        if constants.NO_CONTEXT not in self.conversation_themes:
            self.conversation_themes.append(constants.NO_CONTEXT)

    @staticmethod
    def get_conversation_themes():
        themes = load_json_file(constants.CONVERSATION_THEMES_JSON)
        return themes

    def handle_query(self, message, history, context_theme, should_save):
        if context_theme == "VectorBasedTheme":
            if should_save:
                self.vector_context_loader.save_document(context_theme, message)
                return constants.MESSAGE_SAVED_TO_CONTEXT

            context = self.vector_context_loader.load_context(context_theme)
            self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
        else:
            # Существующая логика для SQLite
            if should_save and isinstance(self.context_loader, SQLiteContextLoader):
                if context_theme == constants.NO_CONTEXT:
                    return constants.ERROR_CANNOT_SAVE_MESSAGE
                self.context_loader.save_message(context_theme, message)
                self.current_theme = None
                return constants.MESSAGE_SAVED_TO_CONTEXT

            if context_theme != self.current_theme:
                context = self.context_loader.load_context(context_theme)
                if context:
                    self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
                else:
                    self.system_prompt = constants.DEFAULT_SYSTEM_PROMPT
                self.current_theme = context_theme

        response = self.client.get_response(
            message=message,
            history=history,
            sys_prompt=self.system_prompt
        )
        return response

    def launch_app(self):
        gr.ChatInterface(
            fn=self.handle_query,
            chatbot=gr.Chatbot(height=500),
            textbox=gr.Textbox(
                placeholder=constants.INPUT_PLACEHOLDER,
                container=False,
                scale=7
            ),
            title="NeuroRaven",
            theme="soft",
            retry_btn=None,
            clear_btn=constants.CLEAR_BUTTON_LABEL,
            additional_inputs=[
                gr.Dropdown(
                    self.conversation_themes,
                    label=constants.SELECT_CONTEXT_THEME_LABEL,
                    value=constants.NO_CONTEXT
                ),
                gr.Checkbox(
                    label=constants.SAVE_MESSAGE_LABEL,
                    value=False
                )
            ],
            css="footer{display:none !important}"
        ).launch(server_name=constants.SERVER_NAME, server_port=constants.SERVER_PORT)


if __name__ == "__main__":
    app = NeuroRavenApp()
    app.launch_app()
import gradio as gr
from context.db_loader import SQLiteContextLoader
from context.faiss_loader import FaissContextLoader
from models.gpt4o import ModelClient
import constants
from helpers import load_json_file


class NeuroRavenApp:
    def __init__(self):
        self.system_prompt = None
        self.current_theme = None
        self.client = ModelClient()
        self.context_loader = SQLiteContextLoader()
        self.vector_context_loader = FaissContextLoader()
        self.conversation_themes = self.get_conversation_themes()
        if constants.NO_CONTEXT not in self.conversation_themes:
            self.conversation_themes.append(constants.NO_CONTEXT)

    @staticmethod
    def get_conversation_themes():
        themes = load_json_file(constants.CONVERSATION_THEMES_JSON)
        return themes

    def handle_query(self, message, history, context_theme, should_save):
        if context_theme == "VectorBasedTheme":
            if should_save:
                self.vector_context_loader.save_document(context_theme, message)
                return constants.MESSAGE_SAVED_TO_CONTEXT

            context = self.vector_context_loader.load_context(context_theme)
            self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
        else:
            # Существующая логика для SQLite
            if should_save and isinstance(self.context_loader, SQLiteContextLoader):
                if context_theme == constants.NO_CONTEXT:
                    return constants.ERROR_CANNOT_SAVE_MESSAGE
                self.context_loader.save_message(context_theme, message)
                self.current_theme = None
                return constants.MESSAGE_SAVED_TO_CONTEXT

            if context_theme != self.current_theme:
                context = self.context_loader.load_context(context_theme)
                if context:
                    self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
                else:
                    self.system_prompt = constants.DEFAULT_SYSTEM_PROMPT
                self.current_theme = context_theme

        response = self.client.get_response(
            message=message,
            history=history,
            sys_prompt=self.system_prompt
        )
        return response

    def launch_app(self):
        gr.ChatInterface(
            fn=self.handle_query,
            chatbot=gr.Chatbot(height=500),
            textbox=gr.Textbox(
                placeholder=constants.INPUT_PLACEHOLDER,
                container=False,
                scale=7
            ),
            title="NeuroRaven",
            theme="soft",
            retry_btn=None,
            clear_btn=constants.CLEAR_BUTTON_LABEL,
            additional_inputs=[
                gr.Dropdown(
                    self.conversation_themes,
                    label=constants.SELECT_CONTEXT_THEME_LABEL,
                    value=constants.NO_CONTEXT
                ),
                gr.Checkbox(
                    label=constants.SAVE_MESSAGE_LABEL,
                    value=False
                )
            ],
            css="footer{display:none !important}"
        ).launch(server_name=constants.SERVER_NAME, server_port=constants.SERVER_PORT)


if __name__ == "__main__":
    app = NeuroRavenApp()
    app.launch_app()
import gradio as gr
from context.db_loader import SQLiteContextLoader
from context.faiss_loader import FaissContextLoader
from models.gpt4o import ModelClient
import constants
from helpers import load_json_file


class NeuroRavenApp:
    def __init__(self):
        self.system_prompt = None
        self.current_theme = None
        self.client = ModelClient()
        self.context_loader = SQLiteContextLoader()
        self.vector_context_loader = FaissContextLoader()
        self.conversation_themes = self.get_conversation_themes()
        if constants.NO_CONTEXT not in self.conversation_themes:
            self.conversation_themes.append(constants.NO_CONTEXT)

    @staticmethod
    def get_conversation_themes():
        themes = load_json_file(constants.CONVERSATION_THEMES_JSON)
        return themes

    def handle_query(self, message, history, context_theme, should_save):
        if context_theme == "VectorBasedTheme":
            if should_save:
                self.vector_context_loader.save_document(context_theme, message)
                return constants.MESSAGE_SAVED_TO_CONTEXT

            context = self.vector_context_loader.load_context(context_theme)
            self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
        else:
            # Существующая логика для SQLite
            if should_save and isinstance(self.context_loader, SQLiteContextLoader):
                if context_theme == constants.NO_CONTEXT:
                    return constants.ERROR_CANNOT_SAVE_MESSAGE
                self.context_loader.save_message(context_theme, message)
                self.current_theme = None
                return constants.MESSAGE_SAVED_TO_CONTEXT

            if context_theme != self.current_theme:
                context = self.context_loader.load_context(context_theme)
                if context:
                    self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
                else:
                    self.system_prompt = constants.DEFAULT_SYSTEM_PROMPT
                self.current_theme = context_theme

        response = self.client.get_response(
            message=message,
            history=history,
            sys_prompt=self.system_prompt
        )
        return response

    def launch_app(self):
        gr.ChatInterface(
            fn=self.handle_query,
            chatbot=gr.Chatbot(height=500),
            textbox=gr.Textbox(
                placeholder=constants.INPUT_PLACEHOLDER,
                container=False,
                scale=7
            ),
            title="NeuroRaven",
            theme="soft",
            retry_btn=None,
            clear_btn=constants.CLEAR_BUTTON_LABEL,
            additional_inputs=[
                gr.Dropdown(
                    self.conversation_themes,
                    label=constants.SELECT_CONTEXT_THEME_LABEL,
                    value=constants.NO_CONTEXT
                ),
                gr.Checkbox(
                    label=constants.SAVE_MESSAGE_LABEL,
                    value=False
                )
            ],
            css="footer{display:none !important}"
        ).launch(server_name=constants.SERVER_NAME, server_port=constants.SERVER_PORT)


if __name__ == "__main__":
    app = NeuroRavenApp()
    app.launch_app()
import gradio as gr
from context.db_loader import SQLiteContextLoader
from context.faiss_loader import FaissContextLoader
from models.gpt4o import ModelClient
import constants
from helpers import load_json_file


class NeuroRavenApp:
    def __init__(self):
        self.system_prompt = None
        self.current_theme = None
        self.client = ModelClient()
        self.context_loader = SQLiteContextLoader()
        self.vector_context_loader = FaissContextLoader()
        self.conversation_themes = self.get_conversation_themes()
        if constants.NO_CONTEXT not in self.conversation_themes:
            self.conversation_themes.append(constants.NO_CONTEXT)

    @staticmethod
    def get_conversation_themes():
        themes = load_json_file(constants.CONVERSATION_THEMES_JSON)
        return themes

    def handle_query(self, message, history, context_theme, should_save):
        if context_theme == "VectorBasedTheme":
            if should_save:
                self.vector_context_loader.save_document(context_theme, message)
                return constants.MESSAGE_SAVED_TO_CONTEXT

            context = self.vector_context_loader.load_context(context_theme)
            self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
        else:
            # Существующая логика для SQLite
            if should_save and isinstance(self.context_loader, SQLiteContextLoader):
                if context_theme == constants.NO_CONTEXT:
                    return constants.ERROR_CANNOT_SAVE_MESSAGE
                self.context_loader.save_message(context_theme, message)
                self.current_theme = None
                return constants.MESSAGE_SAVED_TO_CONTEXT

            if context_theme != self.current_theme:
                context = self.context_loader.load_context(context_theme)
                if context:
                    self.system_prompt = constants.ANSWER_USING_CONTEXT_PROMPT.format(context=context)
                else:
                    self.system_prompt = constants.DEFAULT_SYSTEM_PROMPT
                self.current_theme = context_theme

        response = self.client.get_response(
            message=message,
            history=history,
            sys_prompt=self.system_prompt
        )
        return response

    def launch_app(self):
        gr.ChatInterface(
            fn=self.handle_query,
            chatbot=gr.Chatbot(height=500),
            textbox=gr.Textbox(
                placeholder=constants.INPUT_PLACEHOLDER,
                container=False,
                scale=7
            ),
            title="NeuroRaven",
            theme="soft",
            retry_btn=None,
            clear_btn=constants.CLEAR_BUTTON_LABEL,
            additional_inputs=[
                gr.Dropdown(
                    self.conversation_themes,
                    label=constants.SELECT_CONTEXT_THEME_LABEL,
                    value=constants.NO_CONTEXT
                ),
                gr.Checkbox(
                    label=constants.SAVE_MESSAGE_LABEL,
                    value=False
                )
            ],
            css="footer{display:none !important}"
        ).launch(server_name=constants.SERVER_NAME, server_port=constants.SERVER_PORT)


if __name__ == "__main__":
    app = NeuroRavenApp()
    app.launch_app()
Что ты знаешь  про NeuroRavenApp