Writing Better Code with Ollama

Matt Williams
26 Jan 202404:43

TLDRThe video discusses the release of an official Node.js library for Ollama and its integration with Python. The creator shares their experience with using Ollama's chat endpoint, highlighting the benefits of streaming responses via an async generator for a faster feel. They also introduce Llama Coder and Continue.dev, two VS Code extensions that offer local coding assistance without internet, perfect for those in areas with limited connectivity. The video provides a setup guide for these tools, encouraging viewers to explore and customize their coding experience with different models and settings.

Takeaways

  • 🚀 The Ollama team has released an official Node.js library for Ollama, which can be found on GitHub.
  • 📝 The speaker plans to start building with the Node.js library and its Python equivalent soon.
  • 🔌 Initially, the chat endpoint is used with a system prompt, and the response is in JSON format, including performance metrics.
  • ⏱️ Streaming is introduced as a way to get faster feedback, though it results in an error when set to true due to the return type changing to an async generator.
  • 🧠 Llama Coder is a tool that autocompletes code based on user input, including comments, and is an alternative to GitHub Copilot.
  • 🛠️ The speaker seeks help from Continue.dev to find an alternative to console.log that doesn't add a newline, leading to the use of process.stdout.write.
  • 🔧 Both Llama Coder and Continue.dev are free VS Code extensions that work offline, which is useful for those without constant internet access.
  • 🏞️ The speaker, living on an island, values being able to work on code during their ferry rides without internet.
  • 🛠️ The setup for using Ollama involves installing Ollama, the Llama Coder extension, and Continue, with specific model configurations detailed.
  • 📚 The speaker suggests reviewing Continue's documentation for further capabilities and disabling telemetry for offline use.
  • 🤖 Other VS Code extensions like Code GPT and Ollama Autocoder are mentioned, but the speaker finds Llama Coder and Continue to be the best fit.

Q & A

  • What is the recent development from the Ollama team?

    -The Ollama team has recently released an official Node.js library for Ollama, which can be found on GitHub.

  • How does the chat endpoint of the Ollama library work?

    -The chat endpoint of the Ollama library works by taking a system prompt and an initial question as input and returns a JSON blob containing the output and performance metrics.

  • What is the default behavior of the chat endpoint in terms of response delivery?

    -By default, the chat endpoint does not stream responses. It waits for the full response to be completed before delivering it as a JSON blob.

  • What happens when you set the stream to true in the Ollama library?

    -Setting the stream to true changes the function to return an async generator instead of a JSON blob, which requires a different handling approach.

  • What is Llama Coder and how does it assist in coding?

    -Llama Coder is a VS Code extension that assists in coding by automatically typing out code suggestions based on the user's needs. It can complete code snippets when the user presses tab.

  • How can you avoid newlines when printing tokens in the Ollama library?

    -To avoid newlines when printing tokens, you can use 'process.stdout.write' instead of 'console.log' to output the tokens without breaking the lines.

  • What are the benefits of using Continue.dev in conjunction with Llama Coder?

    -Continue.dev is beneficial as it provides an alternative to console.log that doesn't add a newline, and it allows users to ask questions and receive code suggestions without an internet connection, making it ideal for offline coding scenarios.

  • How does the setting of the Llama Coder extension affect its performance?

    -The setting of the Llama Coder extension, specifically the model used, affects its performance in terms of speed and accuracy. Users can choose the model that best suits their needs based on response time and accuracy.

  • What is the role of the JSON config file in Continue?

    -The JSON config file in Continue allows users to add any model available with Ollama, providing flexibility in selecting the desired model for code suggestions.

  • What are some other VS Code extensions similar to Llama Coder and Continue?

    -Other VS Code extensions similar to Llama Coder and Continue include Code GPT and Ollama Autocoder. These extensions offer different features and capabilities to assist in coding.

  • What is the significance of offline capabilities for a coder living on an island near Seattle?

    -Offline capabilities are significant for a coder living on an island near Seattle because the journey to the mainland involves a ferry ride where there is no cell service. Being able to code effectively without an internet connection ensures productive use of time during such travel.

Outlines

00:00

🚀 Introduction to Ollama Node.js Library and Llama Coder

The speaker introduces the Ollama Node.js library and shares their intention to start building with it and its Python equivalent. They demonstrate the use of the library by importing it and calling the chat endpoint with a system prompt and initial question. The output is initially a JSON blob, which is received after the full response. The speaker then discusses the benefits of streaming responses and the error encountered when trying to use an async generator. They mention the use of Llama Coder, an alternative to Copilot, and its ability to autocomplete code based on typed comments. The speaker also talks about the process of refining the output to display tokens without newlines and the role of Continue.dev in assisting with coding questions.

