llm-chat 0.0.0
LLM-Chat
All Classes Namespaces Files Functions Enumerations Enumerator Properties Pages
backend.h
Go to the documentation of this file.
1#pragma once
2
3#include <QNetworkAccessManager>
4#include <QObject>
5#include <QSettings>
6
7#include "thread.h"
8#include "thread_list.h"
9#include "thread_proxy_list.h"
10
11namespace llm_chat {
12
15class ChatBackend : public QObject {
16 Q_OBJECT
17 Q_PROPERTY(ThreadProxyList *sortedThreads READ threadProxyList CONSTANT FINAL)
18 Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
19 Q_PROPERTY(QStringList modelList READ modelList NOTIFY modelListFetched)
20 Q_PROPERTY(QString systemPrompt READ systemPrompt WRITE setSystemPrompt NOTIFY
22 Q_PROPERTY(QString ollamaServerUrl READ ollamaServerUrl WRITE
24
25 public:
28 explicit ChatBackend(QObject *parent = nullptr);
31 [[nodiscard]] ThreadList *threadList() const { return m_ThreadList.get(); }
34 [[nodiscard]] ThreadProxyList *threadProxyList() const {
35 return m_ThreadProxyList.get();
36 }
39 [[nodiscard]] QString model() const;
41 [[nodiscard]] QStringList modelList() const { return m_ModelList; }
44 [[nodiscard]] QString systemPrompt() const;
47 [[nodiscard]] QString ollamaServerUrl() const;
48
49 public Q_SLOTS:
54 void setModel(const QString &model);
56 void fetchModelList();
60 Thread *getThread(const int index);
63 void deleteThread(const int index);
65 void clearThreads();
68 void sendMessage(const int index, const QString &prompt);
71 void setSystemPrompt(const QString &prompt);
74 void setOllamaServerUrl(const QString &url);
77 void retryLatestMessage(const int index);
78
79 signals:
90
91 private:
92 QScopedPointer<QNetworkAccessManager> m_Manager{new QNetworkAccessManager};
93 QScopedPointer<ThreadList> m_ThreadList{new ThreadList};
94 QScopedPointer<ThreadProxyList> m_ThreadProxyList{new ThreadProxyList};
95 QList<QString> m_ModelList;
96 QSettings m_Settings;
97
100 void sendRequestToOllama(Thread *thread, const QString &prompt);
104 void handleStreamResponse(Thread *thread, QNetworkReply *reply) const;
105};
106
107} // namespace llm_chat
The ChatBackend class handles the communication with the Ollama server.
Definition backend.h:15
void newThreadCreated()
Emitted when the current thread is changed.
void setModel(const QString &model)
Sets the model name.
Definition backend.cpp:137
ThreadList * threadList() const
Returns the chat threads.
Definition backend.h:31
QStringList modelList
Definition backend.h:19
void ollamaServerUrlChanged()
Emitted when the ollama server url is changed.
void deleteThread(const int index)
Removes the thread at the given index.
Definition backend.cpp:169
void modelChanged()
Emitted when the model is changed.
ThreadProxyList * sortedThreads
Definition backend.h:17
ThreadProxyList * threadProxyList() const
Returns the sorted chat threads.
Definition backend.h:34
void setSystemPrompt(const QString &prompt)
Set the system prompt.
Definition backend.cpp:182
void systemPromptChanged()
Emitted when the system prompt is changed.
QString systemPrompt
Definition backend.h:21
void fetchModelList()
Fetches the list of available models from the Ollama server.
Definition backend.cpp:144
Thread * getThread(const int index)
Returns the thread at the given index.
Definition backend.cpp:162
void setOllamaServerUrl(const QString &url)
Set the ollama server url.
Definition backend.cpp:193
void sendMessage(const int index, const QString &prompt)
Sends a message to the Ollama server.
Definition backend.cpp:22
QString model
Definition backend.h:18
void clearThreads()
Removes all the threads.
Definition backend.cpp:176
void retryLatestMessage(const int index)
Retries the latest message.
Definition backend.cpp:201
QString ollamaServerUrl
Definition backend.h:23
void modelListFetched()
Emitted when the list of models is fetched.
QStringList modelList() const
Get the list of available models.
Definition backend.h:41
The ThreadList class provides a model for the chat threads.
Definition thread_list.h:10
The ThreadProxyList class provides a sorted model for the chat.
Definition thread_proxy_list.h:8
The Thread class provides a model for the chat interface.
Definition thread.h:13
Definition backend.cpp:11