2023-06-22 15:44:49 -04:00
# ifndef MODELLIST_H
# define MODELLIST_H
# include <QAbstractListModel>
2024-06-04 14:47:11 -04:00
# include <QByteArray>
# include <QDateTime>
# include <QHash>
# include <QList>
# include <QMutex>
# include <QNetworkAccessManager>
# include <QNetworkReply>
# include <QObject>
# include <QPair>
# include <QSortFilterProxyModel>
2024-06-06 11:59:28 -04:00
# include <QSslError>
2024-06-04 14:47:11 -04:00
# include <QString>
2024-06-06 11:59:28 -04:00
# include <QVariant>
# include <QVector>
2024-06-04 14:47:11 -04:00
# include <Qt>
# include <QtGlobal>
2023-06-22 15:44:49 -04:00
# include <QtQml>
2024-06-24 18:49:23 -04:00
using namespace Qt : : Literals : : StringLiterals ;
2023-06-22 15:44:49 -04:00
struct ModelInfo {
Q_GADGET
2023-07-01 11:34:21 -04:00
Q_PROPERTY ( QString id READ id WRITE setId )
Q_PROPERTY ( QString name READ name WRITE setName )
Q_PROPERTY ( QString filename READ filename WRITE setFilename )
2023-06-22 15:44:49 -04:00
Q_PROPERTY ( QString dirpath MEMBER dirpath )
Q_PROPERTY ( QString filesize MEMBER filesize )
2024-03-05 11:31:31 -05:00
Q_PROPERTY ( QByteArray hash MEMBER hash )
Q_PROPERTY ( HashAlgorithm hashAlgorithm MEMBER hashAlgorithm )
2023-06-22 15:44:49 -04:00
Q_PROPERTY ( bool calcHash MEMBER calcHash )
Q_PROPERTY ( bool installed MEMBER installed )
Q_PROPERTY ( bool isDefault MEMBER isDefault )
2024-01-22 12:36:01 -05:00
Q_PROPERTY ( bool isOnline MEMBER isOnline )
2024-07-25 10:02:52 -04:00
Q_PROPERTY ( bool isCompatibleApi MEMBER isCompatibleApi )
2024-03-05 11:31:31 -05:00
Q_PROPERTY ( QString description READ description WRITE setDescription )
2023-06-22 15:44:49 -04:00
Q_PROPERTY ( QString requiresVersion MEMBER requiresVersion )
2024-03-06 14:12:21 -05:00
Q_PROPERTY ( QString versionRemoved MEMBER versionRemoved )
2024-03-05 11:31:31 -05:00
Q_PROPERTY ( QString url READ url WRITE setUrl )
2023-06-22 15:44:49 -04:00
Q_PROPERTY ( qint64 bytesReceived MEMBER bytesReceived )
Q_PROPERTY ( qint64 bytesTotal MEMBER bytesTotal )
Q_PROPERTY ( qint64 timestamp MEMBER timestamp )
Q_PROPERTY ( QString speed MEMBER speed )
Q_PROPERTY ( bool isDownloading MEMBER isDownloading )
Q_PROPERTY ( bool isIncomplete MEMBER isIncomplete )
Q_PROPERTY ( QString downloadError MEMBER downloadError )
Q_PROPERTY ( QString order MEMBER order )
Q_PROPERTY ( int ramrequired MEMBER ramrequired )
Q_PROPERTY ( QString parameters MEMBER parameters )
2024-03-05 11:31:31 -05:00
Q_PROPERTY ( QString quant READ quant WRITE setQuant )
Q_PROPERTY ( QString type READ type WRITE setType )
Q_PROPERTY ( bool isClone READ isClone WRITE setIsClone )
Q_PROPERTY ( bool isDiscovered READ isDiscovered WRITE setIsDiscovered )
2024-03-13 18:09:24 -04:00
Q_PROPERTY ( bool isEmbeddingModel MEMBER isEmbeddingModel )
2023-07-01 11:34:21 -04:00
Q_PROPERTY ( double temperature READ temperature WRITE setTemperature )
Q_PROPERTY ( double topP READ topP WRITE setTopP )
2024-02-24 17:51:34 -05:00
Q_PROPERTY ( double minP READ minP WRITE setMinP )
2023-07-01 11:34:21 -04:00
Q_PROPERTY ( int topK READ topK WRITE setTopK )
Q_PROPERTY ( int maxLength READ maxLength WRITE setMaxLength )
Q_PROPERTY ( int promptBatchSize READ promptBatchSize WRITE setPromptBatchSize )
2023-12-16 17:58:15 -05:00
Q_PROPERTY ( int contextLength READ contextLength WRITE setContextLength )
2024-01-31 14:17:44 -05:00
Q_PROPERTY ( int maxContextLength READ maxContextLength )
Q_PROPERTY ( int gpuLayers READ gpuLayers WRITE setGpuLayers )
Q_PROPERTY ( int maxGpuLayers READ maxGpuLayers )
2023-07-01 11:34:21 -04:00
Q_PROPERTY ( double repeatPenalty READ repeatPenalty WRITE setRepeatPenalty )
Q_PROPERTY ( int repeatPenaltyTokens READ repeatPenaltyTokens WRITE setRepeatPenaltyTokens )
Q_PROPERTY ( QString promptTemplate READ promptTemplate WRITE setPromptTemplate )
Q_PROPERTY ( QString systemPrompt READ systemPrompt WRITE setSystemPrompt )
2024-07-10 15:45:20 -04:00
Q_PROPERTY ( QString chatNamePrompt READ chatNamePrompt WRITE setChatNamePrompt )
Q_PROPERTY ( QString suggestedFollowUpPrompt READ suggestedFollowUpPrompt WRITE setSuggestedFollowUpPrompt )
2024-03-05 11:31:31 -05:00
Q_PROPERTY ( int likes READ likes WRITE setLikes )
Q_PROPERTY ( int downloads READ downloads WRITE setDownloads )
Q_PROPERTY ( QDateTime recency READ recency WRITE setRecency )
2023-06-22 15:44:49 -04:00
public :
2024-03-05 11:31:31 -05:00
enum HashAlgorithm {
Md5 ,
Sha256
} ;
2023-07-01 11:34:21 -04:00
QString id ( ) const ;
void setId ( const QString & id ) ;
QString name ( ) const ;
void setName ( const QString & name ) ;
QString filename ( ) const ;
void setFilename ( const QString & name ) ;
2024-03-05 11:31:31 -05:00
QString description ( ) const ;
void setDescription ( const QString & d ) ;
QString url ( ) const ;
void setUrl ( const QString & u ) ;
QString quant ( ) const ;
void setQuant ( const QString & q ) ;
QString type ( ) const ;
void setType ( const QString & t ) ;
bool isClone ( ) const ;
void setIsClone ( bool b ) ;
bool isDiscovered ( ) const ;
void setIsDiscovered ( bool b ) ;
int likes ( ) const ;
void setLikes ( int l ) ;
int downloads ( ) const ;
void setDownloads ( int d ) ;
QDateTime recency ( ) const ;
void setRecency ( const QDateTime & r ) ;
2023-06-22 15:44:49 -04:00
QString dirpath ;
QString filesize ;
2024-03-05 11:31:31 -05:00
QByteArray hash ;
HashAlgorithm hashAlgorithm ;
2023-06-22 15:44:49 -04:00
bool calcHash = false ;
bool installed = false ;
bool isDefault = false ;
2024-07-25 10:02:52 -04:00
// Differences between 'isOnline' and 'isCompatibleApi' in ModelInfo:
// 'isOnline':
// - Indicates whether this is a online model.
// - Linked with the ModelList, fetching info from it.
2024-01-22 12:36:01 -05:00
bool isOnline = false ;
2024-07-25 10:02:52 -04:00
// 'isCompatibleApi':
// - Indicates whether the model is using the OpenAI-compatible API which user custom.
// - When the property is true, 'isOnline' should also be true.
// - Does not link to the ModelList directly; instead, fetches info from the *-capi.rmodel file and works standalone.
// - Still needs to copy data from gpt4all.ini and *-capi.rmodel to the ModelList in memory while application getting started(as custom .gguf models do).
bool isCompatibleApi = false ;
2023-06-22 15:44:49 -04:00
QString requiresVersion ;
2024-03-06 14:12:21 -05:00
QString versionRemoved ;
2023-06-22 15:44:49 -04:00
qint64 bytesReceived = 0 ;
qint64 bytesTotal = 0 ;
qint64 timestamp = 0 ;
QString speed ;
bool isDownloading = false ;
bool isIncomplete = false ;
QString downloadError ;
QString order ;
2024-03-05 11:31:31 -05:00
int ramrequired = - 1 ;
2023-06-22 15:44:49 -04:00
QString parameters ;
2024-03-13 18:09:24 -04:00
bool isEmbeddingModel = false ;
bool checkedEmbeddingModel = false ;
2023-07-01 11:34:21 -04:00
2023-06-22 15:44:49 -04:00
bool operator = = ( const ModelInfo & other ) const {
2023-07-01 11:34:21 -04:00
return m_id = = other . m_id ;
2023-06-22 15:44:49 -04:00
}
2023-07-01 11:34:21 -04:00
double temperature ( ) const ;
void setTemperature ( double t ) ;
double topP ( ) const ;
void setTopP ( double p ) ;
2024-02-24 17:51:34 -05:00
double minP ( ) const ;
void setMinP ( double p ) ;
2023-07-01 11:34:21 -04:00
int topK ( ) const ;
void setTopK ( int k ) ;
int maxLength ( ) const ;
void setMaxLength ( int l ) ;
int promptBatchSize ( ) const ;
void setPromptBatchSize ( int s ) ;
2023-12-16 17:58:15 -05:00
int contextLength ( ) const ;
void setContextLength ( int l ) ;
2024-01-31 14:17:44 -05:00
int maxContextLength ( ) const ;
int gpuLayers ( ) const ;
void setGpuLayers ( int l ) ;
int maxGpuLayers ( ) const ;
2023-07-01 11:34:21 -04:00
double repeatPenalty ( ) const ;
void setRepeatPenalty ( double p ) ;
int repeatPenaltyTokens ( ) const ;
void setRepeatPenaltyTokens ( int t ) ;
QString promptTemplate ( ) const ;
void setPromptTemplate ( const QString & t ) ;
QString systemPrompt ( ) const ;
void setSystemPrompt ( const QString & p ) ;
2024-07-10 15:45:20 -04:00
QString chatNamePrompt ( ) const ;
void setChatNamePrompt ( const QString & p ) ;
QString suggestedFollowUpPrompt ( ) const ;
void setSuggestedFollowUpPrompt ( const QString & p ) ;
2023-07-01 11:34:21 -04:00
2024-03-05 11:31:31 -05:00
bool shouldSaveMetadata ( ) const ;
2023-07-01 11:34:21 -04:00
private :
2024-06-24 18:49:23 -04:00
QVariantMap getFields ( ) const ;
2023-07-01 11:34:21 -04:00
QString m_id ;
QString m_name ;
QString m_filename ;
2024-03-05 11:31:31 -05:00
QString m_description ;
QString m_url ;
QString m_quant ;
QString m_type ;
2024-07-10 15:45:20 -04:00
bool m_isClone = false ;
bool m_isDiscovered = false ;
int m_likes = - 1 ;
int m_downloads = - 1 ;
2024-03-05 11:31:31 -05:00
QDateTime m_recency ;
2024-07-10 15:45:20 -04:00
double m_temperature = 0.7 ;
double m_topP = 0.4 ;
double m_minP = 0.0 ;
int m_topK = 40 ;
int m_maxLength = 4096 ;
int m_promptBatchSize = 128 ;
int m_contextLength = 2048 ;
mutable int m_maxContextLength = - 1 ;
int m_gpuLayers = 100 ;
mutable int m_maxGpuLayers = - 1 ;
double m_repeatPenalty = 1.18 ;
int m_repeatPenaltyTokens = 64 ;
QString m_promptTemplate = " ### Human: \n %1 \n \n ### Assistant: \n " ;
QString m_systemPrompt = " ### System: \n You are an AI assistant who gives a quality response to whatever humans ask of you. \n \n " ;
QString m_chatNamePrompt = " Describe the above conversation in seven words or less. " ;
QString m_suggestedFollowUpPrompt = " Suggest three very short factual follow-up questions that have not been answered yet or cannot be found inspired by the previous conversation and excerpts. " ;
2023-07-01 11:34:21 -04:00
friend class MySettings ;
2023-06-22 15:44:49 -04:00
} ;
Q_DECLARE_METATYPE ( ModelInfo )
class InstalledModels : public QSortFilterProxyModel
{
Q_OBJECT
2023-06-26 09:35:29 -04:00
Q_PROPERTY ( int count READ count NOTIFY countChanged )
2023-06-22 15:44:49 -04:00
public :
2024-06-28 20:34:03 -04:00
explicit InstalledModels ( QObject * parent , bool selectable = false ) ;
2024-03-13 18:09:24 -04:00
int count ( ) const { return rowCount ( ) ; }
2023-06-26 09:35:29 -04:00
Q_SIGNALS :
void countChanged ( ) ;
2023-06-22 15:44:49 -04:00
protected :
bool filterAcceptsRow ( int sourceRow , const QModelIndex & sourceParent ) const override ;
2024-06-28 20:34:03 -04:00
private :
bool m_selectable ;
2023-06-22 15:44:49 -04:00
} ;
class DownloadableModels : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY ( int count READ count NOTIFY countChanged )
Q_PROPERTY ( bool expanded READ isExpanded WRITE setExpanded NOTIFY expandedChanged )
public :
explicit DownloadableModels ( QObject * parent ) ;
int count ( ) const ;
bool isExpanded ( ) const ;
void setExpanded ( bool expanded ) ;
2024-03-05 11:31:31 -05:00
Q_INVOKABLE void discoverAndFilter ( const QString & discover ) ;
2023-06-22 15:44:49 -04:00
Q_SIGNALS :
void countChanged ( ) ;
protected :
bool filterAcceptsRow ( int sourceRow , const QModelIndex & sourceParent ) const override ;
Q_SIGNALS :
void expandedChanged ( bool expanded ) ;
private :
bool m_expanded ;
int m_limit ;
2024-03-05 11:31:31 -05:00
QString m_discoverFilter ;
2023-06-22 15:44:49 -04:00
} ;
class ModelList : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY ( int count READ count NOTIFY countChanged )
Q_PROPERTY ( InstalledModels * installedModels READ installedModels NOTIFY installedModelsChanged )
2024-06-28 20:34:03 -04:00
Q_PROPERTY ( InstalledModels * selectableModels READ selectableModels NOTIFY selectableModelsChanged )
2023-06-22 15:44:49 -04:00
Q_PROPERTY ( DownloadableModels * downloadableModels READ downloadableModels NOTIFY downloadableModelsChanged )
2024-07-19 14:28:54 -04:00
Q_PROPERTY ( QList < ModelInfo > selectableModelList READ selectableModelList NOTIFY selectableModelListChanged )
2023-07-12 11:46:40 -04:00
Q_PROPERTY ( bool asyncModelRequestOngoing READ asyncModelRequestOngoing NOTIFY asyncModelRequestOngoingChanged )
2024-03-05 11:31:31 -05:00
Q_PROPERTY ( int discoverLimit READ discoverLimit WRITE setDiscoverLimit NOTIFY discoverLimitChanged )
Q_PROPERTY ( int discoverSortDirection READ discoverSortDirection WRITE setDiscoverSortDirection NOTIFY discoverSortDirectionChanged )
Q_PROPERTY ( DiscoverSort discoverSort READ discoverSort WRITE setDiscoverSort NOTIFY discoverSortChanged )
Q_PROPERTY ( float discoverProgress READ discoverProgress NOTIFY discoverProgressChanged )
Q_PROPERTY ( bool discoverInProgress READ discoverInProgress NOTIFY discoverInProgressChanged )
2023-06-22 15:44:49 -04:00
public :
static ModelList * globalInstance ( ) ;
2024-07-25 10:02:52 -04:00
static QString compatibleModelNameHash ( QUrl baseUrl , QString modelName ) ;
static QString compatibleModelFilename ( QUrl baseUrl , QString modelName ) ;
2024-03-05 11:31:31 -05:00
enum DiscoverSort {
Default ,
Likes ,
Downloads ,
Recent
} ;
2023-06-22 15:44:49 -04:00
enum Roles {
2023-07-01 11:34:21 -04:00
IdRole = Qt : : UserRole + 1 ,
NameRole ,
2023-06-22 15:44:49 -04:00
FilenameRole ,
DirpathRole ,
FilesizeRole ,
2024-03-05 11:31:31 -05:00
HashRole ,
HashAlgorithmRole ,
2023-06-22 15:44:49 -04:00
CalcHashRole ,
InstalledRole ,
DefaultRole ,
2024-01-22 12:36:01 -05:00
OnlineRole ,
2024-07-25 10:02:52 -04:00
CompatibleApiRole ,
2023-06-22 15:44:49 -04:00
DescriptionRole ,
RequiresVersionRole ,
2024-03-06 14:12:21 -05:00
VersionRemovedRole ,
2023-06-22 15:44:49 -04:00
UrlRole ,
BytesReceivedRole ,
BytesTotalRole ,
TimestampRole ,
SpeedRole ,
DownloadingRole ,
IncompleteRole ,
DownloadErrorRole ,
OrderRole ,
RamrequiredRole ,
ParametersRole ,
QuantRole ,
2023-07-01 11:34:21 -04:00
TypeRole ,
IsCloneRole ,
2024-03-05 11:31:31 -05:00
IsDiscoveredRole ,
2024-03-13 18:09:24 -04:00
IsEmbeddingModelRole ,
2023-07-01 11:34:21 -04:00
TemperatureRole ,
TopPRole ,
TopKRole ,
MaxLengthRole ,
PromptBatchSizeRole ,
2023-12-16 17:58:15 -05:00
ContextLengthRole ,
2024-01-31 14:17:44 -05:00
GpuLayersRole ,
2023-07-01 11:34:21 -04:00
RepeatPenaltyRole ,
RepeatPenaltyTokensRole ,
PromptTemplateRole ,
SystemPromptRole ,
2024-07-10 15:45:20 -04:00
ChatNamePromptRole ,
SuggestedFollowUpPromptRole ,
2024-02-24 17:51:34 -05:00
MinPRole ,
2024-03-05 11:31:31 -05:00
LikesRole ,
DownloadsRole ,
RecencyRole
2023-06-22 15:44:49 -04:00
} ;
QHash < int , QByteArray > roleNames ( ) const override
{
QHash < int , QByteArray > roles ;
2023-07-01 11:34:21 -04:00
roles [ IdRole ] = " id " ;
2023-06-22 15:44:49 -04:00
roles [ NameRole ] = " name " ;
roles [ FilenameRole ] = " filename " ;
roles [ DirpathRole ] = " dirpath " ;
roles [ FilesizeRole ] = " filesize " ;
2024-03-05 11:31:31 -05:00
roles [ HashRole ] = " hash " ;
roles [ HashAlgorithmRole ] = " hashAlgorithm " ;
2023-06-22 15:44:49 -04:00
roles [ CalcHashRole ] = " calcHash " ;
roles [ InstalledRole ] = " installed " ;
roles [ DefaultRole ] = " isDefault " ;
2024-01-22 12:36:01 -05:00
roles [ OnlineRole ] = " isOnline " ;
2024-07-25 10:02:52 -04:00
roles [ CompatibleApiRole ] = " isCompatibleApi " ;
2023-06-22 15:44:49 -04:00
roles [ DescriptionRole ] = " description " ;
roles [ RequiresVersionRole ] = " requiresVersion " ;
2024-03-06 14:12:21 -05:00
roles [ VersionRemovedRole ] = " versionRemoved " ;
2023-06-22 15:44:49 -04:00
roles [ UrlRole ] = " url " ;
roles [ BytesReceivedRole ] = " bytesReceived " ;
roles [ BytesTotalRole ] = " bytesTotal " ;
roles [ TimestampRole ] = " timestamp " ;
roles [ SpeedRole ] = " speed " ;
roles [ DownloadingRole ] = " isDownloading " ;
roles [ IncompleteRole ] = " isIncomplete " ;
roles [ DownloadErrorRole ] = " downloadError " ;
roles [ OrderRole ] = " order " ;
roles [ RamrequiredRole ] = " ramrequired " ;
roles [ ParametersRole ] = " parameters " ;
roles [ QuantRole ] = " quant " ;
roles [ TypeRole ] = " type " ;
2023-07-01 11:34:21 -04:00
roles [ IsCloneRole ] = " isClone " ;
2024-03-05 11:31:31 -05:00
roles [ IsDiscoveredRole ] = " isDiscovered " ;
2024-03-13 18:09:24 -04:00
roles [ IsEmbeddingModelRole ] = " isEmbeddingModel " ;
2023-07-01 11:34:21 -04:00
roles [ TemperatureRole ] = " temperature " ;
roles [ TopPRole ] = " topP " ;
2024-02-24 17:51:34 -05:00
roles [ MinPRole ] = " minP " ;
2023-07-01 11:34:21 -04:00
roles [ TopKRole ] = " topK " ;
roles [ MaxLengthRole ] = " maxLength " ;
roles [ PromptBatchSizeRole ] = " promptBatchSize " ;
2023-12-16 17:58:15 -05:00
roles [ ContextLengthRole ] = " contextLength " ;
2024-01-31 14:17:44 -05:00
roles [ GpuLayersRole ] = " gpuLayers " ;
2023-07-01 11:34:21 -04:00
roles [ RepeatPenaltyRole ] = " repeatPenalty " ;
roles [ RepeatPenaltyTokensRole ] = " repeatPenaltyTokens " ;
roles [ PromptTemplateRole ] = " promptTemplate " ;
roles [ SystemPromptRole ] = " systemPrompt " ;
2024-07-10 15:45:20 -04:00
roles [ ChatNamePromptRole ] = " chatNamePrompt " ;
roles [ SuggestedFollowUpPromptRole ] = " suggestedFollowUpPrompt " ;
2024-03-05 11:31:31 -05:00
roles [ LikesRole ] = " likes " ;
roles [ DownloadsRole ] = " downloads " ;
roles [ RecencyRole ] = " recency " ;
2023-06-22 15:44:49 -04:00
return roles ;
}
int rowCount ( const QModelIndex & parent = QModelIndex ( ) ) const override ;
QVariant data ( const QModelIndex & index , int role = Qt : : DisplayRole ) const override ;
2023-07-01 11:34:21 -04:00
QVariant data ( const QString & id , int role ) const ;
2023-07-05 20:12:37 -04:00
QVariant dataByFilename ( const QString & filename , int role ) const ;
2024-03-13 18:09:24 -04:00
void updateDataByFilename ( const QString & filename , QVector < QPair < int , QVariant > > data ) ;
2024-03-05 11:31:31 -05:00
void updateData ( const QString & id , const QVector < QPair < int , QVariant > > & data ) ;
2023-06-22 15:44:49 -04:00
int count ( ) const { return m_models . size ( ) ; }
2023-07-01 11:34:21 -04:00
bool contains ( const QString & id ) const ;
bool containsByFilename ( const QString & filename ) const ;
Q_INVOKABLE ModelInfo modelInfo ( const QString & id ) const ;
Q_INVOKABLE ModelInfo modelInfoByFilename ( const QString & filename ) const ;
Q_INVOKABLE bool isUniqueName ( const QString & name ) const ;
Q_INVOKABLE QString clone ( const ModelInfo & model ) ;
2024-03-05 11:31:31 -05:00
Q_INVOKABLE void removeClone ( const ModelInfo & model ) ;
Q_INVOKABLE void removeInstalled ( const ModelInfo & model ) ;
2023-06-22 15:44:49 -04:00
ModelInfo defaultModelInfo ( ) const ;
2023-07-01 11:34:21 -04:00
void addModel ( const QString & id ) ;
2023-07-10 16:14:57 -04:00
void changeId ( const QString & oldId , const QString & newId ) ;
2023-06-22 15:44:49 -04:00
2024-07-19 14:28:54 -04:00
const QList < ModelInfo > selectableModelList ( ) const ;
2023-06-22 15:44:49 -04:00
InstalledModels * installedModels ( ) const { return m_installedModels ; }
2024-06-28 20:34:03 -04:00
InstalledModels * selectableModels ( ) const { return m_selectableModels ; }
2023-06-22 15:44:49 -04:00
DownloadableModels * downloadableModels ( ) const { return m_downloadableModels ; }
static inline QString toFileSize ( quint64 sz ) {
if ( sz < 1024 ) {
2024-06-24 18:49:23 -04:00
return u " %1 bytes " _s . arg ( sz ) ;
2023-06-22 15:44:49 -04:00
} else if ( sz < 1024 * 1024 ) {
2024-06-24 18:49:23 -04:00
return u " %1 KB " _s . arg ( qreal ( sz ) / 1024 , 0 , ' g ' , 3 ) ;
2023-06-22 15:44:49 -04:00
} else if ( sz < 1024 * 1024 * 1024 ) {
2024-06-24 18:49:23 -04:00
return u " %1 MB " _s . arg ( qreal ( sz ) / ( 1024 * 1024 ) , 0 , ' g ' , 3 ) ;
2023-06-22 15:44:49 -04:00
} else {
2024-06-24 18:49:23 -04:00
return u " %1 GB " _s . arg ( qreal ( sz ) / ( 1024 * 1024 * 1024 ) , 0 , ' g ' , 3 ) ;
2023-06-22 15:44:49 -04:00
}
}
QString incompleteDownloadPath ( const QString & modelFile ) ;
2023-07-12 11:46:40 -04:00
bool asyncModelRequestOngoing ( ) const { return m_asyncModelRequestOngoing ; }
2023-06-22 15:44:49 -04:00
2023-11-17 13:27:17 -05:00
void updateModelsFromDirectory ( ) ;
2024-03-05 11:31:31 -05:00
void updateDiscoveredInstalled ( const ModelInfo & info ) ;
int discoverLimit ( ) const ;
void setDiscoverLimit ( int limit ) ;
int discoverSortDirection ( ) const ;
void setDiscoverSortDirection ( int direction ) ; // -1 or 1
DiscoverSort discoverSort ( ) const ;
void setDiscoverSort ( DiscoverSort sort ) ;
float discoverProgress ( ) const ;
bool discoverInProgress ( ) const ;
Q_INVOKABLE void discoverSearch ( const QString & discover ) ;
2023-11-17 13:27:17 -05:00
2023-06-22 15:44:49 -04:00
Q_SIGNALS :
void countChanged ( ) ;
void installedModelsChanged ( ) ;
2024-06-28 20:34:03 -04:00
void selectableModelsChanged ( ) ;
2023-06-22 15:44:49 -04:00
void downloadableModelsChanged ( ) ;
2024-07-19 14:28:54 -04:00
void selectableModelListChanged ( ) ;
2023-07-12 11:46:40 -04:00
void asyncModelRequestOngoingChanged ( ) ;
2024-03-05 11:31:31 -05:00
void discoverLimitChanged ( ) ;
void discoverSortDirectionChanged ( ) ;
void discoverSortChanged ( ) ;
void discoverProgressChanged ( ) ;
void discoverInProgressChanged ( ) ;
2023-06-22 15:44:49 -04:00
2024-07-12 16:15:40 -04:00
protected :
bool eventFilter ( QObject * obj , QEvent * ev ) override ;
2023-06-22 15:44:49 -04:00
private Q_SLOTS :
2024-03-05 11:31:31 -05:00
void resortModel ( ) ;
2023-07-01 11:34:21 -04:00
void updateModelsFromJson ( ) ;
2023-07-10 16:14:57 -04:00
void updateModelsFromJsonAsync ( ) ;
2023-07-01 11:34:21 -04:00
void updateModelsFromSettings ( ) ;
void updateDataForSettings ( ) ;
2023-07-10 16:14:57 -04:00
void handleModelsJsonDownloadFinished ( ) ;
2023-07-12 11:46:40 -04:00
void handleModelsJsonDownloadErrorOccurred ( QNetworkReply : : NetworkError code ) ;
2024-03-05 11:31:31 -05:00
void handleDiscoveryFinished ( ) ;
void handleDiscoveryErrorOccurred ( QNetworkReply : : NetworkError code ) ;
void handleDiscoveryItemFinished ( ) ;
void handleDiscoveryItemErrorOccurred ( QNetworkReply : : NetworkError code ) ;
2023-07-10 16:14:57 -04:00
void handleSslErrors ( QNetworkReply * reply , const QList < QSslError > & errors ) ;
2023-06-22 15:44:49 -04:00
private :
2024-03-05 11:31:31 -05:00
void removeInternal ( const ModelInfo & model ) ;
void clearDiscoveredModels ( ) ;
2024-03-09 10:03:31 -05:00
bool modelExists ( const QString & fileName ) const ;
2023-06-22 15:44:49 -04:00
int indexForModel ( ModelInfo * model ) ;
QVariant dataInternal ( const ModelInfo * info , int role ) const ;
2024-03-05 11:31:31 -05:00
static bool lessThan ( const ModelInfo * a , const ModelInfo * b , DiscoverSort s , int d ) ;
2023-07-10 16:14:57 -04:00
void parseModelsJsonFile ( const QByteArray & jsonData , bool save ) ;
2024-03-05 11:31:31 -05:00
void parseDiscoveryJsonFile ( const QByteArray & jsonData ) ;
2023-07-01 11:34:21 -04:00
QString uniqueModelName ( const ModelInfo & model ) const ;
2023-06-22 15:44:49 -04:00
private :
2023-06-25 20:22:38 -04:00
mutable QMutex m_mutex ;
2023-06-28 11:13:33 -04:00
QNetworkAccessManager m_networkManager ;
2023-06-22 15:44:49 -04:00
InstalledModels * m_installedModels ;
2024-06-28 20:34:03 -04:00
InstalledModels * m_selectableModels ;
2023-06-22 15:44:49 -04:00
DownloadableModels * m_downloadableModels ;
QList < ModelInfo * > m_models ;
QHash < QString , ModelInfo * > m_modelMap ;
2023-07-12 11:46:40 -04:00
bool m_asyncModelRequestOngoing ;
2024-03-05 11:31:31 -05:00
int m_discoverLimit ;
int m_discoverSortDirection ;
DiscoverSort m_discoverSort ;
int m_discoverNumberOfResults ;
int m_discoverResultsCompleted ;
bool m_discoverInProgress ;
2023-06-22 15:44:49 -04:00
2024-03-05 11:31:31 -05:00
protected :
2023-06-22 15:44:49 -04:00
explicit ModelList ( ) ;
2024-03-13 18:09:24 -04:00
~ ModelList ( ) { for ( auto * model : m_models ) { delete model ; } }
2023-06-22 15:44:49 -04:00
friend class MyModelList ;
} ;
# endif // MODELLIST_H