Skip to main content

jupyter_anywidget_window_ai

Example of using window.ai in-browser LLM (Chrome Canary) in JupyterLab / Jupyter notebook using anywidget.

Example of jupyter_anywidget_window_ai panel view

Set-up Chrome Canary / window.ai: Getting started with window.ai in Chrome Canary — in browser Gemini LLM

We can test the availability of window.ai prompt API using some simple javascript magic in a Jupyter notebook accessed via an appropriately configured Chrome Canary browser:

%%javascript
// VIEW RESULT IN BROWSER DEV TOOLS CONSOLE

// h/t ChatGPT

(async function() {
     console.log("Creating AI asisstant...\n\n");
 
    // Assuming ai.assistant.create() is defined 
    // and accessible in your environment
    const session = await ai.assistant.create();

    console.log("Session created...\n\n");

    console.log("Sending prompt...\n\n");

    // Prompt the model and wait for the result
    const result = await session.prompt("Write me a poem.");


    // Log the result to the console
    console.log(result);
})();

Installation

pip install jupyter_anywidget_window_ai

Usage

This runs in a browser based Jupyter environment and uses the browser machinery to run the in-browser LLM application.

Create a widget:

# Import package
from jupyter_anywidget_window_ai import windowai_panel, windowai_inline, windowai_headless

# Create a headless widget
# - works in: Jupyter Lab, Jupyter Notebook, VS Code
w = windowai_headless()

# Inline mode
# Preview output as cell output from initialising cell
# - works in: Jupyter Lab, Jupyter Notebook, VS Code
# w = windowai_inline()

# Create a widget panel with a handle
# - uses jupyter sidecar (Jupyter Lab only)
#w = windowai_panel()
# Close panel either via X or:
#w.close()

Get model capabilities: w.update_capabilities(). Note that this may take a moment to update the py state and no callback is currently available. Run the command in its own cell and wait a moment.

Create a prompt session with an optional system prompt: w.create_session(system_prompt=PROMPT)

Submit a prompt: w.prompt("Hello, how are you?")

Also available: w.create_session(..., initialPrompts=[], temperature=FLOAT, topK=INT )

At the moment, there is no callback available on a response generated from a prompt. However, an audible alert is available.

This is enabled by default in windowai_headless(). The response can also be spoken. Use boolean (True/False ) parameters completion_tone= and speak_msg= in windowai_panel(), windowai_inline() and windowai_headless() to set audible responses.

Get the response text: w.get_latest_output()

Destroy the session: w.destroy()

See window.ai.assistant docs for more examples that should translate: Google explainer: prompt-api

TO DO

ELSEWHERE

See other examples of running "sideloaded" WASM apps using Jupyter anywidget models

Metadata

Release files for jupyter-anywidget-window-ai 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyter-anywidget-window-ai 0.0.3
File Size Uploaded
jupyter_anywidget_window_ai-0.0.3.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyter-anywidget-window-ai 0.0.3
File Interpreter ABI Platform
jupyter_anywidget_window_ai-0.0.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.3 kB

Release files / jupyter_anywidget_window_ai-0.0.3.tar.gz

Download URL jupyter_anywidget_window_ai-0.0.3.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
244676b0318a6c29e099064184760545920b12cfa3a2bc1cfa2f5899523a0b09
BLAKE2b-256 checksum
How to use checksums
b68668f7c459270e10014370c66368e402da059614ce02ac9beeeb2426439b0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Release files / jupyter_anywidget_window_ai-0.0.3-py2.py3-none-any.whl

Download URL jupyter_anywidget_window_ai-0.0.3-py2.py3-none-any.whl
Size 8.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
83c7777f7b500f2b1f5455f081c1248a33d3844604b2774079d7973fc1d2db3a
BLAKE2b-256 checksum
How to use checksums
1466bdfe4e6757cc33d117744a7121a85078a1bbdd366ac8f96207692fc7e755
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

1 release file

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page