Skip to content
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

IME Input Handling Issue in Chat LangChain #24233

Closed
5 tasks done
norisuke3 opened this issue Jul 13, 2024 · 2 comments
Closed
5 tasks done

IME Input Handling Issue in Chat LangChain #24233

norisuke3 opened this issue Jul 13, 2024 · 2 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@norisuke3
Copy link

norisuke3 commented Jul 13, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

There is an issue at https://chat.langchain.com/

Description

When using IME to input Japanese prompts in the Chat LangChain (https://chat.langchain.com/), pressing the Enter key to confirm Japanese character conversion results in the prompt being prematurely sent. This issue likely affects other languages using IME as well. (The same type of issue as #24231, but the solution is slightly different)

Steps to Reproduce:

Use IME to input a Japanese prompt.
Press the Enter key to confirm character conversion.

Expected Behavior:

The input should be correctly converted to Japanese.
The prompt should not be sent.

Actual Behavior:

The prompt is sent prematurely while still being composed.

Proposed Solution:

In my local environment, running the following code in the Chrome console resolves the issue. I suggest incorporating a similar solution into the Chat LangChain:

(function() {
    'use strict';

    var parent_element = document.querySelector("body");
    var isComposing = false;

    // Start of Japanese input
    parent_element.addEventListener('compositionstart', function(){
        if (event.target.tagName === 'TEXTAREA') {
            isComposing = true;
        }
    });

    // End of Japanese input
    parent_element.addEventListener('compositionend', function(){
        if (event.target.tagName === 'TEXTAREA') {
            isComposing = false;
        }
    });

    // Modified handleIMEEnter function
    function handleIMEEnter(event) {
        if (event.target.tagName === 'TEXTAREA') {
            if (event.code == "Enter" && isComposing) {
                event.stopPropagation();
            }
        }
    }

    // Register handleIMEEnter function as a keydown event listener
    parent_element.addEventListener('keydown', handleIMEEnter);
})();

Additional Notes:

The difference with IME Input Handling Issue in LangChain Chat Playground is that in Chat LangChain, a new TextArea is dynamically added for each prompt submission. Therefore, it is necessary to ensure that events are fired from the newly added TextArea as well. Specifically, this is achieved by capturing and handling events that bubble up to the body element.

System Information

OS: Darwin
OS Version: Darwin Kernel Version 21.6.0: Thu Jun 8 23:57:12 PDT 2023; root:xnu-8020.240.18.701.6~1/RELEASE_X86_64
Browser: Google Chrome Version 126.0.6478.127 (Official Build) (x86_64)

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 13, 2024
@keenborder786
Copy link
Contributor

This is Repo for Langchain Python. You should raise this issue in the Langchain JS repo.

@norisuke3
Copy link
Author

Okay. I've just posted here: langchain-ai/chat-langchainjs#31

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 14, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants