mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-04-06 04:42:44 -04:00
refactor: Add external LLMCore lib (#334)
* feat: Add LLMCore submodule
This commit is contained in:
@ -17,6 +17,8 @@ target_link_libraries(QodeAssistTest PRIVATE
|
||||
GTest::Main
|
||||
QtCreator::LanguageClient
|
||||
Context
|
||||
PluginLLMCore
|
||||
LLMCore
|
||||
)
|
||||
|
||||
target_compile_definitions(QodeAssistTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
@ -24,6 +24,19 @@
|
||||
#include <QSharedPointer>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace QodeAssist::PluginLLMCore {
|
||||
|
||||
void PrintTo(const ContextData &data, std::ostream *os)
|
||||
{
|
||||
*os << "ContextData{prefix="
|
||||
<< (data.prefix ? data.prefix->toStdString() : "<nullopt>")
|
||||
<< ", suffix=" << (data.suffix ? data.suffix->toStdString() : "<nullopt>")
|
||||
<< ", fileContext=" << (data.fileContext ? data.fileContext->toStdString() : "<nullopt>")
|
||||
<< "}";
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::PluginLLMCore
|
||||
|
||||
using namespace QodeAssist::Context;
|
||||
using namespace QodeAssist::LLMCore;
|
||||
using namespace QodeAssist::Settings;
|
||||
@ -369,7 +382,7 @@ TEST_F(DocumentContextReaderTest, testPrepareContext)
|
||||
|
||||
EXPECT_EQ(
|
||||
reader.prepareContext(2, 3, *createSettingsForWholeFile()),
|
||||
(ContextData{
|
||||
(QodeAssist::PluginLLMCore::ContextData{
|
||||
.prefix = "Line 0\nLine 1\nLin",
|
||||
.suffix = "e 2\nLine 3\nLine 4",
|
||||
.fileContext = "\n Language: (MIME: text/python) filepath: /path/to/file()\n\n"
|
||||
@ -377,7 +390,7 @@ TEST_F(DocumentContextReaderTest, testPrepareContext)
|
||||
|
||||
EXPECT_EQ(
|
||||
reader.prepareContext(2, 3, *createSettingsForLines(1, 1)),
|
||||
(ContextData{
|
||||
(QodeAssist::PluginLLMCore::ContextData{
|
||||
.prefix = "Line 1\nLin",
|
||||
.suffix = "e 2\nLine 3",
|
||||
.fileContext = "\n Language: (MIME: text/python) filepath: /path/to/file()\n\n"
|
||||
@ -385,7 +398,7 @@ TEST_F(DocumentContextReaderTest, testPrepareContext)
|
||||
|
||||
EXPECT_EQ(
|
||||
reader.prepareContext(2, 3, *createSettingsForLines(2, 2)),
|
||||
(ContextData{
|
||||
(QodeAssist::PluginLLMCore::ContextData{
|
||||
.prefix = "Line 0\nLine 1\nLin",
|
||||
.suffix = "e 2\nLine 3\nLine 4",
|
||||
.fileContext = "\n Language: (MIME: text/python) filepath: /path/to/file()\n\n"
|
||||
|
||||
@ -62,8 +62,6 @@ public:
|
||||
QString url() const override { return "https://mock_url"; }
|
||||
QString completionEndpoint() const override { return "/v1/completions"; }
|
||||
QString chatEndpoint() const override { return "/v1/chat/completions"; }
|
||||
bool supportsModelListing() const override { return false; }
|
||||
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *promptTemplate,
|
||||
@ -85,14 +83,6 @@ public:
|
||||
return QtFuture::makeReadyFuture(QList<QString>{});
|
||||
}
|
||||
|
||||
QStringList validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType templateType) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
QString apiKey() const override { return "mock_api_key"; }
|
||||
void prepareNetworkRequest(QNetworkRequest &request) const override {}
|
||||
LLMCore::ProviderID providerID() const override { return LLMCore::ProviderID::OpenAI; }
|
||||
};
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <llmcore/ContextData.hpp>
|
||||
#include <pluginllmcore/ContextData.hpp>
|
||||
#include <QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -61,14 +61,14 @@ std::ostream &operator<<(std::ostream &out, const std::optional<T> &value)
|
||||
|
||||
namespace QodeAssist::LLMCore {
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &out, const Message &value)
|
||||
inline std::ostream &operator<<(std::ostream &out, const PluginLLMCore::Message &value)
|
||||
{
|
||||
out << "Message{"
|
||||
<< "role=" << value.role << "content=" << value.content << "}";
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &out, const ContextData &value)
|
||||
inline std::ostream &operator<<(std::ostream &out, const PluginLLMCore::ContextData &value)
|
||||
{
|
||||
out << "ContextData{"
|
||||
<< "\n systemPrompt=" << value.systemPrompt << "\n prefix=" << value.prefix
|
||||
|
||||
Reference in New Issue
Block a user