OllamaInterface/OllamaHistoryEditDialog.py

Mon, 16 Sep 2024 19:05:50 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 16 Sep 2024 19:05:50 +0200
changeset 44
ef9a85b8768a
child 67
3c2bcbf7eeaf
permissions
-rw-r--r--

Added the capability to change the model of a chat.

# -*- coding: utf-8 -*-

# Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to edit parameters of a chat history.
"""

from PyQt6.QtCore import pyqtSlot
from PyQt6.QtWidgets import QDialog, QDialogButtonBox

from .Ui_OllamaHistoryEditDialog import Ui_OllamaHistoryEditDialog


class OllamaHistoryEditDialog(QDialog, Ui_OllamaHistoryEditDialog):
    """
    Class implementing a dialog to edit parameters of a chat history.
    """

    def __init__(self, title, model, selectableModels, parent=None):
        """
        Constructor

        @param title title of the chat
        @type str
        @param model current model used by the chat
        @type str
        @param selectableModels list of available models
        @type list of str
        @param parent reference to the parent widget (defaults to None)
        @type QWidget (optional)
        """
        super().__init__(parent)
        self.setupUi(self)

        self.modelComboBox.addItems(selectableModels)

        self.chatTitleEdit.setText(title)
        self.modelComboBox.setCurrentText(model)

        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())

    @pyqtSlot(str)
    def on_chatTitleEdit_textChanged(self, title):
        """
        Private slot to handle a change of the chat title.

        @param title entered title text
        @type str
        """
        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
            bool(title)
        )

    def getData(self):
        """
        Public method to retrieve the entered chat parameters.

        @return tuple containing the entered chat title and the selected model name
        @rtype tuple of (str, str)
        """
        return (
            self.chatTitleEdit.text(),
            self.modelComboBox.currentText(),
        )

eric ide

mercurial