Start working on more thread safety and model load error handling.

This commit is contained in:
Adam Treat
2023-06-19 19:51:28 -04:00
committed by AT
parent d5f56d3308
commit 7d2ce06029
6 changed files with 115 additions and 56 deletions

View File

@@ -100,9 +100,9 @@ public:
bool deserialize(QDataStream &stream, int version);
public Q_SLOTS:
bool prompt(const QString &prompt, const QString &prompt_template, int32_t n_predict,
int32_t top_k, float top_p, float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens,
int32_t n_threads);
bool prompt(const QList<QString> &collectionList, const QString &prompt, const QString &prompt_template,
int32_t n_predict, int32_t top_k, float top_p, float temp, int32_t n_batch, float repeat_penalty,
int32_t repeat_penalty_tokens, int32_t n_threads);
bool loadDefaultModel();
bool loadModel(const QString &modelName);
void modelNameChangeRequested(const QString &modelName);
@@ -110,7 +110,8 @@ public Q_SLOTS:
void unloadModel();
void reloadModel();
void generateName();
void handleChatIdChanged();
void handleChatIdChanged(const QString &id);
void handleDefaultModelChanged(const QString &defaultModel);
void handleShouldBeLoadedChanged();
void handleThreadStarted();
@@ -143,15 +144,24 @@ protected:
void restoreState();
protected:
// The following are all accessed by multiple threads and are thus guarded with thread protection
// mechanisms
LLModel::PromptContext m_ctx;
quint32 m_promptTokens;
quint32 m_promptResponseTokens;
LLModelInfo m_modelInfo;
LLModelType m_modelType;
private:
// The following are all accessed by multiple threads and are thus guarded with thread protection
// mechanisms
std::string m_response;
std::string m_nameResponse;
LLModelInfo m_modelInfo;
LLModelType m_modelType;
QString m_modelName;
Chat *m_chat;
bool m_isChatGPT;
// The following are only accessed by this thread
QString m_defaultModel;
TokenTimer *m_timer;
QByteArray m_state;
QThread m_llmThread;
@@ -159,7 +169,6 @@ protected:
std::atomic<bool> m_shouldBeLoaded;
std::atomic<bool> m_isRecalc;
bool m_isServer;
bool m_isChatGPT;
};
#endif // CHATLLM_H