-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathserve.go
More file actions
96 lines (79 loc) · 2.56 KB
/
serve.go
File metadata and controls
96 lines (79 loc) · 2.56 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
package cmd
import (
"errors"
"path/filepath"
"github.com/openai/openai-go"
"github.com/spf13/cobra"
"github.com/runmedev/runme/v3/pkg/agent/ai"
"github.com/runmedev/runme/v3/pkg/agent/application"
"github.com/runmedev/runme/v3/pkg/agent/server"
"github.com/runmedev/runme/v3/pkg/agent/tlsbuilder"
)
func NewServeCmd(appName string) *cobra.Command {
cmd := cobra.Command{
Use: "serve",
Short: "Start the Assistant and Runme server",
RunE: func(cmd *cobra.Command, args []string) error {
app := application.NewApp(appName)
// Load the configuration
if err := app.LoadConfig(cmd); err != nil {
return err
}
if err := app.SetupServerLogging(); err != nil {
return err
}
if err := app.SetupOTEL(); err != nil {
return err
}
agentOptions := &ai.AgentOptions{}
if app.AppConfig.CloudAssistant == nil {
return errors.New("cloudAssistant config is required for serve; set cloudAssistant in config.yaml")
}
if err := agentOptions.FromAssistantConfig(*app.AppConfig.CloudAssistant); err != nil {
return err
}
var client *openai.Client
if app.AppConfig.OpenAI == nil {
// OpenAI access tokens will be provided by the client per request.
client = ai.NewClientWithoutKey()
} else {
var err error
client, err = ai.NewClient(*app.AppConfig.OpenAI)
if err != nil {
return err
}
}
agentOptions.Client = client
if app.AppConfig.OpenAI != nil {
agentOptions.OAuthOpenAIOrganization = app.AppConfig.OpenAI.Organization
agentOptions.OAuthOpenAIProject = app.AppConfig.OpenAI.Project
}
agent, err := ai.NewAgent(*agentOptions)
if err != nil {
return err
}
// Setup the defaults for the TLSConfig
if app.AppConfig.AssistantServer.TLSConfig != nil && app.AppConfig.AssistantServer.TLSConfig.Generate {
// Set the default values for the TLSConfig
if app.AppConfig.AssistantServer.TLSConfig.KeyFile == "" {
app.AppConfig.AssistantServer.TLSConfig.KeyFile = filepath.Join(app.AppConfig.GetConfigDir(), tlsbuilder.KeyPEMFile)
}
if app.AppConfig.AssistantServer.TLSConfig.CertFile == "" {
app.AppConfig.AssistantServer.TLSConfig.CertFile = filepath.Join(app.AppConfig.GetConfigDir(), tlsbuilder.CertPEMFile)
}
}
serverOptions := &server.Options{
Telemetry: app.AppConfig.Telemetry,
Server: app.AppConfig.AssistantServer,
IAMPolicy: app.AppConfig.IAMPolicy,
WebApp: app.AppConfig.WebApp,
}
s, err := server.NewServer(*serverOptions, agent)
if err != nil {
return err
}
return s.Run()
},
}
return &cmd
}