-
Notifications
You must be signed in to change notification settings - Fork 0
/
parker.go
71 lines (57 loc) · 1.33 KB
/
parker.go
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
package main
import (
"encoding/json"
"io"
"log"
"log/slog"
"net/http"
"github.com/tmc/langchaingo/llms/openai"
)
func main() {
var programLevel = new(slog.LevelVar) // Info by default
// h := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel})
// slog.SetDefault(slog.New(h))
programLevel.Set(slog.LevelDebug)
plugins, err := fetchPlugins("plugins")
if err != nil {
log.Fatal(err)
return
}
corePlugin := getCorePlugin()
actions := make(map[string]Action, 0)
for _, action := range corePlugin.Actions {
actions[action.FunctionDefinition.Name] = action
}
for _, plugin := range plugins {
for _, action := range plugin.Actions {
actions[action.FunctionDefinition.Name] = action
}
}
llm, err := openai.New()
if err != nil {
log.Fatal(err)
}
pm := NewParkerModel(
llm,
actions,
)
closeHandler()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var payload RequestPayload
err := json.NewDecoder(r.Body).Decode(&payload)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
result, err := pm.executeUserInput(payload.Query)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
io.WriteString(w, result)
})
http.ListenAndServe(":8090", nil)
}
type RequestPayload struct {
Query string
}