package main import ( "bytes" "context" "encoding/json" "fmt" "html/template" "os" "os/signal" "strings" "syscall" "google.golang.org/genai" ) func main() { ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT) defer can() if err := run(ctx, os.Args[1]); err != nil && ctx.Err() == nil { panic(err) } } func run(ctx context.Context, city string) error { city = strings.Title(city) client, err := genai.NewClient(ctx, nil) if err != nil { return err } descriptors := []string{ `Literally poison in the air that politicians are adamant against doing anything to mitigate`, `Drought worst-case`, `Wildfire risk`, `Hurricane`, `Earthquake`, `Tornado`, `Crime`, `Consistent Air Pollution`, `Transient Air Pollution (from wildfires, etc)`, `Colorado river distribution conflict / reduced capacity`, `PFAS`, `Homelessness`, `Neighbors disappointed in church attendance`, `Hot`, `Personal gripes`, `Alcohol universal`, `Few traffic destination hubs`, `Popularity of booze`, `Tourist destination (eg Branson-like)`, `Weed universal`, `Greater cost of living than Utah`, `Traffic >= Bend at 3k/sqmi`, `Lots of schools`, `Coffee shops`, `Yummy resturaunts`, `Board game stores`, `Home for < 400k`, `20min drive to fun`, `Would we get out and be active? Bike++`, `Close airport`, `DnD Players`, `Trees!`, `Population is college educated`, `Home for < 600k`, `Software developers per capita`, `Fiber-speed internet`, `Organic Groceries`, `Close hospital for emergency situations`, `Home for < 800`, `Hematologist reasonably close`, `Does it have the vibes?`, `Concrete Jungle`, } tmpl, err := template.New("tmpl").Parse(` For the city {{.City}}, answer the following descriptors '1' for true or '0' for false. Output only a JSON object mapping descriptors to answers. {{ range .Descriptors -}} * {{ . }} {{ end }} `) if err != nil { return err } w := bytes.NewBuffer(nil) if err := tmpl.Execute(w, map[string]any{ "City": city, "Descriptors": descriptors, }); err != nil { return err } //panic(w.String()) result, err := client.Models.GenerateContent( ctx, "gemini-2.5-flash", genai.Text(w.String()), nil, ) if err != nil { return err } text := "{" + strings.Split(strings.Split(result.Text(), "{")[1], "}")[0] + "}" var m map[string]any if err := json.Unmarshal([]byte(text), &m); err != nil { return err } for _, d := range descriptors { if _, ok := m[d]; !ok { return fmt.Errorf("desc %q missing", d) } } //log.Println(text) for _, d := range descriptors { fmt.Println(m[d]) } return ctx.Err() }