@ -31,16 +31,29 @@ bool GPTJObject::loadModel()
if ( isModelLoaded ( ) )
if ( isModelLoaded ( ) )
return true ;
return true ;
QString modelName ( " ggml-model-q4_0.bin " ) ;
QDir dir ( QCoreApplication : : applicationDirPath ( ) ) ;
QString fileName = QCoreApplication : : applicationDirPath ( ) + QDir : : separator ( ) + modelName ;
dir . setNameFilters ( QStringList ( ) < < " ggml-*.bin " ) ;
QFile file ( fileName ) ;
QStringList fileNames = dir . entryList ( ) ;
if ( file . exists ( ) ) {
if ( fileNames . isEmpty ( ) ) {
qDebug ( ) < < " ERROR: Could not find any applicable models in directory "
< < QCoreApplication : : applicationDirPath ( ) ;
}
QString modelName = fileNames . first ( ) ;
QString filePath = QCoreApplication : : applicationDirPath ( ) + QDir : : separator ( ) + modelName ;
QFileInfo info ( filePath ) ;
if ( info . exists ( ) ) {
auto fin = std : : ifstream ( fileName . toStdString ( ) , std : : ios : : binary ) ;
auto fin = std : : ifstream ( file Path . toStdString ( ) , std : : ios : : binary ) ;
m_gptj - > loadModel ( modelName . toStdString ( ) , fin ) ;
m_gptj - > loadModel ( modelName . toStdString ( ) , fin ) ;
emit isModelLoadedChanged ( ) ;
emit isModelLoadedChanged ( ) ;
}
}
if ( m_gptj ) {
m_modelName = info . baseName ( ) . remove ( 0 , 5 ) ; // remove the ggml- prefix
emit modelNameChanged ( ) ;
}
return m_gptj ;
return m_gptj ;
}
}
@ -64,6 +77,11 @@ QString GPTJObject::response() const
return QString : : fromStdString ( m_response ) ;
return QString : : fromStdString ( m_response ) ;
}
}
QString GPTJObject : : modelName ( ) const
{
return m_modelName ;
}
bool GPTJObject : : handleResponse ( const std : : string & response )
bool GPTJObject : : handleResponse ( const std : : string & response )
{
{
#if 0
#if 0
@ -97,6 +115,7 @@ LLM::LLM()
connect ( m_gptj , & GPTJObject : : responseChanged , this , & LLM : : responseChanged , Qt : : QueuedConnection ) ;
connect ( m_gptj , & GPTJObject : : responseChanged , this , & LLM : : responseChanged , Qt : : QueuedConnection ) ;
connect ( m_gptj , & GPTJObject : : responseStarted , this , & LLM : : responseStarted , Qt : : QueuedConnection ) ;
connect ( m_gptj , & GPTJObject : : responseStarted , this , & LLM : : responseStarted , Qt : : QueuedConnection ) ;
connect ( m_gptj , & GPTJObject : : responseStopped , this , & LLM : : responseStopped , Qt : : QueuedConnection ) ;
connect ( m_gptj , & GPTJObject : : responseStopped , this , & LLM : : responseStopped , Qt : : QueuedConnection ) ;
connect ( m_gptj , & GPTJObject : : modelNameChanged , this , & LLM : : modelNameChanged , Qt : : QueuedConnection ) ;
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 ) ;
@ -145,6 +164,11 @@ void LLM::responseStopped()
emit responseInProgressChanged ( ) ;
emit responseInProgressChanged ( ) ;
}
}
QString LLM : : modelName ( ) const
{
return m_gptj - > modelName ( ) ;
}
bool LLM : : checkForUpdates ( ) const
bool LLM : : checkForUpdates ( ) const
{
{
# if defined(Q_OS_LINUX)
# if defined(Q_OS_LINUX)