-
Notifications
You must be signed in to change notification settings - Fork 6
Chat Partial Result #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f2cabc
Log partial result
angjordn ad3d3a8
Reaching partial result handler
angjordn 7e75224
Rendering partial responses successfully
angjordn d499aae
Add comments
angjordn 53883a0
Cleaned up code and added comments
angjordn 34f0586
Update comment
angjordn c6b3db6
Merged with latest changes
angjordn 892cd2b
Move ignore null serialization to ChatResult record
angjordn a089605
Fix checkstyle errors
angjordn b1d1294
Fix checkstyle after merge
angjordn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.swt.browser.Browser; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatRequestParams; | ||
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult; | ||
import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer; | ||
|
||
public final class ChatMessage { | ||
private final Browser browser; | ||
private final ChatRequestParams chatRequestParams; | ||
private final AmazonQLspServer amazonQLspServer; | ||
private final ChatCommunicationManager chatCommunicationManager; | ||
|
||
public ChatMessage(final AmazonQLspServer amazonQLspServer, final Browser browser, final ChatRequestParams chatRequestParams) { | ||
this.amazonQLspServer = amazonQLspServer; | ||
this.browser = browser; | ||
this.chatRequestParams = chatRequestParams; | ||
this.chatCommunicationManager = ChatCommunicationManager.getInstance(); | ||
} | ||
|
||
public Browser getBrowser() { | ||
return browser; | ||
} | ||
|
||
public ChatRequestParams getChatRequestParams() { | ||
return chatRequestParams; | ||
} | ||
|
||
public String getPartialResultToken() { | ||
return chatRequestParams.getPartialResultToken(); | ||
} | ||
|
||
public CompletableFuture<ChatResult> sendChatMessageWithProgress() { | ||
// Retrieving the chat result is expected to be a long-running process with intermittent progress notifications being sent | ||
// from the LSP server. The progress notifications provide a token and a partial result Object - we are utilizing a token to | ||
// ChatMessage mapping to acquire the associated ChatMessage so we can formulate a message for the UI. | ||
String partialResultToken = chatCommunicationManager.addPartialChatMessage(this); | ||
|
||
CompletableFuture<ChatResult> chatResult = amazonQLspServer.sendChatPrompt(chatRequestParams) | ||
.thenApply(result -> { | ||
// The mapping entry no longer needs to be maintained once the final result is retrieved. | ||
chatCommunicationManager.removePartialChatMessage(partialResultToken); | ||
return result; | ||
}); | ||
|
||
return chatResult; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatPartialResultMap.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
|
||
/** | ||
* ChatPartialResultMap is a utility class responsible for managing the mapping between | ||
* partial result tokens and their corresponding ChatMessage objects in the Amazon Q plugin for Eclipse. | ||
* | ||
* The Language Server Protocol (LSP) server sends progress notifications during long-running operations, | ||
* such as processing chat requests. These notifications include a token that identifies the specific operation | ||
* and a partial result object containing the progress information. | ||
* | ||
* This class maintains a concurrent map (tokenToChatMessageMap) that associates each token with | ||
* its respective ChatMessage object. This mapping is crucial for correctly updating the chat UI | ||
* with the latest progress information as it becomes available from the LSP server. | ||
* | ||
* The progress notifications are handled by the {@link AmazonQLspClientImpl#notifyProgress(ProgressParams)} | ||
* method, which retrieves the corresponding ChatMessage object from the tokenToChatMessageMap using | ||
* the token provided in the ProgressParams. The ChatMessage can then be updated with the partial result. | ||
*/ | ||
public final class ChatPartialResultMap { | ||
|
||
private final Map<String, ChatMessage> tokenToChatMessageMap; | ||
|
||
public ChatPartialResultMap() { | ||
tokenToChatMessageMap = new ConcurrentHashMap<String, ChatMessage>(); | ||
} | ||
|
||
public void setEntry(final String token, final ChatMessage chatMessage) { | ||
tokenToChatMessageMap.put(token, chatMessage); | ||
} | ||
|
||
public void removeEntry(final String token) { | ||
tokenToChatMessageMap.remove(token); | ||
} | ||
|
||
public ChatMessage getValue(final String token) { | ||
return tokenToChatMessageMap.getOrDefault(token, null); | ||
} | ||
|
||
public Boolean hasKey(final String token) { | ||
return tokenToChatMessageMap.containsKey(token); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
plugin/src/software/aws/toolkits/eclipse/amazonq/util/ProgressNotficationUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.util; | ||
|
||
import org.eclipse.lsp4j.ProgressParams; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
|
||
|
||
public final class ProgressNotficationUtils { | ||
private ProgressNotficationUtils() { | ||
// Prevent instantiation | ||
} | ||
|
||
/* | ||
* Get the token from the ProgressParams value | ||
* @return The token as a String | ||
*/ | ||
public static String getToken(final ProgressParams params) { | ||
String token; | ||
|
||
if (params.getToken().isLeft()) { | ||
angjordn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
token = params.getToken().getLeft(); | ||
} else { | ||
token = params.getToken().getRight().toString(); | ||
} | ||
|
||
return token; | ||
} | ||
|
||
/* | ||
* Get the object from the ProgressParams value | ||
* @param cls The class of the object to be deserialized | ||
* @return The deserialized object, or null if the value is not a JsonElement | ||
*/ | ||
public static <T> T getObject(final ProgressParams params, final Class<T> cls) { | ||
Object val = params.getValue().getRight(); | ||
|
||
if (!(val instanceof JsonElement)) { | ||
return null; | ||
} | ||
|
||
Gson gson = new Gson(); | ||
JsonElement element = (JsonElement) val; | ||
T obj = gson.fromJson(element, cls); | ||
breedloj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return obj; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.