@hackage / ollama-holes-plugin

A typed-hole plugin that uses LLMs via Ollama to generate valid hole-fits

0.1.0.0

About

Metadata

  • Last updated , by tritlo
  • License MIT
  • Categories Development
  • Maintained by: Matthias Pall Gissurarson <mpg@mpg.is>

  • Lottery factor: 1

Links

Installation

Tested Compilers

  1. 9.6.7
  2. 9.6.6
  3. 9.6.5
  4. 9.6.4
  5. 9.6.3
  6. 9.6.2
  7. 9.6.1

Readme

Ollama Holes

image

Introduction

This is an example of a typed-hole plugin for GHC that uses the Ollama to host a local LLM to fill in holes in Haskell code.

Example

Given

{-# OPTIONS_GHC -fplugin=GHC.Plugin.OllamaHoles #-}
{-# OPTIONS_GHC -fplugin-opt=GHC.Plugin.OllamaHoles:model=gemma3:27b #-}
{-# OPTIONS_GHC -fplugin-opt=GHC.Plugin.OllamaHoles:n=5 #-}

module Main where

import Data.List


main :: IO ()
main = do let k = (_b :: [Int] -> [String])
          print (k [1,2,3])

We get the following output:

    Main.hs:12:20: error: [GHC-88464]
        • Found hole: _b :: [Int] -> [String]
        Or perhaps ‘_b’ is mis-spelled, or not in scope
        • In the expression: _b :: [Int] -> [String]
        In an equation for ‘k’: k = (_b :: [Int] -> [String])
        In the expression:
            do let k = (_b :: [Int] -> [String])
            print (k [1, 2, ....])
        • Relevant bindings include
            k :: [Int] -> [String] (bound at Main.hs:12:15)
            main :: IO () (bound at Main.hs:12:1)
        Valid hole fits include
            \x -> map show x
            map (show)
            \x -> map (\y -> "Number: " ++ show y) x
            \x -> replicate (length x) "Hello"
            []
    |
    12 | main = do let k = (_b :: [Int] -> [String])
    |                    ^^
    Error: cabal: Failed to build exe:main from OllamaHolesTest-1.0.0.

Installation

  1. Install Ollama
  2. Install the gemma3:27b model (or any other model you prefer) using the following command:

ollama pull gemma3:27b
  1. Clone this repository and navigate to the directory, and build the project using:
cabal build
  1. Run the example using:
cabal build Test
  1. Enjoy! If you want to change the underlying model, make sure to pass the model name via the plugin arguments (see example)