Package: nbwrite
nbwriteNote: This is an experimental use case for LLMs, the output may at times be unhelpful or inappropriatenbwrite is a CLI tool which generates notebook-based Python examples using LLMsPotential use cases include:You are writing a Python package and you want to produce executable tutorials for your stakeholdersYou are using a Python package and you want to generate a kick-start guideYou want to generate regression tests for a python packageFeaturesConverts a set of steps and a task description into an executable Python notebookConfigurable OpenAI API parametersGenerate notebooks based on your own code using retrieval augmented generationGetting Started1. Install via any Python package managerpipinstallnbwrite2. Setup your OpenAI API AccessYou will need to create an account and potentially buy credits viahttps://platform.openai.com/exportOPENAI_API_KEY='sk-xxxx'3. Create a spec file for your generation jobe.g. nbwrite/example1.yaml:task:|Plot the iris dataset using pandasgeneration:count:24. Generate some notebooksnbwrite./nbwrite/example1.yamlYour outputs will be in your current directoryGuidesGenerate guides for my closed-source codeYou will need to install the 'rag' extrapip install 'nbwrite[rag]'By default, OpenAI's models can generate docs based on parametric knowledge.
This is limited to popular open source libraries.Thepackagesinput 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.pkgCustomise the OpenAI parametersYou can modify both the system prompt and the llm args to try out different OpenAI models,
temperatures, etc. SeeLangchain's API refNote! 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 applicationsteps:-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 expectingpackages:-nbmake-nbformat-nbclientgeneration: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.BaseOpenAImodel_name:gpt-3.5-turbo# The API name of the model as per https://platform.openai.com/docs/modelstemperature:0.5retriever_kwargs:k:3search_type:similarityFAQs and TroubleshootingHow much does this costIt depends on (a) the model you use and other params such as context length, (b) the number of outputs you generate.See OpenAI usage herehttps://platform.openai.com/account/usageDebugging with PhoenixThis is an Alpha stage product, and we encourage you to investigate and report bugsYou will need to install the 'tracing' extrapip 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 pythonimportphoenix
phoenix.launch_app()input("Press any key to exit...")In another termianl, run nbwrite with the following var set:export NBWRITE_PHOENIX_TRACE=1Check the phoenix traces in the dashboard (defaulthttp://127.0.0.1:6060/)