Mon, 07 Apr 2025 18:22:14 +0200
Added the capability to send the prompt by pressing Ctrl-Return or Ctrl-Enter.
<!DOCTYPE html> <html><head> <title>Plugin_AI_Ollama.OllamaInterface.OllamaChatWidget</title> <meta charset="UTF-8"> <link rel="stylesheet" href="styles.css"> </head> <body> <a NAME="top" ID="top"></a> <h1>Plugin_AI_Ollama.OllamaInterface.OllamaChatWidget</h1> <p> Module implementing a widget showing the chat with the 'ollama' server. </p> <h3>Global Attributes</h3> <table> <tr><td>None</td></tr> </table> <h3>Classes</h3> <table> <tr> <td><a href="#OllamaChatDialog">OllamaChatDialog</a></td> <td>Class implementing a dialog showing the chat with the 'ollama' server.</td> </tr> <tr> <td><a href="#OllamaChatWidget">OllamaChatWidget</a></td> <td>Class implementing a widget showing the chat with the 'ollama' server.</td> </tr> </table> <h3>Functions</h3> <table> <tr><td>None</td></tr> </table> <hr /> <hr /> <a NAME="OllamaChatDialog" ID="OllamaChatDialog"></a> <h2>OllamaChatDialog</h2> <p> Class implementing a dialog showing the chat with the 'ollama' server. </p> <h3>Derived from</h3> QDialog <h3>Class Attributes</h3> <table> <tr><td>None</td></tr> </table> <h3>Class Methods</h3> <table> <tr><td>None</td></tr> </table> <h3>Methods</h3> <table> <tr> <td><a href="#OllamaChatDialog.__init__">OllamaChatDialog</a></td> <td>Constructor</td> </tr> <tr> <td><a href="#OllamaChatDialog.getHistoryId">getHistoryId</a></td> <td>Public method to get the history ID of this chat.</td> </tr> <tr> <td><a href="#OllamaChatDialog.setHistory">setHistory</a></td> <td>Public method to add a list of messages to the view.</td> </tr> </table> <h3>Static Methods</h3> <table> <tr><td>None</td></tr> </table> <a NAME="OllamaChatDialog.__init__" ID="OllamaChatDialog.__init__"></a> <h4>OllamaChatDialog (Constructor)</h4> <b>OllamaChatDialog</b>(<i>hid, title, model, parent=None</i>) <p> Constructor </p> <dl> <dt><i>hid</i> (str)</dt> <dd> ID of the chat history </dd> <dt><i>title</i> (str)</dt> <dd> title of the chat </dd> <dt><i>model</i> (str)</dt> <dd> model name used for the chat </dd> <dt><i>parent</i> (QWidget (optional))</dt> <dd> reference to the parent widget (defaults to None) </dd> </dl> <a NAME="OllamaChatDialog.getHistoryId" ID="OllamaChatDialog.getHistoryId"></a> <h4>OllamaChatDialog.getHistoryId</h4> <b>getHistoryId</b>(<i></i>) <p> Public method to get the history ID of this chat. </p> <dl> <dt>Return:</dt> <dd> DESCRIPTION </dd> </dl> <dl> <dt>Return Type:</dt> <dd> TYPE </dd> </dl> <a NAME="OllamaChatDialog.setHistory" ID="OllamaChatDialog.setHistory"></a> <h4>OllamaChatDialog.setHistory</h4> <b>setHistory</b>(<i>messages</i>) <p> Public method to add a list of messages to the view. </p> <dl> <dt><i>messages</i> (list[dict[str, str]])</dt> <dd> list of chat messages </dd> </dl> <div align="right"><a href="#top">Up</a></div> <hr /> <hr /> <a NAME="OllamaChatWidget" ID="OllamaChatWidget"></a> <h2>OllamaChatWidget</h2> <p> Class implementing a widget showing the chat with the 'ollama' server. </p> <h3>Derived from</h3> QWidget, Ui_OllamaChatWidget <h3>Class Attributes</h3> <table> <tr><td>None</td></tr> </table> <h3>Class Methods</h3> <table> <tr><td>None</td></tr> </table> <h3>Methods</h3> <table> <tr> <td><a href="#OllamaChatWidget.__init__">OllamaChatWidget</a></td> <td>Constructor</td> </tr> <tr> <td><a href="#OllamaChatWidget.__scrollChatToBottom">__scrollChatToBottom</a></td> <td>Private slot to scroll the chat scroll area to the bottom.</td> </tr> <tr> <td><a href="#OllamaChatWidget.__setHeader">__setHeader</a></td> <td>Private method to set the header label.</td> </tr> <tr> <td><a href="#OllamaChatWidget.addMessage">addMessage</a></td> <td>Public method to add a new message.</td> </tr> <tr> <td><a href="#OllamaChatWidget.appendMessage">appendMessage</a></td> <td>Public method to append a given message to the bottom most message box.</td> </tr> <tr> <td><a href="#OllamaChatWidget.chatParametersChanged">chatParametersChanged</a></td> <td>Public slot to handle a change of the chat parameters.</td> </tr> <tr> <td><a href="#OllamaChatWidget.clear">clear</a></td> <td>Public method to clear the list of messages.</td> </tr> <tr> <td><a href="#OllamaChatWidget.getHistoryId">getHistoryId</a></td> <td>Public method to get the history ID of this chat.</td> </tr> <tr> <td><a href="#OllamaChatWidget.getRecentMessage">getRecentMessage</a></td> <td>Public method to get the message of the last message box.</td> </tr> </table> <h3>Static Methods</h3> <table> <tr><td>None</td></tr> </table> <a NAME="OllamaChatWidget.__init__" ID="OllamaChatWidget.__init__"></a> <h4>OllamaChatWidget (Constructor)</h4> <b>OllamaChatWidget</b>(<i>hid, title, model, parent=None</i>) <p> Constructor </p> <dl> <dt><i>hid</i> (str)</dt> <dd> ID of the chat history </dd> <dt><i>title</i> (str)</dt> <dd> title of the chat </dd> <dt><i>model</i> (str)</dt> <dd> model name used for the chat </dd> <dt><i>parent</i> (QWidget (optional))</dt> <dd> reference to the parent widget (defaults to None) </dd> </dl> <a NAME="OllamaChatWidget.__scrollChatToBottom" ID="OllamaChatWidget.__scrollChatToBottom"></a> <h4>OllamaChatWidget.__scrollChatToBottom</h4> <b>__scrollChatToBottom</b>(<i></i>) <p> Private slot to scroll the chat scroll area to the bottom. </p> <a NAME="OllamaChatWidget.__setHeader" ID="OllamaChatWidget.__setHeader"></a> <h4>OllamaChatWidget.__setHeader</h4> <b>__setHeader</b>(<i>title, model</i>) <p> Private method to set the header label. </p> <dl> <dt><i>title</i> (str)</dt> <dd> chat title </dd> <dt><i>model</i> (str)</dt> <dd> model of the chat </dd> </dl> <a NAME="OllamaChatWidget.addMessage" ID="OllamaChatWidget.addMessage"></a> <h4>OllamaChatWidget.addMessage</h4> <b>addMessage</b>(<i>role, message, scrollToBottom=True</i>) <p> Public method to add a new message. </p> <dl> <dt><i>role</i> (str)</dt> <dd> role of the message sender (one of 'user' or 'assistant') </dd> <dt><i>message</i> (str)</dt> <dd> message text </dd> <dt><i>scrollToBottom</i> (bool (optional))</dt> <dd> flag indicating to scroll the view to the bottom (defaults to True) </dd> </dl> <a NAME="OllamaChatWidget.appendMessage" ID="OllamaChatWidget.appendMessage"></a> <h4>OllamaChatWidget.appendMessage</h4> <b>appendMessage</b>(<i>message</i>) <p> Public method to append a given message to the bottom most message box. </p> <dl> <dt><i>message</i> (str)</dt> <dd> message text to be appended </dd> </dl> <a NAME="OllamaChatWidget.chatParametersChanged" ID="OllamaChatWidget.chatParametersChanged"></a> <h4>OllamaChatWidget.chatParametersChanged</h4> <b>chatParametersChanged</b>(<i>_hid, title, model</i>) <p> Public slot to handle a change of the chat parameters. </p> <dl> <dt><i>_hid</i> (str)</dt> <dd> history ID (unused) </dd> <dt><i>title</i> (str)</dt> <dd> new chat title </dd> <dt><i>model</i> (str)</dt> <dd> new chat model </dd> </dl> <a NAME="OllamaChatWidget.clear" ID="OllamaChatWidget.clear"></a> <h4>OllamaChatWidget.clear</h4> <b>clear</b>(<i></i>) <p> Public method to clear the list of messages. </p> <a NAME="OllamaChatWidget.getHistoryId" ID="OllamaChatWidget.getHistoryId"></a> <h4>OllamaChatWidget.getHistoryId</h4> <b>getHistoryId</b>(<i></i>) <p> Public method to get the history ID of this chat. </p> <dl> <dt>Return:</dt> <dd> history ID of the chat </dd> </dl> <dl> <dt>Return Type:</dt> <dd> str </dd> </dl> <a NAME="OllamaChatWidget.getRecentMessage" ID="OllamaChatWidget.getRecentMessage"></a> <h4>OllamaChatWidget.getRecentMessage</h4> <b>getRecentMessage</b>(<i></i>) <p> Public method to get the message of the last message box. </p> <dl> <dt>Return:</dt> <dd> message content </dd> </dl> <dl> <dt>Return Type:</dt> <dd> str </dd> </dl> <div align="right"><a href="#top">Up</a></div> <hr /> </body></html>