-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
152 lines (129 loc) · 3.27 KB
/
main.go
File metadata and controls
152 lines (129 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"os"
"slices"
"github.com/LukasDeco/github-portfolio-generator/netlify"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
var reposOfInterest []string = []string{
"lzw-compress",
"token-buddy",
"slicefuncs",
"lego",
"twilio-rust",
"github-portfolio-generator",
}
func main() {
ctx := context.Background()
err := createPortfolio(ctx, "LukasDeco", "index.html")
if err != nil {
panic(err)
}
fmt.Println("portfolio website generated!")
}
func deployVercel(ctx context.Context, html, website, token string) error {
return nil
}
func createWebsite(ctx context.Context, style string, githubJson []byte) (string, error) {
var html string
prompt := fmt.Sprintf(`
Make a beautiful website. Your code should be visually stunning,
but also intuitive and mobile friendly. Include some animations where appropriate.
Make the cards have a hover box-shadow animation.
Use gradients and fun vector images for some of the elements and background.
Remember to prioritize readability and organization, and to create a polished final product.
Make any links open in a new tab.
Give it a %s style please.
Include the following information from this json in the website.
Just use the json struct to generate the html directly, don't use any JS.
---
%s
`, style, githubJson)
llm, err := openai.New()
if err != nil {
return "", err
}
aiRes, err := llm.Generate(ctx, []string{prompt},
llms.WithTemperature(0.2),
llms.WithMaxTokens(2500),
)
if err != nil {
return "", err
}
if len(aiRes) == 0 {
return "", errors.New("ai response empty")
}
html = aiRes[0].Text
return html, nil
}
func createPortfolio(ctx context.Context, userName, portfolioHtmlFilename string) error {
gitubApiUrl := fmt.Sprintf("https://api.github.com/users/%s", userName)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, gitubApiUrl, nil)
if err != nil {
return err
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
userJson, err := io.ReadAll(res.Body)
if err != nil {
return err
}
// fmt.Println(string(userJson))
var user GithubUser
err = json.Unmarshal(userJson, &user)
if err != nil {
return err
}
repoUrl := fmt.Sprintf("https://api.github.com/users/%s/repos", userName)
req, err = http.NewRequestWithContext(ctx, http.MethodGet, repoUrl, nil)
if err != nil {
return err
}
res, err = http.DefaultClient.Do(req)
if err != nil {
return err
}
repoJson, err := io.ReadAll(res.Body)
if err != nil {
return err
}
var repos []GithubRepo
err = json.Unmarshal(repoJson, &repos)
if err != nil {
return err
}
// fmt.Println(string(repoJson))
var filteredRepos []GithubRepo
for _, r := range repos {
if slices.Contains(reposOfInterest, r.Name) {
filteredRepos = append(filteredRepos, r)
}
}
portfolio := GithubPortfolio{
User: user,
Repos: filteredRepos,
}
portfolioJson, err := json.Marshal(portfolio)
if err != nil {
return err
}
htmlContents, err := createWebsite(ctx, "dark theme with blue oceans", portfolioJson)
if err != nil {
return err
}
err = os.WriteFile(portfolioHtmlFilename, []byte(htmlContents), 0644)
if err != nil {
return err
}
netlify.DeployNetlify(portfolioHtmlFilename)
return nil
}