< up >
2024-02-26

Ollama and codelama - enter the AI rabbit hole

Ollama makes using models like codellama as easy to use as containers. I stumpled over it on hacker news and was cruious if it was as easy as claimed.

Getting started

  1. download and install ollama:
    • Linux: curl -fsSL https://ollama.com/install.sh | sh
    • others: Download page
  2. pull e.g. Meta’s codellama model: ollama pull codellama
  3. run prompt: ollama run codellama

Prompts

To improve readability and transparence, prompts are written as citation and answers with italic letters (if not code blocks), like this:

Prompt

Answer…

code

More answes

Port scanner

Write a go program that checks all well-known tcp ports below 100 if they are open.

Here is an example Go program that checks all TCP ports below 100 on the local machine to see if they are open:

package main

import (
	"fmt"
	"net"
)

func main() {
	for port := 1; port < 100; port++ {
		addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf(":%d", port))
		if err != nil {
			fmt.Println(err)
			continue
		}

		conn, err := net.DialTCP("tcp", nil, addr)
		if err == nil {
			fmt.Printf("%d is open\n", port)
			conn.Close()
		} else {
			fmt.Printf("%d is closed\n", port)
		}
	}
}

This program uses the net package to create a TCP connection on each port in the range [1, 100). If the connection succeeds, the port is considered open and the program prints a message indicating so. If the connection fails or times out, the port is considered closed and the program prints a message indicating so.

Note that this program will only work if you have permission to create a TCP connection on each port in the range. Additionally, this program will not check for any firewall rules or other network restrictions that may prevent you from creating a connection on certain ports.

Remarks

Further reading