general ui work
This commit is contained in:
49
backend.cpp
49
backend.cpp
@ -1,8 +1,11 @@
|
||||
#include "backend.h"
|
||||
#include "exllama.h"
|
||||
#include <qstringliteral.h>
|
||||
|
||||
AiBackend::Request::Request(const QString& textIn, void* userPtrIn):
|
||||
AiBackend::Request::Request(const QString& textIn, type_t typeIn, void* userPtrIn):
|
||||
text(textIn),
|
||||
userPtr(userPtrIn)
|
||||
userPtr(userPtrIn),
|
||||
type(typeIn)
|
||||
{
|
||||
id = idCounter++;
|
||||
}
|
||||
@ -27,13 +30,21 @@ bool AiBackend::Request::operator==(const Request& in)
|
||||
return id == in.id;
|
||||
}
|
||||
|
||||
AiBackend::Response::Response(QString textIn, uint32_t idIn, bool finishedIn, void* userPtrIn):
|
||||
AiBackend::Request::Request(textIn, userPtrIn),
|
||||
finished(finishedIn)
|
||||
AiBackend::Request::type_t AiBackend::Request::getType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
AiBackend::Response::Response(QString textIn, uint32_t idIn, bool finishedIn,
|
||||
AiBackend::Request::type_t type, int64_t tokensIn, void* userPtrIn):
|
||||
AiBackend::Request::Request(textIn, type, userPtrIn),
|
||||
finished(finishedIn),
|
||||
tokens(tokensIn)
|
||||
{
|
||||
id = idIn;
|
||||
}
|
||||
|
||||
|
||||
bool AiBackend::Response::isFinished() const
|
||||
{
|
||||
return finished;
|
||||
@ -44,10 +55,32 @@ void AiBackend::Response::setUserPtr(void* ptr)
|
||||
userPtr = ptr;
|
||||
}
|
||||
|
||||
void AiBackend::generate(const Request& request)
|
||||
std::vector<QString> AiBackend::getAvailableBackendNames()
|
||||
{
|
||||
m_requests.insert(request.getId(), request);
|
||||
generateImpl(request);
|
||||
return {QStringLiteral("KoboldAI"), ExLlama::backendNameStatic()};
|
||||
}
|
||||
|
||||
std::shared_ptr<AiBackend> AiBackend::createBackend(const QString& name)
|
||||
{
|
||||
if(name == QStringLiteral("KoboldAI"))
|
||||
return nullptr;
|
||||
if(name == ExLlama::backendNameStatic())
|
||||
return std::shared_ptr<ExLlama>(new ExLlama());
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AiBackend::generate(const Request& request)
|
||||
{
|
||||
if(request.getType() == Request::UNKOWN)
|
||||
return false;
|
||||
|
||||
bool ret = generateImpl(request);
|
||||
|
||||
if(ret)
|
||||
m_requests.insert(request.getId(), request);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AiBackend::isValidId(uint32_t id)
|
||||
|
Reference in New Issue
Block a user