No project description provided
Project description
jupyter_anywidget_window_ai
Example of using window.ai
in-browser LLM (Chrome Canary) in JupyterLab / Jupyter notebook using anywidget
.
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
// 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()
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=[] )
At the moment, there is no callback available on a response ggenerated 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
- add support for changing
temperature
,topK
; - add
autosession
flag to allow session to be automatically configured and created when a widget is instantiated; - add support for other APIs (
explainers-by-googlers/writing-assistance-apis
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for jupyter_anywidget_window_ai-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30a5e390aadd5fe1617d0d9f29f2334cf426869fa1f83205d7c60d4dbe047b77 |
|
MD5 | fe3688373025a7021cf00af706cec568 |
|
BLAKE2b-256 | dbac5073bb2badb4f189416e6592ea37db122989d1aad22203e3270465059d0e |
Hashes for jupyter_anywidget_window_ai-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66271732437deb18486277d5d9a5a01aec61b76e67454294d2f9f9b711aba6ee |
|
MD5 | b66fc7c726945b5730c2d0a48311f4ca |
|
BLAKE2b-256 | 38953b96cab61e32a52a54652f91245584efb0b2d154ec4f3279c2086db3b777 |