https://www.boundaryml.com logo
Python Notebooks not loading baml
# help
b
Any tips for using notebooks?
.ipynb
Whenever I change my baml
src
and codegen runs, the running kernel get's confused about types and stuff My current solution (which isn't perfect, it doesn't always work)
Copy code
py
import sys
for mod in list[str](sys.modules.keys()):
  if mod.startswith("baml_client"):
    del sys.modules[mod]

from baml_client.types import *
from baml_client.async_client import b
I put that in a cell. It works sometimes and means I get to avoid restarting my kernel just because i changed some baml classes
if you set the
autoreload
thing, then it should "just work" if you re-run the import cell
b
This is my current import setup:
Copy code
%load_ext autoreload
%autoreload 2

import sys
import os
if '__file__' in globals():
  sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
else:
  sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..')))

from dotenv import load_dotenv
load_dotenv()

import os
os.environ["BAML_LOG"] = "off" # off | error | warn | info | debug | trace
Maybe it cases me issues because baml_client is located in a parent directory? That's why i have to add
..
to the syspath