chore: Some refactorings

This commit is contained in:
Robin Shen 2025-11-13 22:30:33 +08:00
parent 1eb8bda97e
commit a62db8265f
13 changed files with 30 additions and 39 deletions

View File

@ -29,9 +29,7 @@ public class AIModelSetting implements Serializable {
private static final long serialVersionUID = 1L;
private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 10;
private static final int DEFAULT_READ_TIMEOUT_SECONDS = 30;
private static final int TIMEOUT_SECONDS = 30;
private static final Logger logger = LoggerFactory.getLogger(AIModelSetting.class);
@ -84,16 +82,14 @@ public class AIModelSetting implements Serializable {
try {
var modelsUrl = baseUrl.endsWith("/") ? baseUrl + "models" : baseUrl + "/models";
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(DEFAULT_CONNECT_TIMEOUT_SECONDS))
.build();
HttpClient client = HttpClient.newBuilder().build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(modelsUrl))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.GET()
.timeout(Duration.ofSeconds(DEFAULT_READ_TIMEOUT_SECONDS))
.timeout(Duration.ofSeconds(TIMEOUT_SECONDS))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
@ -128,7 +124,7 @@ public class AIModelSetting implements Serializable {
.apiKey(apiKey)
.baseUrl(baseUrl)
.modelName(name)
.timeout(Duration.ofSeconds(DEFAULT_READ_TIMEOUT_SECONDS))
.timeout(Duration.ofSeconds(TIMEOUT_SECONDS))
.build();
}

View File

@ -27,4 +27,4 @@ input.input-assist {
}
.dark-mode .input-error-mark {
background: url(wave-dark.png) repeat-x bottom;
}
}

View File

