LangForge Toolkit

repository·main·Indexed 41 days ago

https://github.com/mme/langforge

An open-source toolkit for simplifying the creation, development, and deployment of LangChain applications. It features a CLI for project initialization, integrated JupyterLab environments with a dedicated extension, template-based development, and automatic REST API generation for notebooks.

Tokens
12.1K
Snippets
55
Records
58
Agent score
50%

What's inside LangForge

  1. Debug Playwright tests with the inspector

    main

    To debug tests using the Playwright inspector tool, run the tests in debug mode by setting the PWDEBUG environment variable to 1.

    1. Compile the extension:

      jlpm install
      jlpm build:prod
    2. Install test dependencies (if not already done):

      cd ./ui-tests
      jlpm install
      jlpm playwright install
      cd ..
    3. Run tests in debug mode:

      cd ./ui-tests
      PWDEBUG=1 jlpm playwright test
    cd ./ui-tests
    PWDEBUG=1 jlpm playwright test
  2. Create a new LangChain app

    main

    Use the langforge create command to initialize a new project. The command will prompt you for configuration details, set up a virtual environment, install necessary packages, and configure your API keys (such as OpenAI).

    langforge create myapp
  3. Run integration tests for the JupyterLab extension

    main

    Integration tests for the extension are powered by Playwright and Galata.

    Follow these steps from the repository root to run the tests:

    1. Compile the extension:

      jlpm install
      jlpm build:prod

      Note: Ensure the extension is installed in your JupyterLab instance before proceeding.

    2. Install test dependencies (only required once):

      cd ./ui-tests
      jlpm install
      jlpm playwright install
      cd ..
    3. Execute the tests:

      cd ./ui-tests
      jlpm playwright test

    Test results are displayed in the terminal. If tests fail, an HTML report will automatically open in your browser.

    # From root
    jlpm install
    jlpm build:prod
    
    # From ui-tests directory
    cd ./ui-tests
    jlpm install
    jlpm playwright install
    cd ..
    
    cd ./ui-tests
    jlpm playwright test
  4. Launch JupyterLab for development

    main

    Navigate into your project directory and use the langforge lab command to launch JupyterLab. This environment includes predefined templates and a built-in chat interface to interact with your LangChain chains.

    cd myapp
    langforge lab
  5. Install LangForge in development mode

    main

    If you are developing the extension, follow these steps to set up a development environment. You will need NodeJS installed.

    Note: jlpm is JupyterLab's pinned version of yarn. You can substitute jlpm with yarn or npm if preferred.

    1. Clone the repository and enter the langforge directory.
    2. Install the package in editable mode using pip install -e ".".
    3. Link your development version to JupyterLab using jupyter labextension develop.
    4. Build the TypeScript source using jlpm build.
    # Clone the repo to your local environment
    # Change directory to the langforge directory
    
    # Install package in development mode
    pip install -e "."
    
    # Link your development version of the extension with JupyterLab
    jupyter labextension develop . --overwrite
    
    # Rebuild extension Typescript source after making changes
    jlpm build
  6. Update Playwright test snapshots

    main

    If your tests use snapshot comparisons and you need to update the reference snapshots in the repository, follow these steps from the repository root:

    1. Compile the extension:

      jlpm install
      jlpm build:prod
    2. Install test dependencies (if not already done):

      cd ./ui-tests
      jlpm install
      jlpm playwright install
      cd ..
    3. Run Playwright with the update flag:

      cd ./ui-tests
      jlpm playwright test -u

    Tip for Pull Requests: To avoid discrepancies between local snapshots and CI snapshots, you can type please update playwright snapshots in your PR to trigger a bot on the CI to compute and commit new snapshots for you.

    # From root
    jlpm install
    jlpm build:prod
    
    # From ui-tests directory
    cd ./ui-tests
    jlpm install
    jlpm playwright install
    cd ..
    
    cd ./ui-tests
    jlpm playwright test -u
  7. Serve your app as a REST interface

    main

    LangForge automatically generates a REST interface for your notebooks. To deploy your app, use the langforge serve command followed by the filename of your notebook.

    langforge serve chat-creative.ipynb
  8. Develop and watch LangForge extension changes

    main

    To see changes in real-time, run the jlpm watch command in one terminal. This will automatically rebuild the extension whenever you save a file. In a separate terminal, run jupyter lab to start the JupyterLab server.

    Note: After a rebuild, you must refresh your browser tab in JupyterLab to load the changes. It may take several seconds for the rebuild to complete.

    To make debugging easier by generating source maps for JupyterLab core extensions, run: jupyter lab build --minimize=False.

    # Watch the source directory in one terminal, automatically rebuilding when needed
    jlpm watch
    
    # Run JupyterLab in another terminal
    jupyter lab
  9. Create new tests using Playwright codegen

    main

    The easiest way to create new integration tests is to use the Playwright code generator. This tool records your interactions with the browser and generates code automatically.

    1. Compile the extension:

      jlpm install
      jlpm build:prod
    2. Install test dependencies (if not already done):

      cd ./ui-tests
      jlpm install
      jlpm playwright install
      cd ..
    3. Launch the code generator:

      cd ./ui-tests
      jlpm playwright codegen localhost:8888

      Note: Replace localhost:8888 with the actual URL where your JupyterLab server is running.

    cd ./ui-tests
    jlpm playwright codegen localhost:8888