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

Review and update Polyglot Chat README #258

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ cd graalvm-demos
<td align="left" width="30%"><a href="/graalpy-notebook-example/">graalpy-notebook-example</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/graalpy-notebook-example.yml"><img alt="graalpy-notebook-example" src="https://github.com/graalvm/graalvm-demos/actions/workflows/graalpy-notebook-example.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to embed Python in a Java application running on GraalVM <br><strong>Technologies: </strong>GraalPy</td>
</tr>
<tr>
<td align="left" width="30%"><a href="/polyglot-chat-app/">polyglot-chat-app</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/polyglot-chat-app.yml"><img alt="polyglot-chat-app" src="https://github.com/graalvm/graalvm-demos/actions/workflows/polyglot-chat-app.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to integrate Python in a Micronaut Java application and build using Gradle <br><strong>Technologies: </strong>Java, GraalPy, Micronaut</td>
</tr>
</tbody>
</table>

Expand All @@ -265,10 +269,6 @@ cd graalvm-demos
</tr>
</thead>
<tbody>
<tr>
<td align="left" width="30%"><a href="/polyglot-chat-app/">polyglot-chat-app</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/polyglot-chat-app.yml"><img alt="polyglot-chat-app" src="https://github.com/graalvm/graalvm-demos/actions/workflows/polyglot-chat-app.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to build a polyglot chat application by embedding Python and R into the Java host language <br><strong>Technologies: </strong>Java, GraalPy, FastR, Micronaut</td>
</tr>
<tr>
<td align="left" width="30%"><a href="/polyglot-debug/">polyglot-debug</a><br><a href="https://github.com/graalvm/graalvm-demos/actions/workflows/polyglot-debug.yml"><img alt="polyglot-debug" src="https://github.com/graalvm/graalvm-demos/actions/workflows/polyglot-debug.yml/badge.svg" /></a></td>
<td align="left" width="70%">Demonstrates how to debug a polyglot Java and JavaScript application using GraalVM Tools for Java in VS Code <br><strong>Technologies: </strong>Java, JavaScript, Maven, GraalVM Extension Pack</td>
Expand Down
1 change: 1 addition & 0 deletions polyglot-chat-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ out/
.settings
.classpath
.factorypath
src/main/resources/venv/pyvenv.cfg
43 changes: 26 additions & 17 deletions polyglot-chat-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,44 @@
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/)
## Preparation`
olyagpl marked this conversation as resolved.
Show resolved Hide resolved

## Preparation

1. Download the latest GraalPy as described on [https://www.graalvm.org/python/](https://www.graalvm.org/python/). For example on Linux:
1. Download or clone GraalVM demos repository and navigate into the `polyglot-chat-app` directory:
olyagpl marked this conversation as resolved.
Show resolved Hide resolved
```bash
git clone https://github.com/graalvm/graalvm-demos
```
```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
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 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
``

3. Create a virtual environment for this demo in the _resources_ directory, and install the required packages:
```bash
graalpy-23.1.1-linux-amd64/bin/graalpy -m venv src/main/resources/venv
```
```bash
src/main/resources/venv/bin/graalpy -m pip install nltk
```
```bash
src/main/resources/venv/bin/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. (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.

## Building and Running the application:
## Building and Running the Application:

olyagpl marked this conversation as resolved.
Show resolved Hide resolved
1. Build application with Gradle:
```bash
./gradlew run
```
```bash
./gradlew run
```

2. Navigate to http://localhost:12345/#/chat/bob
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.
Expand Down Expand Up @@ -61,7 +70,7 @@ The Python code has to be shipped in a _resources_ directory that is kept next t

3. Run the native executable:
```bash
build/native/nativeCompile/websocket.chat
./build/native/nativeCompile/websocket.chat
```

### Learn More
Expand Down
5 changes: 1 addition & 4 deletions polyglot-chat-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,4 @@ micronaut {
deduceEnvironment = true
optimizeNetty = true
}
}



}
2 changes: 0 additions & 2 deletions polyglot-chat-app/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@

rootProject.name="websocket.chat"

Loading