feat: Add ChatBot GPT-3 integration (#16)

* Added dependency go-resty

* Configured Parser to read plugin configurations

* Add example ssh with ChatGPT plugin

* Add client ChatBot

* Improve logging

* Add integration with plugin OpenAIChatGPT

* Improve readme with ChatBot Example

* Add contributed ChatGPT question

* Refactoring

* Refactoring and improve unit test
This commit is contained in:
Mario Candela
2022-12-16 23:02:16 +01:00
committed by GitHub
parent 9ddb076621
commit d062435818
9 changed files with 260 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package protocols
import (
"beelzebub/parser"
"beelzebub/plugin"
"beelzebub/tracer"
"fmt"
"github.com/gliderlabs/ssh"
@ -39,6 +40,7 @@ func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parse
})
term := terminal.NewTerminal(sess, buildPrompt(sess.User(), beelzebubServiceConfiguration.ServerName))
var histories []plugin.History
for {
commandInput, err := term.ReadLine()
if err != nil {
@ -64,7 +66,21 @@ func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parse
}
if matched {
term.Write(append([]byte(command.Handler), '\n'))
commandOutput := command.Handler
if command.Plugin == plugin.ChatGPTPluginName {
openAIGPTVirtualTerminal := plugin.OpenAIGPTVirtualTerminal{Histories: histories, OpenAPIChatGPTSecretKey: beelzebubServiceConfiguration.Plugin.OpenAPIChatGPTSecretKey}
openAIGPTVirtualTerminal.InjectDependency()
if commandOutput, err = openAIGPTVirtualTerminal.GetCompletions(commandInput); err != nil {
log.Errorf("Error GetCompletions: %s, %s", commandInput, err.Error())
commandOutput = "command not found"
}
}
histories = append(histories, plugin.History{Input: commandInput, Output: commandOutput})
term.Write(append([]byte(commandOutput), '\n'))
break
}
}