Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor to reduce LOC and keep code DRY. #53

Merged
merged 14 commits into from
Jun 26, 2023
18 changes: 9 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"beelzebub/builder"
"beelzebub/parser"
"flag"
"fmt"

log "github.com/sirupsen/logrus"
)

var quit = make(chan struct{})

func main() {
var configurationsCorePath string
var configurationsServicesDirectory string
var (
quit = make(chan struct{})
configurationsCorePath string
configurationsServicesDirectory string
)

flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
Expand All @@ -22,20 +22,20 @@ func main() {
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)

coreConfigurations, err := parser.ReadConfigurationsCore()
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
failOnError(err, "Error during ReadConfigurationsCore: ")

beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsServices: "))
failOnError(err, "Error during ReadConfigurationsServices: ")

beelzebubBuilder := builder.NewBuilder()

director := builder.NewDirector(beelzebubBuilder)

beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
failOnError(err, fmt.Sprintf("Error during BuildBeelzebub: "))
failOnError(err, "Error during BuildBeelzebub: ")

err = beelzebubBuilder.Run()
failOnError(err, fmt.Sprintf("Error during run beelzebub core: "))
failOnError(err, "Error during run beelzebub core: ")

defer beelzebubBuilder.Close()

Expand Down
15 changes: 9 additions & 6 deletions plugins/openai-gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import (
"errors"
"fmt"
"strings"

log "github.com/sirupsen/logrus"

"github.com/go-resty/resty/v2"
)

const ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
const openAIGPTEndpoint = "https://api.openai.com/v1/completions"
const (
// Reference: https://www.engraved.blog/building-a-virtual-machine-inside/
promptVirtualizeLinuxTerminal = "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\n"
chrispaig3 marked this conversation as resolved.
Show resolved Hide resolved
ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
openAIGPTEndpoint = "https://api.openai.com/v1/completions"
)

type History struct {
Input, Output string
}

type OpenAIGPTVirtualTerminal struct {
Histories []History
OpenAPIChatGPTSecretKey string
Expand Down Expand Up @@ -62,7 +66,6 @@ type gptRequest struct {
}

// Reference: https://www.engraved.blog/building-a-virtual-machine-inside/
mariocandela marked this conversation as resolved.
Show resolved Hide resolved
const promptVirtualizeLinuxTerminal = "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\n"

func buildPrompt(histories []History, command string) string {
var sb strings.Builder
Expand Down
10 changes: 4 additions & 6 deletions tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ type Event struct {
Description string
}

type Protocol int
type (
Protocol int
Status int
)

const (
HTTP Protocol = iota
Expand All @@ -42,8 +45,6 @@ func (status Protocol) String() string {
return [...]string{"HTTP", "SSH", "TCP"}[status]
}

type Status int

const (
Start Status = iota
End
Expand Down Expand Up @@ -105,12 +106,9 @@ func (tracer *tracer) TraceEvent(event Event) {
switch event.Protocol {
case HTTP.String():
eventsHTTPTotal.Inc()
break
case SSH.String():
eventsSSHTotal.Inc()
break
case TCP.String():
eventsTCPTotal.Inc()
break
}
}