mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-11 21:31:04 +00:00
Clean up code
This commit is contained in:
parent
ec3120a5e6
commit
346218b512
3 changed files with 12 additions and 9 deletions
|
|
@ -15,7 +15,7 @@ import java.util.Map;
|
|||
import java.util.stream.Collectors;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TotalTokensPanel extends JPanel {
|
||||
|
||||
|
|
@ -23,7 +23,10 @@ public class TotalTokensPanel extends JPanel {
|
|||
private final TokenDetails tokenDetails;
|
||||
private final JBLabel label;
|
||||
|
||||
public TotalTokensPanel(Conversation conversation, String userPrompt, String highlightedText) {
|
||||
public TotalTokensPanel(
|
||||
Conversation conversation,
|
||||
String userPrompt,
|
||||
@Nullable String highlightedText) {
|
||||
super(new FlowLayout(FlowLayout.LEADING, 0, 0));
|
||||
this.encodingManager = EncodingManager.getInstance();
|
||||
this.tokenDetails = createTokenDetails(conversation, userPrompt, highlightedText);
|
||||
|
|
@ -65,11 +68,13 @@ public class TotalTokensPanel extends JPanel {
|
|||
private TokenDetails createTokenDetails(
|
||||
Conversation conversation,
|
||||
String userPrompt,
|
||||
String highlightedText) {
|
||||
@Nullable String highlightedText) {
|
||||
var tokenDetails = new TokenDetails(encodingManager);
|
||||
tokenDetails.setConversationTokens(encodingManager.countConversationTokens(conversation));
|
||||
tokenDetails.setUserPromptTokens(encodingManager.countTokens(userPrompt));
|
||||
tokenDetails.setHighlightedTokens(encodingManager.countTokens(highlightedText));
|
||||
if (highlightedText != null) {
|
||||
tokenDetails.setHighlightedTokens(encodingManager.countTokens(highlightedText));
|
||||
}
|
||||
return tokenDetails;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,13 +52,12 @@ public final class EditorUtils {
|
|||
return editorManager != null ? editorManager.getSelectedTextEditor() : null;
|
||||
}
|
||||
|
||||
public static @NotNull String getSelectedEditorSelectedText(@NotNull Project project) {
|
||||
public static @Nullable String getSelectedEditorSelectedText(@NotNull Project project) {
|
||||
var selectedEditor = EditorUtils.getSelectedEditor(project);
|
||||
var selectedText = "";
|
||||
if (selectedEditor != null) {
|
||||
selectedText = selectedEditor.getSelectionModel().getSelectedText();
|
||||
return selectedEditor.getSelectionModel().getSelectedText();
|
||||
}
|
||||
return selectedText == null ? "" : selectedText;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isMainEditorTextSelected(@NotNull Project project) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue