Menu

The Unix Philosophy in Go: An example working with LLMs.

#golang#redditgolang#pipe#using#llms
Reading 0:00
15s threshold

I've been doing experiments using LLMs in Golang since 2024 but last year I stumbled over the Unix Philosophy of creating things that do one thing exceptionally well. The main challenges that I encountered working with LLMs in Go (mostly doing HTTP requests) was chaining tasks and making them composable. So it felt like the right fit to create small programs that could be chained together to produce one output. I discovered the io.Pipe implementation and was excited that Go has already everything I need to implement the chaining inside Go code. The http/net pkg seemed to actually use the Unix Philosophy for middleware as well using http.Handler and http.HandlerFunc. So I took these two concepts and created a simple API for working with llms. See the example bellow:

go client := ollama.New(ollama.WithModel("gemma4:e4b")) pipe.Do(context.Background(), os.Stdin, os.Stdout, llm.Generate(client), ) fmt.Fprintln(os.Stdout)

The example shows a simple pipe that generates text using the given client.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.