[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-run-local-llm-ollama-golang-guide-all--*":3,"academy-blog-translations-v9902nhg6spnu8l":88},{"data":4,"page":74,"perPage":74,"totalItems":74,"totalPages":74},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":82,"keywords":83,"locale":55,"published_at":84,"scheduled_at":13,"school_blog":78,"short_description":85,"status":76,"title":86,"updated":87,"updated_by":13,"slug":79,"views":81},"Step-by-step guide to installing Ollama and connecting Go with Local LLM (Llama 3)","sclblg987654321","school_blog_translations","\u003Cp>In our previous episode, we explored how to connect to GPT-4o via Cloud APIs. However, for projects that demand high privacy or long-term cost control, \u003Cstrong>Local LLMs\u003C\u002Fstrong> are the ideal solution. Today, we’re going to transform your computer into a private AI server using \u003Cstrong>Ollama\u003C\u002Fstrong>—a tool that stands out for being free to run, keeping your data secure, and functioning even without an internet connection.\u003C\u002Fp>\u003Ch2>How to Install Ollama on Windows\u002FMac to Run AI Models Locally\u003C\u002Fh2>\u003Cp>\u003Cstrong>Ollama\u003C\u002Fstrong> is currently the easiest tool for downloading and running Large Language Models (LLMs) such as \u003Cstrong>Llama 3, Mistral, or Phi-3\u003C\u002Fstrong>. It handles all the background library complexities, allowing us to focus entirely on building our applications.\u003C\u002Fp>\u003Ch3>Installation Steps:\u003C\u002Fh3>\u003Col>\u003Cli>\u003Cp>\u003Cstrong>Download:\u003C\u002Fstrong> Visit \u003Ca rel=\"noopener noreferrer\" href=\"http:\u002F\u002Follama.com\">ollama.com\u003C\u002Fa> to download the installer (supports macOS, Linux, and Windows).\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Install:\u003C\u002Fstrong> Run the installer and follow the standard installation process.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Run Model:\u003C\u002Fstrong> Open your Terminal and type the command to download and run your desired model:\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Fol>\u003Cp>Bash\u003C\u002Fp>\u003Cpre>\u003Ccode>ollama run llama3\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>\u003Cstrong>Note:\u003C\u002Fstrong> The first time you run this command, the system will download the model to your machine (approximately 4.7GB for Llama 3 8B). Once the download is complete, you can start chatting with the AI directly through your Terminal.\u003C\u002Fp>\u003Ch2>Connecting Ollama with Go: Commanding AI via Code\u003C\u002Fh2>\u003Cp>Once Ollama is installed, it automatically runs an \u003Cstrong>API Server\u003C\u002Fstrong> on port \u003Ccode>11434\u003C\u002Fcode> (localhost:11434). This allows us to write Go programs to interact with the model immediately.\u003C\u002Fp>\u003Cp>While you could write custom \u003Ccode>net\u002Fhttp\u003C\u002Fcode> calls to hit the API directly, we will use the official Ollama library for speed, organization, and to keep our code looking like a true Gopher.\u003C\u002Fp>\u003Ch3>Library Installation\u003C\u002Fh3>\u003Cp>Run this command in your terminal to install the official Ollama SDK:\u003C\u002Fp>\u003Cp>Bash\u003C\u002Fp>\u003Cpre>\u003Ccode>go get github.com\u002Follama\u002Follama\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>Code Example: Prompting the Model (Streaming)\u003C\u002Fh3>\u003Cp>The core of the Ollama SDK in Go is the \u003Ccode>Generate\u003C\u002Fcode> function, which uses a \u003Cstrong>Callback Function\u003C\u002Fstrong> to handle real-time data.\u003C\u002Fp>\u003Cp>Go\u003C\u002Fp>\u003Cpre>\u003Ccode>package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com\u002Follama\u002Follama\u002Fapi\"\n)\n\nfunc main() {\n\t\u002F\u002F 1. Create a client to connect to Ollama (automatically pulls from environment)\n\tclient, err := api.ClientFromEnvironment()\n\tif err != nil {\n\t\tlog.Fatal(\"Could not connect to Ollama:\", err)\n\t}\n\n\tctx := context.Background()\n\n\t\u002F\u002F 2. Define the request details\n\treq := &amp;api.GenerateRequest{\n\t\tModel:  \"llama3\", \u002F\u002F Specify the model name downloaded on your machine\n\t\tPrompt: \"Why is Docker important for AI work? Summarize briefly.\",\n\t}\n\n\t\u002F\u002F 3. Callback function to handle the streaming response\n\trespFunc := func(resp api.GenerateResponse) error {\n\t\t\u002F\u002F Print each response chunk immediately as it arrives\n\t\tfmt.Print(resp.Response)\n\t\treturn nil\n\t}\n\n\t\u002F\u002F 4. Send the request to the model\n\terr = client.Generate(ctx, req, respFunc)\n\tif err != nil {\n\t\tfmt.Println(\"\\nAn error occurred:\", err)\n\t}\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>Why use this approach?\u003C\u002Fh3>\u003Cul>\u003Cli>\u003Cp>\u003Cstrong>api.ClientFromEnvironment():\u003C\u002Fstrong> Highly convenient as it automatically locates the Ollama service running on your machine without needing to manually specify the IP or Port.\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>respFunc:\u003C\u002Fstrong> The Ollama SDK is designed for streaming by default. Using this callback function ensures your application feels \"smooth\" and responsive, as it displays the AI's output piece by piece rather than waiting for the entire generation to finish.\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>Local vs. Cloud: Comparing Ollama and OpenAI—Which One Should You Choose?\u003C\u002Fh2>\u003Cp>Deciding whether to run a model locally (\u003Cstrong>Ollama\u003C\u002Fstrong>) or use an external service (\u003Cstrong>OpenAI\u003C\u002Fstrong>) doesn't have a single \"right\" answer. It depends entirely on the requirements of your specific project. Here is a head-to-head comparison to help you decide.\u003C\u002Fp>\u003Ctable style=\"min-width: 75px;\">\u003Ccolgroup>\u003Ccol style=\"min-width: 25px;\">\u003Ccol style=\"min-width: 25px;\">\u003Ccol style=\"min-width: 25px;\">\u003C\u002Fcolgroup>\u003Ctbody>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Feature\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Local LLM (Ollama)\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Cloud API (OpenAI)\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Cost\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Free\u003C\u002Fstrong> (No subscription or token fees)\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Pay-as-you-go based on \u003Cstrong>Tokens\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Privacy\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Maximum\u003C\u002Fstrong> (Data stays 100% on your machine)\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Data is processed on the Cloud\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Internet\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Offline\u003C\u002Fstrong> (No connection required)\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Constant, stable connection required\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Performance\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Dependent on your \u003Cstrong>GPU\u002FRAM\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Dependent on internet and server load\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Intelligence\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Moderate (Depends on the model size)\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Very High\u003C\u002Fstrong> (Access to massive models)\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Scalability\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>Hard (Requires hardware upgrades)\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Very Easy\u003C\u002Fstrong> (Just request more quota)\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Ch3>💡 Quick Summary for Decision Making:\u003C\u002Fh3>\u003Cul>\u003Cli>\u003Cp>\u003Cstrong>Choose Local (Ollama) when:\u003C\u002Fstrong> You are working on projects with highly sensitive data (e.g., customer records, internal accounting), want to save on long-term costs, and have access to decent hardware (especially a dedicated GPU).\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Choose Cloud (OpenAI) when:\u003C\u002Fstrong> You need the highest possible intelligence (complex reasoning), want to avoid server setup\u002Fmaintenance, or are building an app for a large number of concurrent users (\u003Cstrong>High Scalability\u003C\u002Fstrong>).\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Ch2>🎯 Daily Mission\u003C\u002Fh2>\u003Cp>To see this in action, I want everyone to try installing \u003Cstrong>Ollama\u003C\u002Fstrong> and downloading a \"Small Language Model\" (SLM) that isn't too hardware-demanding, such as \u003Cstrong>phi3\u003C\u002Fstrong> or \u003Cstrong>gemma:2b\u003C\u002Fstrong>.\u003C\u002Fp>\u003Ch3>Homework Challenge:\u003C\u002Fh3>\u003Cp>Modify the Go code from the previous section to accept input via the Command Line using \u003Ccode>os.Args\u003C\u002Fcode>. This will allow you to pass your questions directly when running the program.\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp>\u003Cstrong>Goal:\u003C\u002Fstrong> You should be able to run: \u003Ccode>go run main.go \"Summarize Go's top 3 features\"\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>Tip:\u003C\u002Fstrong> Don't forget to check the number of arguments (using \u003Ccode>len(os.Args)\u003C\u002Fcode>) to prevent the program from crashing (Panic) if the user forgets to type a question!\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cdiv data-type=\"horizontalRule\">\u003Chr>\u003C\u002Fdiv>\u003Ch2>Conclusion: A Major Step Towards Autonomous AI\u003C\u002Fh2>\u003Cp>Choosing Ollama paired with Go is about more than just cost-cutting. It’s about opening the door to building applications that are truly portable and 100% secure. Even in a world without an internet connection, your application remains intelligent and ready to serve your users at all times.\u003C\u002Fp>\u003Cp>However, there is no perfect choice between Local and Cloud. As programmers, our responsibility is to select the right tool for the specific problem at hand and extract the maximum performance from it.\u003C\u002Fp>\u003Ch3>Coming Up Next | EP.146: Prompt Engineering for Gophers — Mastering AI Commands\u003C\u002Fh3>\u003Cp>Whether you choose a world-class model like GPT-4o or a local model via Ollama, the single factor that determines if the AI is worth its cost is the Prompt.\u003C\u002Fp>\u003Cp>In the next episode, we’ll move beyond just connecting to commanding. We will dive deep into Prompt Engineering within code—techniques to control output precision and push the AI's efficiency to its absolute limit!\u003C\u002Fp>\u003Cp>\u003Cstrong>Follow Superdev Academy on all platforms:\u003C\u002Fstrong>\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp>\u003Cstrong>🔵 Facebook: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\">\u003Cstrong>Superdev Academy Thailand\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>🎬 YouTube: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.youtube.com\u002F@SuperdevAcademy\">\u003Cstrong>Superdev Academy Channel\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>📸 Instagram: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevacademy\u002F\">\u003Cstrong>@superdevacademy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">\u003Cstrong>@superdevacademy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fsuperdevacademy.com\">\u003Cstrong>superdevacademy.com\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003C\u002Fp>","10k03mtw8t60_mofaxqt0qk.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fk2n1r9yfpi15c4a\u002F10k03mtw8t60_mofaxqt0qk.png","2026-05-19 07:49:32.045Z","",{"keywords":15,"locale":49,"school_blog":59},[16,23,27,31,36,41,45],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-04-08 03:39:24.854Z","9a3wamff29x0joy","Ollama","2026-04-10 16:14:47.753Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":24,"updated_by":13},"2026-05-19 07:37:17.692Z","fl65uctzhsh7hv2","Local LLM",{"collectionId":17,"collectionName":18,"created":28,"created_by":13,"id":29,"name":30,"updated":28,"updated_by":13},"2026-05-19 07:37:25.747Z","sei8ls8q3fzaqjt","Llama 3",{"collectionId":17,"collectionName":18,"created":32,"created_by":13,"id":33,"name":34,"updated":35,"updated_by":13},"2026-03-04 08:20:14.253Z","ah6lvy4x8qe08l5","Golang","2026-04-10 16:07:26.172Z",{"collectionId":17,"collectionName":18,"created":37,"created_by":13,"id":38,"name":39,"updated":40,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"collectionId":17,"collectionName":18,"created":42,"created_by":13,"id":43,"name":44,"updated":42,"updated_by":13},"2026-05-19 07:37:47.156Z","5e3gcm3yaz0pk0h","AI Privacy",{"collectionId":17,"collectionName":18,"created":46,"created_by":13,"id":47,"name":48,"updated":46,"updated_by":13},"2026-05-19 07:38:50.563Z","1t6pwzq8qszxfnb","Offline LLM",{"code":50,"collectionId":51,"collectionName":52,"created":53,"flag":54,"id":55,"is_default":56,"label":57,"updated":58},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":60,"collectionId":61,"collectionName":62,"created":63,"expand":64,"id":78,"slug":79,"updated":80,"views":81},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs","2026-05-19 07:38:06.102Z",{"category":65},{"blogIds":66,"collectionId":67,"collectionName":68,"created":69,"created_by":13,"id":60,"image":70,"image_alt":13,"image_path":71,"label":72,"name":73,"priority":74,"publish_at":75,"scheduled_at":13,"status":76,"updated":77,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":73,"th":73},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","v9902nhg6spnu8l","run-local-llm-ollama-golang-guide","2026-05-25 04:18:09.300Z",108,"k2n1r9yfpi15c4a",[20,25,29,33,38,43,47],"2026-05-25 03:18:41.212Z","Learn how to transform your PC into an AI server using Ollama and Go. Build private, cost-effective AI applications without relying on Cloud APIs.","Golang The Series EP.145: How to Run Llama 3 Locally with Ollama and Go","2026-05-25 03:18:41.218Z",{"th":79,"en":79}]