Skip to content

Commit c664db4

Browse files
committed
Hello AI world
1 parent bde4ffe commit c664db4

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

coderd/aistart/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package aistart implements an experimental AI-based auto-start.
2+
package aistart

scripts/aistart/loadcsv.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"fmt"
6+
"os"
7+
"time"
8+
9+
"github.com/coder/flog"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
func connectDB() (*sql.DB, error) {
14+
const envKey = "POSTGRES_URL"
15+
url := os.Getenv(envKey)
16+
if url == "" {
17+
return nil, fmt.Errorf("no $%v provided", envKey)
18+
}
19+
20+
return sql.Open("postgres", url)
21+
}
22+
23+
func loadTrainingCSV() *cobra.Command {
24+
return &cobra.Command{
25+
Use: "load-training-csv",
26+
RunE: func(cmd *cobra.Command, args []string) error {
27+
db, err := connectDB()
28+
if err != nil {
29+
return err
30+
}
31+
const q = `SELECT
32+
date_trunc('hour', created_at) at_hour
33+
FROM
34+
agent_stats
35+
GROUP BY
36+
workspace_id, at_hour;
37+
`
38+
rows, err := db.Query(q)
39+
if err != nil {
40+
return err
41+
}
42+
43+
var times []time.Time
44+
for rows.Next() {
45+
var t time.Time
46+
err = rows.Scan(&t)
47+
if err != nil {
48+
return nil
49+
}
50+
times = append(times, t)
51+
}
52+
flog.Info("times: %+v", times)
53+
return nil
54+
},
55+
}
56+
}

scripts/aistart/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/coder/coder/cli"
10+
)
11+
12+
func main() {
13+
cmd := &cobra.Command{
14+
Use: "aistart",
15+
Long: "A tool for experimenting with our AIstart implementation",
16+
}
17+
18+
cmd.AddCommand(loadTrainingCSV())
19+
20+
cmd, err := cmd.ExecuteC()
21+
if err != nil {
22+
cobraErr := cli.FormatCobraError(err, cmd)
23+
_, _ = fmt.Fprintln(os.Stderr, cobraErr)
24+
os.Exit(1)
25+
}
26+
}

0 commit comments

Comments
 (0)