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
- download and install ollama:
- Linux:
curl -fsSL https://ollama.com/install.sh | sh
- others: Download page
- Linux:
- pull e.g. Meta’s codellama model:
ollama pull codellama
- run prompt:
ollama run codellama
set /verbose
: see some metrics about each promptexplain following riscv bootloader: <paste>
worked pretty well
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
- compiled without any issue
- empty host in
ResolveTCPAddr
“:%d” needed to be set to “127.0.0.1:%d” - dropped else branch to decrease noise