-
Notifications
You must be signed in to change notification settings - Fork 169
Review and update Polyglot Chat README #258
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ac7698
Review and update Polyglot Chat README
olyagpl fb91b24
Update README.md
olyagpl 99bdccb
Update README.md
olyagpl 7fd83ec
Move polyglo-chat-app to GraalPy demos list in top-level README
olyagpl e420fd8
Add src/main/resources/venv/pyvenv.cfg to gitignore
olyagpl c22a8a4
Update README.md
olyagpl 5601aaa
Update README.md
olyagpl a069870
Update README and build.gradle to use correct version
95bdb7b
Update README.md
308709b
Resolve merge conflict with master and remove demo entries from top-l…
olyagpl 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
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 |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ out/ | |
| .settings | ||
| .classpath | ||
| .factorypath | ||
| src/main/resources/venv/pyvenv.cfg | ||
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 |
|---|---|---|
| @@ -1,69 +1,84 @@ | ||
| # Polyglot Chat Application | ||
|
|
||
| This example demonstrates how to integrate Python on GraalVM with a Micronaut application. | ||
| The application uses the Gradle build tool. | ||
|
|
||
| ### Prerequisites | ||
| - [Native Image](https://www.graalvm.org/latest/reference-manual/native-image/) | ||
| - [Python support](https://www.graalvm.org/latest/reference-manual/python/) | ||
| This example demonstrates how to integrate Python in a Micronaut Java application using the Gradle build tool. | ||
| The application uses the [Natural Language Toolkit (nltk)](https://www.nltk.org/) module to analyze the sentiment of user input. | ||
| The example also shows how to create a native executable from the application using GraalVM. | ||
|
|
||
| ## Preparation | ||
|
|
||
| 1. Download the latest GraalPy as described on [https://www.graalvm.org/python/](https://www.graalvm.org/python/). For example on Linux: | ||
| ```bash | ||
| wget https://github.com/oracle/graalpython/releases/download/graal-23.1.1/graalpy-23.1.1-linux-amd64.tar.gz | ||
| tar xzf graalpy-23.1.1-linux-amd64.tar.gz | ||
| ``` | ||
| 1. Download or clone the GraalVM demos repository and navigate into the _polyglot-chat-app_ directory: | ||
| ```bash | ||
| git clone https://github.com/graalvm/graalvm-demos | ||
| ``` | ||
| ```bash | ||
| cd graalvm-demos/polyglot-chat-app | ||
| ``` | ||
|
|
||
| 2. Install the required packages for this demo into the _resources_ directory: | ||
| 2. Download and install the latest GraalPy as described in the [Getting Started guide](https://www.graalvm.org/latest/reference-manual/python/#installing-graalpy). For example: | ||
| ```bash | ||
| pyenv install graalpy-23.1.2 | ||
| pyenv shell graalpy-23.1.2 | ||
| ``` | ||
|
|
||
| 3. Create a virtual environment for the demo in the _resources_ directory, activate it, install the required package, and download a lexicon: | ||
| ```bash | ||
| graalpy -m venv src/main/resources/venv | ||
| ``` | ||
| ```bash | ||
| source src/main/resources/venv/bin/activate | ||
| ``` | ||
| ```bash | ||
| graalpy -m pip install nltk | ||
| ``` | ||
| ```bash | ||
| graalpy-23.1.1-linux-amd64/bin/graalpy -m venv src/main/resources/venv | ||
| src/main/resources/venv/bin/graalpy -m pip install nltk | ||
| graalpy -c "import nltk; nltk.download('vader_lexicon')" | ||
| ``` | ||
|
|
||
| 3. Optional: Download and install GraalVM JDK for Java 21 or later to run Python with runtime compilation and to build a native image. | ||
| The demo will work on any OpenJDK distribution, but will be much faster on GraalVM JDK. | ||
| 4. The demo will work with any OpenJDK distribution, but will be much faster on [GraalVM JDK for Java 21](https://www.graalvm.org/downloads/). | ||
|
|
||
| ## Building and Running the application: | ||
|
|
||
| 1. Build application with Gradle: | ||
| ```bash | ||
| ./gradlew run | ||
| ``` | ||
| ## Building and Running the Application | ||
|
|
||
| 2. Navigate to http://localhost:12345/#/chat/bob | ||
| 1. Build and run the application using Gradle: | ||
| ```bash | ||
| ./gradlew run | ||
| ``` | ||
|
|
||
| 2. Navigate to [http://localhost:12345/#/chat/bob](http://localhost:12345/#/chat/bob). | ||
|
|
||
| You can connect from multiple browsers and chat via websockets. | ||
| The Python code will load a language model in the background. | ||
| Once it is ready, it will analyse the sentiments of all messages and add an emoji to the message to indicate the feelings conveyed. | ||
| The Python code loads a language model in the background—this can take up to 5 minutes. | ||
| Once it is ready, it analyzes the sentiments of messages and add an emoji to each message to indicate the feelings conveyed. | ||
| A chat may look like this (newest message at the top): | ||
|
|
||
| ``` | ||
| [bob 😀] awesome, GraalVM and GraalPy rock! | ||
| [bob 🫥] are we done yet? | ||
| [bob 💬] still loading the sentiment model I believe | ||
| [bob 💬] Joined! | ||
| ``` | ||
|
|
||
| ## Building a Native Image | ||
| ## (Optional) Building a Native Executable | ||
|
|
||
| > Note: this requires [GraalVM JDK for Java 21](https://www.graalvm.org/downloads/) or later. | ||
|
|
||
| The application can be AOT compiled using GraalVM Native Image. | ||
| The Python code has to be shipped in a _resources_ directory that is kept next to the native executable. | ||
| The application can be compiled ahead-of-time to a native executable using GraalVM Native Image. | ||
| The Python code must be copied to the _build/_ directory that is kept next to the native executable. | ||
|
|
||
| 1. Build a native executable with the Micronaut AOT support: | ||
| 1. Build a native executable using Micronaut AOT support: | ||
| ```bash | ||
| ./gradlew nativeCompile | ||
| ``` | ||
|
|
||
| 2. Copy the venv into the output _resources_ directory: | ||
| 2. Copy the _venv_ directory into the output _resources_ directory: | ||
| ```bash | ||
| cp -R src/main/resources/venv/ build/native/nativeCompile/resources/python/ | ||
| ``` | ||
|
|
||
| 3. Run the native executable: | ||
| ```bash | ||
| build/native/nativeCompile/websocket.chat | ||
| ./build/native/nativeCompile/websocket.chat | ||
| ``` | ||
|
|
||
| ### Learn More | ||
|
|
||
| Learn more about GraalVM polyglot capabilities [here](https://www.graalvm.org/latest/reference-manual/polyglot-programming/). | ||
| Learn more about GraalVM polyglot capabilities [here](https://www.graalvm.org/latest/reference-manual/polyglot-programming/). | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
|
|
||
| rootProject.name="websocket.chat" | ||
|
|
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.