No project description provided
Project description
nbwrite
Note: This is an experimental use case for LLMs, the output may at times be unhelpful or inappropriate
nbwrite is a CLI tool which generates notebook-based Python examples using LLMs
Potential use cases include:
- You are writing a Python package and you want to produce executable tutorials for your stakeholders
- You are using a Python package and you want to generate a kick-start guide
- You want to generate regression tests for a python package
Features
- Converts a set of steps and a task description into an executable Python notebook
- Configurable OpenAI API parameters
- Generate notebooks based on your own code using retrieval augmented generation
Getting Started
1. Install via any Python package manager
pip install nbwrite
2. Setup your OpenAI API Access
You will need to create an account and potentially buy credits via https://platform.openai.com/
export OPENAI_API_KEY='sk-xxxx'
3. Create a spec file for your generation job
e.g. nbwrite/example1.yaml:
task: |
Plot the iris dataset using pandas
generation:
count: 2
4. Generate some notebooks
nbwrite ./nbwrite/example1.yaml
Your outputs will be in your current directory
Guides
Generate guides for my closed-source code
You will need to install the 'rag' extra pip install 'nbwrite[rag]'
By default, OpenAI's models can generate docs based on parametric knowledge. This is limited to popular open source libraries.
The packages
input in the spec file can be used to reference Python packages in your
current environment, which will be indexed in a local Vector DB. Code relevant to the
task is then stuffed into the prompt.
You can pass in an arbitrary number of packages, just remember that the code will be sent to OpenAI to create embeddings, and this costs money.
example:
packages:
- my_internal_pkg
- another.internal.pkg
Customise the OpenAI parameters
You can modify both the system prompt and the llm args to try out different OpenAI models, temperatures, etc. See Langchain's API ref
Note! This is a confusing use case -- change it to something relevant to your work.
task: |
Create a hello world notebook 'x.ipynb', use nbmake's NotebookRun class to test it from a Python application
steps:
- Create a hello world notebook using nbformat
- Use nbmake's NotebookRun class to execute it from a Python application
- Check the output notebook printed what we were expecting
packages:
- nbmake
- nbformat
- nbclient
generation:
count: 2 # number of notebooks to generate
# system_prompt:
llm_kwargs:
# https://api.python.langchain.com/en/latest/llms/langchain.llms.openai.BaseOpenAI.html#langchain.llms.openai.BaseOpenAI
model_name: gpt-3.5-turbo # The API name of the model as per https://platform.openai.com/docs/models
temperature: 0.5
retriever_kwargs:
k: 3
search_type: similarity
FAQs and Troubleshooting
How much does this cost
It depends on (a) the model you use and other params such as context length, (b) the number of outputs you generate.
See OpenAI usage here https://platform.openai.com/account/usage
Debugging with Phoenix
This is an Alpha stage product, and we encourage you to investigate and report bugs
You will need to install the 'tracing' extra pip install 'nbwrite[tracing]'
For any errors occurring during the main generation process, it's possible to view traces using Phoenix.
-
Start Phoenix with this script
#! /usr/bin/env python import phoenix phoenix.launch_app() input("Press any key to exit...")
-
In another termianl, run nbwrite with the following var set:
export NBWRITE_PHOENIX_TRACE=1
-
Check the phoenix traces in the dashboard (default http://127.0.0.1:6060/)
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file nbwrite-0.2.tar.gz
.
File metadata
- Download URL: nbwrite-0.2.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09bd87aea1bdab1aadc78dd4f42d06a746527110e339349995525e74eeef3013 |
|
MD5 | 222d30fb49f3bf85aecfae1b469137fb |
|
BLAKE2b-256 | 7c8fe54bcb27f1094aea122e02b2ce12a92a9afcbd34bc5911b6341dffad1d9a |
File details
Details for the file nbwrite-0.2-py3-none-any.whl
.
File metadata
- Download URL: nbwrite-0.2-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d922518527533795bd95f645a73bd2c7b3771e6118df329de391ee21cba065 |
|
MD5 | a79dc726c08a4358311c52f731c7af55 |
|
BLAKE2b-256 | 2e488dc2ce8b400c4f729422fb8ad19bceab865963c44c86a078f95f4d0ddc75 |