| 89 | } |
| 90 | |
| 91 | void QuickRefactorHandler::prepareAndSendRequest( |
| 92 | TextEditor::TextEditorWidget *editor, |
| 93 | const QString &instructions, |
| 94 | const Utils::Text::Range &range) |
| 95 | { |
| 96 | auto &settings = Settings::generalSettings(); |
| 97 | |
| 98 | auto &providerRegistry = PluginLLMCore::ProvidersManager::instance(); |
| 99 | auto &promptManager = PluginLLMCore::PromptTemplateManager::instance(); |
| 100 | |
| 101 | const auto providerName = settings.qrProvider(); |
| 102 | auto provider = providerRegistry.getProviderByName(providerName); |
| 103 | |
| 104 | if (!provider) { |
| 105 | QString error = QString("No provider found with name: %1").arg(providerName); |
| 106 | LOG_MESSAGE(error); |
| 107 | RefactorResult result; |
| 108 | result.success = false; |
| 109 | result.errorMessage = error; |
| 110 | result.editor = editor; |
| 111 | emit refactoringCompleted(result); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | const auto templateName = settings.qrTemplate(); |
| 116 | auto promptTemplate = promptManager.getChatTemplateByName(templateName); |
| 117 | |
| 118 | if (!promptTemplate) { |
| 119 | QString error = QString("No template found with name: %1").arg(templateName); |
| 120 | LOG_MESSAGE(error); |
| 121 | RefactorResult result; |
| 122 | result.success = false; |
| 123 | result.errorMessage = error; |
| 124 | result.editor = editor; |
| 125 | emit refactoringCompleted(result); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | QJsonObject payload{ |
| 130 | {"model", Settings::generalSettings().qrModel()}, {"stream", true}}; |
| 131 | |
| 132 | PluginLLMCore::ContextData context = prepareContext(editor, range, instructions); |
| 133 | |
| 134 | bool enableTools = Settings::quickRefactorSettings().useTools(); |
| 135 | bool enableThinking = Settings::quickRefactorSettings().useThinking(); |
| 136 | provider->prepareRequest( |
| 137 | payload, |
| 138 | promptTemplate, |
| 139 | context, |
| 140 | PluginLLMCore::RequestType::QuickRefactoring, |
| 141 | enableTools, |
| 142 | enableThinking); |
| 143 | |
| 144 | provider->client()->setMaxToolContinuations( |
| 145 | Settings::toolsSettings().maxToolContinuations()); |
| 146 | |
| 147 | provider->client()->setTransferTimeout( |
| 148 | static_cast<int>(Settings::generalSettings().requestTimeout() * 1000)); |
nothing calls this directly
no test coverage detected