The Dino 🦕, the Llama 🦙, and the Whale 🐋
This article explores the feasibility of running large language models (LLMs) using Deno and Jupyter Notebooks, focusing on the integration of tools like Ollama, LangChain.js, and zod for structured output validation. It outlines the setup process and highlights the potential of Deno and Jupyter for
Introduction
The integration of Deno and Jupyter Notebooks offers a novel approach to experimenting with large language models (LLMs) locally. This article outlines the process of setting up an environment that leverages Deno's built-in Jupyter kernel, the Ollama framework for running LLMs, and LangChain.js for structured interactions with the model. The focus is on creating a modular and interactive workflow for AI experimentation.
Setting Up the Environment
The first step involves installing Ollama, a framework that allows users to run LLMs locally. Once installed, the Ollama server must be running on port 11434. The next step is to pull a local model, such as the DeepSeek R1 8b parameter model, using the command ollama pull deepseek-r1:8b. This ensures that the model is available for use within the local environment.
With the model in place, the next step is to create a Jupyter Notebook using VSCode. This requires installing the Deno extension and enabling the Deno kernel. The Deno runtime includes a built-in Jupyter kernel, which simplifies the process of creating and running notebooks. This setup allows for interactive code execution and text-based documentation, making it ideal for iterative exploration and thorough documentation of AI workflows.
Using the Model with LangChain.js
LangChain.js provides a consistent interface for interacting with LLMs, including those hosted via Ollama. This is achieved by importing the ChatOllama module and initializing it with the appropriate model configuration. The following code snippet demonstrates how to create a chain using LangChain.js:
import { ChatOllama } from "npm:@langchain/ollama"; const model = new ChatOllama({ model: "deepseek-r1:8b" });
This setup allows for the creation of modular AI workflows, or "chains," which can be structured using RunnableSequence and validated using zod. The StructuredOutputParser is used to parse and validate the output of the LLM, ensuring that it adheres to a predefined schema.
Documenting the Process
LangChain.js, Deno, and Jupyter can be used to document the flow of AI workflows visually. This is achieved by generating a Mermaid diagram of the chain's structure and rendering it as an image within the notebook. This visual representation helps in understanding the flow of data and the interactions between different components of the AI workflow.
The process of asking a question involves invoking the chain with the appropriate parameters. The following code snippet demonstrates how to ask a question and receive a response:
const response = await chain.invoke({ question: "What is a Deno?", format_instructions: parser.getFormatInstructions(), }); console.log(response);
The response is then logged to the console, providing a structured output that includes the answer and the source used to generate it. This approach ensures that the output is validated against a predefined schema, making it easier to integrate with other systems and applications.
Conclusion
The integration of Deno and Jupyter Notebooks provides a fun and productive environment for local AI experimentation. The setup process is relatively straightforward, and the tools used are well-suited for iterative exploration and thorough documentation. This environment has become a go-to solution for learning and prototyping AI workflows, offering a flexible and interactive approach to working with LLMs.
Source: Deno. Analysis based on publicly available information; no hands-on testing is claimed.