-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcortex.go
More file actions
72 lines (64 loc) · 1.58 KB
/
Copy pathcortex.go
File metadata and controls
72 lines (64 loc) · 1.58 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
package main
import (
"flag"
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/xichan96/cortex/internal/app"
"github.com/xichan96/cortex/internal/config"
)
func chatHandler(c *gin.Context) {
agent := app.NewAgent()
httpTrigger := agent.HttpTrigger(c)
req, err := httpTrigger.GetMessageRequest(c)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
engine, err := agent.Engine(c, req.SessionID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
httpTrigger.ChatAPI(c, engine, req)
}
func streamChatHandler(c *gin.Context) {
agent := app.NewAgent()
httpTrigger := agent.HttpTrigger(c)
req, err := httpTrigger.GetMessageRequest(c)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
engine, err := agent.Engine(c, req.SessionID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
httpTrigger.StreamChatAPI(c, engine, req)
}
func mcpHandler(c *gin.Context) {
agent := app.NewAgent()
mcpTrigger, err := agent.McpTrigger(c)
if err != nil {
return
}
mcpTrigger.Agent()(c)
}
func router(r *gin.Engine) {
r.POST("/chat", chatHandler)
r.POST("/chat/stream", streamChatHandler)
r.Any("/mcp", mcpHandler)
}
func main() {
log.Println("Loading config...")
configPath := flag.String("config", "cortex.yaml", "path to config file")
flag.Parse()
if err := config.Load(*configPath); err != nil {
panic(err)
}
log.Println("Starting Cortex...")
r := gin.Default()
router(r)
r.Run(":5678")
}