mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-08 07:10:32 +00:00
Add a reset context feature to clear the chat history and the context for now.
This commit is contained in:
parent
f9d676b28b
commit
c62ebdb81c
@ -47,7 +47,6 @@ set(CPACK_GENERATOR "IFW")
|
|||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES Linux)
|
if(${CMAKE_SYSTEM_NAME} MATCHES Linux)
|
||||||
find_program(LINUXDEPLOYQT linuxdeployqt HINTS ${_qt_bin_dir})
|
find_program(LINUXDEPLOYQT linuxdeployqt HINTS ${_qt_bin_dir})
|
||||||
message(AUTHOR_WARNING "heeeeeee ${LINUXDEPLOYQT}")
|
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deploy-qt-linux.cmake.in"
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deploy-qt-linux.cmake.in"
|
||||||
"${CMAKE_BINARY_DIR}/cmake/deploy-qt-linux.cmake" @ONLY)
|
"${CMAKE_BINARY_DIR}/cmake/deploy-qt-linux.cmake" @ONLY)
|
||||||
set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-linux.cmake)
|
set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-linux.cmake)
|
||||||
@ -59,6 +58,11 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows)
|
|||||||
set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-windows.cmake)
|
set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-windows.cmake)
|
||||||
set(CPACK_IFW_ROOT "C:/Qt/Tools/QtInstallerFramework/4.5")
|
set(CPACK_IFW_ROOT "C:/Qt/Tools/QtInstallerFramework/4.5")
|
||||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES Darwin)
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES Darwin)
|
||||||
|
find_program(MACDEPLOYQT macdeployqt HINTS ${_qt_bin_dir})
|
||||||
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deploy-qt-mac.cmake.in"
|
||||||
|
"${CMAKE_BINARY_DIR}/cmake/deploy-qt-mac.cmake" @ONLY)
|
||||||
|
set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-mac.cmake)
|
||||||
|
set(CPACK_IFW_ROOT "~/Qt/Tools/QtInstallerFramework/4.5")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
||||||
|
16
llm.cpp
16
llm.cpp
@ -13,6 +13,8 @@ LLM *LLM::globalInstance()
|
|||||||
return llmInstance();
|
return llmInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GPTJ::PromptContext s_ctx;
|
||||||
|
|
||||||
GPTJObject::GPTJObject()
|
GPTJObject::GPTJObject()
|
||||||
: QObject{nullptr}
|
: QObject{nullptr}
|
||||||
, m_gptj(new GPTJ)
|
, m_gptj(new GPTJ)
|
||||||
@ -51,6 +53,11 @@ void GPTJObject::resetResponse()
|
|||||||
m_response = std::string();
|
m_response = std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPTJObject::resetContext()
|
||||||
|
{
|
||||||
|
s_ctx = GPTJ::PromptContext();
|
||||||
|
}
|
||||||
|
|
||||||
QString GPTJObject::response() const
|
QString GPTJObject::response() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(m_response);
|
return QString::fromStdString(m_response);
|
||||||
@ -75,8 +82,7 @@ bool GPTJObject::prompt(const QString &prompt)
|
|||||||
m_stopGenerating = false;
|
m_stopGenerating = false;
|
||||||
auto func = std::bind(&GPTJObject::handleResponse, this, std::placeholders::_1);
|
auto func = std::bind(&GPTJObject::handleResponse, this, std::placeholders::_1);
|
||||||
emit responseStarted();
|
emit responseStarted();
|
||||||
static GPTJ::PromptContext ctx;
|
m_gptj->prompt(prompt.toStdString(), func, s_ctx, 4096 /*number of chars to predict*/);
|
||||||
m_gptj->prompt(prompt.toStdString(), func, ctx, 4096 /*number of chars to predict*/);
|
|
||||||
emit responseStopped();
|
emit responseStopped();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -93,6 +99,7 @@ LLM::LLM()
|
|||||||
|
|
||||||
connect(this, &LLM::promptRequested, m_gptj, &GPTJObject::prompt, Qt::QueuedConnection);
|
connect(this, &LLM::promptRequested, m_gptj, &GPTJObject::prompt, Qt::QueuedConnection);
|
||||||
connect(this, &LLM::resetResponseRequested, m_gptj, &GPTJObject::resetResponse, Qt::BlockingQueuedConnection);
|
connect(this, &LLM::resetResponseRequested, m_gptj, &GPTJObject::resetResponse, Qt::BlockingQueuedConnection);
|
||||||
|
connect(this, &LLM::resetContextRequested, m_gptj, &GPTJObject::resetContext, Qt::BlockingQueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LLM::isModelLoaded() const
|
bool LLM::isModelLoaded() const
|
||||||
@ -110,6 +117,11 @@ void LLM::resetResponse()
|
|||||||
emit resetResponseRequested(); // blocking queued connection
|
emit resetResponseRequested(); // blocking queued connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLM::resetContext()
|
||||||
|
{
|
||||||
|
emit resetContextRequested(); // blocking queued connection
|
||||||
|
}
|
||||||
|
|
||||||
void LLM::stopGenerating()
|
void LLM::stopGenerating()
|
||||||
{
|
{
|
||||||
m_gptj->stopGenerating();
|
m_gptj->stopGenerating();
|
||||||
|
3
llm.h
3
llm.h
@ -18,6 +18,7 @@ public:
|
|||||||
bool loadModel();
|
bool loadModel();
|
||||||
bool isModelLoaded() const;
|
bool isModelLoaded() const;
|
||||||
void resetResponse();
|
void resetResponse();
|
||||||
|
void resetContext();
|
||||||
void stopGenerating() { m_stopGenerating = true; }
|
void stopGenerating() { m_stopGenerating = true; }
|
||||||
|
|
||||||
QString response() const;
|
QString response() const;
|
||||||
@ -53,6 +54,7 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE bool isModelLoaded() const;
|
Q_INVOKABLE bool isModelLoaded() const;
|
||||||
Q_INVOKABLE void prompt(const QString &prompt);
|
Q_INVOKABLE void prompt(const QString &prompt);
|
||||||
|
Q_INVOKABLE void resetContext();
|
||||||
Q_INVOKABLE void resetResponse();
|
Q_INVOKABLE void resetResponse();
|
||||||
Q_INVOKABLE void stopGenerating();
|
Q_INVOKABLE void stopGenerating();
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ Q_SIGNALS:
|
|||||||
void responseInProgressChanged();
|
void responseInProgressChanged();
|
||||||
void promptRequested(const QString &prompt);
|
void promptRequested(const QString &prompt);
|
||||||
void resetResponseRequested();
|
void resetResponseRequested();
|
||||||
|
void resetContextRequested();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void responseStarted();
|
void responseStarted();
|
||||||
|
22
main.qml
22
main.qml
@ -187,7 +187,7 @@ Window {
|
|||||||
TextField {
|
TextField {
|
||||||
id: textInput
|
id: textInput
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: resetContextButton.left
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.margins: 30
|
anchors.margins: 30
|
||||||
color: "#dadadc"
|
color: "#dadadc"
|
||||||
@ -239,5 +239,25 @@ Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: resetContextButton
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 30
|
||||||
|
anchors.verticalCenter: textInput.verticalCenter
|
||||||
|
width: 40
|
||||||
|
height: 40
|
||||||
|
|
||||||
|
background: Image {
|
||||||
|
anchors.fill: parent
|
||||||
|
source: "qrc:/gpt4all-chat/icons/regenerate.svg"
|
||||||
|
}
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
LLM.stopGenerating()
|
||||||
|
LLM.resetContext()
|
||||||
|
chatModel.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user