@ -251,11 +251,8 @@ onedev.server.inputassist = {
$form.css("position", "relative");
var coord = getCaretCoordinates($input[0], caret);
var $indicator;
if (onedev.server.isDarkMode())
$indicator = $("<div class='ajax-loading-indicator natural-language-translating-indicator'><img src='/~img/dark-ajax-indicator.gif' width='16' height='16'></div>");
else
$indicator = $("<div class='ajax-loading-indicator natural-language-translating-indicator'><img src='/~img/ajax-indicator.gif' width='16' height='16'></div>");
var icon = onedev.server.isDarkMode()? "sparkle.gif": "sparkle-dark.gif";
var $indicator = $("<div class='ajax-loading-indicator natural-language-translating-indicator'><img src='/~img/" + icon + "' width='16' height='16'></div>");
$indicator.appendTo($form);
var inputCoord = $input.offset();

View File

@ -3,7 +3,7 @@
<wicket:enclosure child="definitions">
<div class="mb-2"><b><wicket:t>Possible definitions</wicket:t></b></div>
<div wicket:id="definitionInferHint" class="mb-2 hint">
<wicket:svg href="bulb" class="icon icon-sm"/><wicket:t><a href="/~administration/settings/lite-ai-model" target="_blank">Set up AI</a> to mark the most probable</wicket:t>
<wicket:svg href="bulb" class="icon icon-sm"/><wicket:t><a href="/~administration/settings/lite-ai-model" target="_blank">Set up AI</a> to mark the most likely</wicket:t>
</div>
<ul class="definitions list-unstyled">
<li wicket:id="definitions">

View File

@ -315,6 +315,7 @@ public abstract class SymbolTooltipPanel extends Panel {
target.appendJavaScript(script);
} else {
var liteModel = settingService.getAISetting().getLiteModel();
int index;
try {
ObjectMapper mapperCopy = objectMapper.copy();
mapperCopy.addMixIn(PlanarRange.class, IgnorePlanarRangeMixin.class);
@ -344,19 +345,17 @@ public abstract class SymbolTooltipPanel extends Panel {
Possible symbol definitions json:
%s
""", symbolName, jsonOfSymbolContext, jsonOfSymbolHits));
var lineNo = Integer.parseInt(liteModel.chat(systemMessage, userMessage).aiMessage().text());
if (lineNo >= 0 && lineNo < symbolHits.size()) {
@SuppressWarnings("unchecked")
ListView<QueryHit> definitionsView = (ListView<QueryHit>) content.get("definitions");
@SuppressWarnings("deprecation")
var script = String.format("onedev.server.symboltooltip.doneInfer('%s');",
definitionsView.get(lineNo).getMarkupId());
target.appendJavaScript(script);
}
index = Integer.parseInt(liteModel.chat(systemMessage, userMessage).aiMessage().text());
if (index < 0 || index >= symbolHits.size())
Session.get().warn("Unable to find most likely definition");
} catch (Exception e) {
index = -1;
logger.error("Error inferring most likely symbol definition", e);
Session.get().error("Error inferring most likely symbol definition, check server log for details");
}
var script = String.format("onedev.server.symboltooltip.doneInfer('%s', %d);",
getMarkupId() + "-symbol-tooltip", index);
target.appendJavaScript(script);
}
}

View File

@ -26,8 +26,8 @@
}
.symbol-tooltip .definition-inferring-indicator img {
width: 14px;
height: 14px;
width: 16px;
height: 16px;
}
.symbol-tooltip .definitions.no-definition-infer>li .most-probable-indicator {
display: none;

View File

@ -83,11 +83,8 @@ onedev.server.symboltooltip = {
$tooltip.removeClass("d-none");
var $definitions = $content.children(".definitions");
if (callback) {
var $indicator;
if (onedev.server.isDarkMode())
$indicator = $('<div class="definition-inferring-indicator mb-2 ajax-loading-indicator"><img src="/~img/dark-ajax-indicator.gif"/> <wicket:t>Inferring the most probable...</wicket:t></div>');
else
$indicator = $('<div class="definition-inferring-indicator mb-2 ajax-loading-indicator"><img src="/~img/ajax-indicator.gif"/> <wicket:t>Inferring the most probable...</wicket:t></div>');
var icon = onedev.server.isDarkMode()? "sparkle.gif": "sparkle-dark.gif";
var $indicator = $('<div class="definition-inferring-indicator mb-2 ajax-loading-indicator"><img src="/~img/' + icon + '"/> <wicket:t>Inferring the most likely...</wicket:t></div>');
$indicator.insertBefore($definitions);
callback("infer");
} else {
@ -98,11 +95,13 @@ onedev.server.symboltooltip = {
}
},
doneInfer: function(definitionId) {
var $definition = $("#" + definitionId);
$definition.addClass("most-probable");
var $tooltip = $definition.closest(".symbol-tooltip");
doneInfer: function(tooltipId, index) {
var $tooltip = $("#" + tooltipId);
$tooltip.find(".definition-inferring-indicator").remove();
var $definitions = $tooltip.find(">.definitions>li");
if (index >= 0 && index < $definitions.length) {
$definitions.eq(index).addClass("most-probable");
}
$tooltip.align($tooltip.data("alignment"));
},

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -5,7 +5,7 @@
This model will be used to perform lite tasks including:
<ul class="mb-0">
<li>Query issues, builds, and pull requests with natural language</li>
<li>Mark the most probable symbol definition in symbol navigation</li>
<li>Mark the most likely symbol definition in symbol navigation</li>
</ul>
It should be fast and cost-effective. Some suggested models:
<code>Google/gemini-2.5-flash</code>,

View File

@ -19,7 +19,7 @@
</div>
<div wicket:id="buildSupportNote" class="build-support-note p-3 flex-shrink-0">
<wicket:svg href="bulb" class="icon"/>
<wicket:t>Enable build support by <a wicket:id="addFile" class="link-primary"></a></wicket:t>
<wicket:t>Enable CI/CD by <a wicket:id="addFile" class="link-primary"></a></wicket:t>
</div>
<div wicket:id="blobContent" class="blob-content autofit flex-grow-1 d-flex flex-column"></div>
<div wicket:id="searchResult" class="search-result flex-shrink-0 flex-column overflow-hidden">

View File

@ -5,7 +5,7 @@
<div class="mb-4">
<wicket:t>
You may initialize the project by <a wicket:id="addFiles" class="link-primary">adding files</a>,
<a wicket:id="setupBuildSpec" class="link-primary">setting up build spec</a>,
<a wicket:id="setupBuildSpec" class="link-primary">setting up CI/CD</a>,
or <a wicket:id="pushInstructions" class="link-primary">pushing an existing repository</a>
</wicket:t>
</div>

View File

@ -34,7 +34,7 @@
</a>
</div>
<!-- Put all options in a single line to make :empty selector working -->
<div class="options d-flex align-items-center"><wicket:enclosure child="viewPlain"><label class="checkbox"><input type="checkbox" wicket:id="viewPlain"> <wicket:t>View Source</wicket:t></label></wicket:enclosure><wicket:enclosure child="blame"><label class="checkbox"><input type="checkbox" wicket:id="blame"> <wicket:t>Blame</wicket:t></label></wicket:enclosure><wicket:container wicket:id="extraOptions"></wicket:container></div>
<div class="options d-flex align-items-center"><wicket:enclosure child="viewPlain"><label class="checkbox"><input type="checkbox" wicket:id="viewPlain"> <wicket:t>YAML</wicket:t></label></wicket:enclosure><wicket:enclosure child="blame"><label class="checkbox"><input type="checkbox" wicket:id="blame"> <wicket:t>Blame</wicket:t></label></wicket:enclosure><wicket:container wicket:id="extraOptions"></wicket:container></div>
<div wicket:id="formats" class="formats d-none d-sm-block"></div>
</div>
</div>