File tree Expand file tree Collapse file tree 4 files changed +48
-21
lines changed Expand file tree Collapse file tree 4 files changed +48
-21
lines changed Original file line number Diff line number Diff line change
1
+ echo " Building for Linux.."
2
+ GOOS=linux GOARCH=amd64 go build -o oa-helper_linux_amd64 .
3
+ GOOD=linux GOARCH=arm64 go build -o oa-helper_linux_arm64 .
4
+ echo " Building for Windows.."
5
+ GOOS=windows GOARCH=amd64 go build -o oa-helper_windows_amd64.exe .
6
+ echo " Building for Mac.."
7
+ GOOS=darwin GOARCH=amd64 go build -o oa-helper_darwin_amd64 .
8
+ GOOS=darwin GOARCH=arm64 go build -o oa-helper_darwin_arm64 .
Original file line number Diff line number Diff line change @@ -16,32 +16,19 @@ func main() {
16
16
panic (err )
17
17
}
18
18
InitChatGPTClient (model .Conf .ApiKey )
19
+ i := 0
19
20
for true {
20
21
err = StartTask ()
21
22
if err != nil {
22
23
logx .Error ("Error while doing task: " , err )
23
24
}
25
+ if i ++ ; i == 10 {
26
+ i = 0
27
+ err = RefreshCookie ()
28
+ if err != nil {
29
+ logx .Error ("Error while refreshing cookie: " , err )
30
+ }
31
+ }
24
32
time .Sleep (2 * time .Second )
25
33
}
26
- // s, err := GetLabelsFromChatGPT(`{
27
- // "spam": 0,
28
- // "fails_task": 0,
29
- // "lang_mismatch": 0,
30
- // "not_appropriate": 0,
31
- // "pii": 0,
32
- // "hate_speech": 0,
33
- // "sexual_content": 0,
34
- // "quality": 0.75,
35
- // "helpfulness": 1,
36
- // "creativity": 0.5,
37
- // "humor": 0,
38
- // "toxicity": 0,
39
- // "violence": 0
40
- // }`)
41
- // if err != nil {
42
- // panic(err)
43
- // }
44
- // for l, v := range s {
45
- // println(l, " ", v)
46
- // }
47
34
}
Original file line number Diff line number Diff line change @@ -95,3 +95,16 @@ func LoadConfig() error {
95
95
96
96
return nil
97
97
}
98
+
99
+ func UpdateCookie (cookie string ) error {
100
+ Conf .OaCookie = cookie
101
+ file , err := json .MarshalIndent (Conf , "" , " " )
102
+ if err != nil {
103
+ return err
104
+ }
105
+ err = os .WriteFile ("config.json" , file , 0644 )
106
+ if err != nil {
107
+ return err
108
+ }
109
+ return nil
110
+ }
Original file line number Diff line number Diff line change 7
7
"github.com/zeromicro/go-zero/core/jsonx"
8
8
"github.com/zeromicro/go-zero/core/logx"
9
9
"open-assistant-helper-go/model"
10
+ "strings"
10
11
)
11
12
12
13
var rty = resty .New ()
@@ -28,6 +29,24 @@ func CancelTask(id string) error {
28
29
return nil
29
30
}
30
31
32
+ func RefreshCookie () error {
33
+ logx .Infof ("RefreshCookie" )
34
+ resp , err := rty .R ().
35
+ SetHeaders (map [string ]string {
36
+ "cookie" : model .Conf .OaCookie ,
37
+ }).
38
+ Get ("https://open-assistant.io/api/auth/session" )
39
+ if err != nil {
40
+ return err
41
+ }
42
+ cs := resp .Header ()["Set-Cookie" ]
43
+ if len (cs ) == 0 {
44
+ return fmt .Errorf ("no cookie" )
45
+ }
46
+ c := strings .Join (cs , "" )
47
+ return model .UpdateCookie (c )
48
+ }
49
+
31
50
func GetLabelsFromChatGPT (resp string ) (map [model.OALabel ]float32 , error ) {
32
51
var j map [string ]interface {}
33
52
err := jsonx .Unmarshal ([]byte (resp ), & j )
You can’t perform that action at this time.
0 commit comments