This repository was archived by the owner on Aug 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.cpp
More file actions
58 lines (52 loc) · 1.25 KB
/
Copy pathprocessor.cpp
File metadata and controls
58 lines (52 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <QFile>
#include "processor.h"
class Processor::InternalData
{
public:
bool chat_init_status = false;
session_env_t env;
};
Processor::Processor(QObject *parent) : QObject(parent)
{
Q_UNUSED(parent)
qRegisterMetaType<gpt_params>();
m_data = QSharedPointer<InternalData>(new InternalData());
}
void Processor::handleLoadModel(const gpt_params ¶ms)
{
bool success = ::load_model(&m_data->env,params,updateLoadProgress,this);
if(success)
{
emit modelLoadSuccessed();
}
else
{
emit modelLoadFailed("Failed to OpenFile");
}
}
void Processor::handleUnloadModel()
{
::unload_model(&m_data->env);
emit modelUnloaded();
}
void Processor::handleEvalToken(const QString &prompt)
{
emit tokenRemaining();
if(!m_data->chat_init_status)
{
::init_chat_env(&m_data->env);
m_data->chat_init_status=true;
}
::init_user_input(&m_data->env, prompt);
while(::should_generate(&m_data->env))
{
QString result = ::generate_token(&m_data->env);
emit tokenSampled(result);
}
emit tokenConsumed();
}
void Processor::updateLoadProgress(float progress, void *ctx)
{
Processor* ctx_ = (Processor*)ctx;
emit ctx_->modelLoading(100*progress);
}