Repository: ollama/ollama
File: llm/llama.go (Go)

Code before:
			path.Join(buildPath, "cpu", "bin", "server"),
		}
	}

	// copy the files locally to run the llama.cpp server
	tmpDir, err := os.MkdirTemp("", "llama-*")
	if err != nil {
		log.Fatalf("load llama runner: failed to create temp dir: %v", err)
	}
	runnerAvailable := false // if no runner files are found in the embed, this flag will cause a fast fail
	for _, f := range files {
		if _, err := fs.Stat(llamaCppEmbed, f); err != nil {
			// this is expected, ollama may be compiled without all runners packed in
			log.Printf("%s runner not found: %v", f, err)
			continue
		}
		runnerAvailable = true

		srcFile, err := llamaCppEmbed.Open(f)
		if err != nil {
			log.Fatalf("read llama runner %s: %v", f, err)
		}
		defer srcFile.Close()

		// create the directory in case it does not exist
		destPath := filepath.Join(tmpDir, strings.TrimPrefix(f, buildPath))
		if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
			log.Fatalf("create runner temp dir %s: %v", filepath.Dir(f), err)
		}
		destFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
		if err != nil {
			log.Fatalf("write llama runner %s: %v", f, err)
		}
		defer destFile.Close()

		if _, err := io.Copy(destFile, srcFile); err != nil {
			log.Fatalf("copy llama runner %s: %v", f, err)
		}
	}
	if !runnerAvailable {
		log.Fatalf("%s runner not found", runnerType)
	}

	// return the runners to try in priority order
	switch runtime.GOOS {
	case "darwin":
		return []ModelRunner{
			{Path: path.Join(tmpDir, "metal", "bin", "server")},
			{Path: path.Join(tmpDir, "cpu", "bin", "server")},
		}
	case "linux":

Review comment (suggestion):
Is it necessary to preserve part of the path? I would imagine `filepath.Dir` would be sufficient for most cases.

Code after:
				path.Join(buildPath, "cpu", "bin", "server"),
			}
		}
	case "windows":
		// TODO: select windows GPU runner here when available
		runners = []string{
			path.Join(buildPath, "cpu", "bin", "Release", "server.exe"),
		}
	default:
		log.Printf("unknown OS, running on CPU: %s", runtime.GOOS)
		runners = []string{
			path.Join(buildPath, "cpu", "bin", "server"),
		}
	}

	// copy the files locally to run the llama.cpp server
	tmpDir, err := os.MkdirTemp("", "llama-*")
	if err != nil {
		log.Fatalf("load llama runner: failed to create temp dir: %v", err)
	}
	runnerAvailable := false // if no runner files are found in the embed, this flag will cause a fast fail
	for _, r := range runners {
		// find all the files in the runner's bin directory
		files, err := fs.Glob(llamaCppEmbed, filepath.Join(filepath.Dir(r), "*"))
		if err != nil {
			// this is expected, ollama may be compiled without all runners packed in
			log.Printf("%s runner not found: %v", r, err)
			continue
		}
		runnerAvailable = true

		for _, f := range files {
			srcFile, err := llamaCppEmbed.Open(f)
			if err != nil {
				log.Fatalf("read llama runner %s: %v", f, err)
			}
			defer srcFile.Close()

			// create the directory in case it does not exist
			destPath := filepath.Join(tmpDir, filepath.Dir(f))
			if err := os.MkdirAll(destPath, 0o755); err != nil {
				log.Fatalf("create runner temp dir %s: %v", filepath.Dir(f), err)
			}
			destFile, err := os.OpenFile(filepath.Join(destPath, filepath.Base(f)), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
			if err != nil {
				log.Fatalf("write llama runner %s: %v", f, err)
			}
			defer destFile.Close()

			if _, err := io.Copy(destFile, srcFile); err != nil {
				log.Fatalf("copy llama runner %s: %v", f, err)