getappmap / appmap-js

Client libraries for AppMap
48 stars 17 forks source link

User can discard a Navie answer #2033

Open kgilpin opened 2 weeks ago

kgilpin commented 2 weeks ago

When Navie produces an answer that the user doesn't like, the answer can be discarded.

Discarding the answer has the following effects:

github-actions[bot] commented 2 weeks ago

Title: Implement Feature to Discard Navie Answer and Reload Question

Problem: Users need the ability to discard an answer from Navie that they find unsatisfactory. Discarding an answer should remove it from the UI, reload the question into the input box for amendment, and cause the discarded answer and its question to be ignored in the chat history.

Analysis: The feature requires modifications in both the user interface and the backend chat logic. From the user's perspective, discarding an answer involves removing it visually and re-presenting the original question for correction. Behind the scenes, it requires adjusting how the chat history is stored and referenced, ensuring that discarded answers and their associated questions do not impact future exchanges or history retrieval operations.

There needs to be a clear mechanism to toggle or flag specific exchanges (consisting of a question and its answer) as discarded, so they are omitted from any future operations involving chat history, such as displaying past interactions or analyzing conversation context. This can be achieved by modifying exchanges to support a "discarded" state for each exchange.

Proposed Changes:

  1. Frontend Adjustments:

    • Implement a UI component (e.g., a "discard" button) that allows users to discard an answer.
    • Upon interaction, remove the answer from the display and populate the question input box with the corresponding question text.
    • Trigger an event or state change that the backend can listen for to process the discard action.
  2. Backend Changes:

    • Thread Class (packages/cli/src/rpc/explain/navie/thread.ts):
      • Modify the Exchange data structure to include a discarded flag (boolean).
      • Implement a method within the Thread class to mark the most recent exchange as discarded.
      • Ensure that the setAnswer and other relevant methods check for the discarded flag and ignore exchanges where discarded is true.
  3. Chat History Management (packages/cli/src/rpc/explain/navie/history.ts and packages/cli/src/rpc/explain/navie/ihistory.ts):

    • Adjust the way history is managed so that discarded exchanges are correctly marked and skipped in retrieval operations.
    • Ensure that read and write operations to history files take into account the discarded state, filtering out these exchanges when fetching the chat or committing changes.
  4. User Experience Flow (packages/navie/src/services/classification-service.ts):

    • Implement logic to extract the question and populate it back into the input field.
    • Ensure the classification of new or modified questions can still depend on the context correctly, ignoring discarded exchanges.
  5. Testing:

    • Verify that when an answer is discarded, it is immediately removed from the UI, and the question reloads for user modification.
    • Ensure backend history ignores the discarded exchanges, reflected in consistent system behavior post-discard action.
    • Test for edge cases, such as multiple quick discards and re-ask scenarios, to ensure system stability and correct functioning.

By implementing these changes, users can effectively manage the quality of interaction they have with Navie, discarding and refining questions as needed without cluttering the active history.