Mindmap

Keywords

💡Ollama

Ollama refers to an AI platform mentioned in the script that has recently released an official Node.js library. This library is a collection of tools and modules that allow developers to integrate Ollama's functionalities into their applications. It is central to the video's theme as the speaker discusses their experience with this library and its capabilities.

💡GitHub

GitHub is a web-based hosting service for version control and collaboration that is used by developers to store and manage their code. In the context of the video, the speaker mentions finding the Ollama Node.js library on GitHub, indicating it as a source for accessing the tools they intend to use.

💡Python

Python is a high-level, interpreted programming language known for its readability and ease of use. The speaker mentions the Python equivalent, suggesting they are looking forward to working with both Node.js and Python versions of the Ollama library, highlighting the importance of cross-language compatibility in their work.

💡Chat Endpoint

A chat endpoint refers to a specific location in a network where messages are sent and received, typically used in the context of chatbots or messaging applications. In the script, the speaker calls the chat endpoint with a system prompt and an initial question, demonstrating how to interact with the Ollama service.

💡JSON

JSON, or JavaScript Object Notation, is a lightweight data interchange format that is easy for humans to read and write and for machines to parse and generate. The speaker mentions that the chat endpoint's default response is a JSON blob, which contains data and metrics about the interaction's performance.

💡Streaming

In the context of computing, streaming refers to the continuous delivery of data, often used for media content like audio and video. The speaker discusses the benefits of enabling streaming in their code, as it allows for a more immediate and interactive experience with the data being processed.

💡Async Generator

An async generator is a type of iterator in JavaScript that yields values asynchronously, allowing for the generation of a sequence of values over time. The speaker encounters an error when setting stream to true because it changes the function's return type to an async generator, requiring a different handling approach in their code.

💡Llama Coder

Llama Coder is an AI-powered coding assistant mentioned in the script, which helps developers by providing code suggestions or autocompletion based on the context. The speaker uses Llama Coder to enhance their coding experience and mentions its effectiveness in writing code for them.

💡Continue.dev

Continue.dev is an AI-powered platform for developers that provides real-time assistance and knowledge, helping to solve coding problems. The speaker uses it to find an alternative to console.log that doesn't add a newline, showcasing its utility in addressing specific coding questions.

💡process.stdout.write

process.stdout.write is a method in Node.js used for writing data to the standard output (stdout) without adding a newline character. The speaker uses this method to print the tokens without newlines, demonstrating a solution to their problem of managing output formatting.

💡VS Code Extensions

VS Code Extensions are add-ons that enhance the functionality of Visual Studio Code, a popular code editor. The script mentions Llama Coder and Continue as extensions that the speaker finds beneficial for their coding workflow, providing a local alternative to online services like Copilot.

Highlights

The Ollama team has released an official Node.js library for Ollama, which is available on GitHub.

The user plans to start building with the Node.js library and its Python equivalent soon.

The chat endpoint of Ollama can be called with a system prompt and an initial question.

By default, the chat endpoint does not stream, resulting in a JSON blob with output and performance metrics.

Setting the stream to true changes the function to return an async generator instead of a JSON blob, requiring a different handling method.

The user utilizes Llama Coder, an alternative to Copilot, which auto-completions code snippets based on typed prompts.

Llama Coder is not perfect but provides a good starting point for coding.

Continue.dev is a platform that allows users to ask coding-related questions and receive answers.

process.stdout.write is an alternative to console.log that doesn't add a newline, which can be useful for certain coding scenarios.

The user mentions living on an island near Seattle and coding on a ferry without internet, highlighting the offline utility of these tools.

Ollama needs to be installed and running to use the Node.js library and Llama Coder extension.

The Llama Coder extension offers different models to choose from, with Deepseek Coder 1.3b q4 being a fast and efficient option.

Continue.dev has no upfront settings but allows users to select the model to use and disable telemetry for offline use.

Other VS Code extensions like Code GPT and Ollama Autocoder are available, but Llama Coder and Continue seem to be the most suitable for the user's needs.

The user expresses interest in trying out Cody from Sourcegraph and is open to suggestions for other configurations.

The user invites viewers to share their setups and experiences with local alternatives to Copilot.

The video aims to provide insights into the use of local coding tools as an alternative to cloud-based services like Copilot.