mirror of
https://github.com/lyx0/ollama-twitch-bot.git
synced 2024-11-06 18:52:03 +01:00
cleanup
This commit is contained in:
parent
45757905ee
commit
3d9bee1512
4 changed files with 27 additions and 21 deletions
4
Makefile
4
Makefile
|
@ -5,6 +5,10 @@ build:
|
|||
run:
|
||||
./Nourybot.out
|
||||
|
||||
jq:
|
||||
./Nourybot.out | jq
|
||||
|
||||
|
||||
up:
|
||||
docker compose down
|
||||
docker compose build
|
||||
|
|
|
@ -22,7 +22,7 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
if msgLen < 2 {
|
||||
reply = "Not enough arguments provided. Usage: ()gpt <query>"
|
||||
} else {
|
||||
switch app.config.ollamaContext {
|
||||
switch app.cfg.ollamaContext {
|
||||
case "none":
|
||||
app.generateNoContext(message.Channel, message.Message[6:len(message.Message)])
|
||||
return
|
||||
|
|
12
generate.go
12
generate.go
|
@ -41,8 +41,8 @@ func (app *application) chatUserContext(target, username, input string) {
|
|||
olm.Content = input
|
||||
app.userMsgStore[username] = append(app.userMsgStore[username], olm)
|
||||
|
||||
requestBody.Model = app.config.ollamaModel
|
||||
requestBody.System = app.config.ollamaSystem
|
||||
requestBody.Model = app.cfg.ollamaModel
|
||||
requestBody.System = app.cfg.ollamaSystem
|
||||
requestBody.Messages = app.userMsgStore[username]
|
||||
requestBody.Prompt = input
|
||||
requestBody.Stream = false
|
||||
|
@ -89,8 +89,8 @@ func (app *application) chatGeneralContext(target, input string) {
|
|||
olm.Content = input
|
||||
app.msgStore = append(app.msgStore, olm)
|
||||
|
||||
requestBody.Model = app.config.ollamaModel
|
||||
requestBody.System = app.config.ollamaSystem
|
||||
requestBody.Model = app.cfg.ollamaModel
|
||||
requestBody.System = app.cfg.ollamaSystem
|
||||
requestBody.Messages = app.msgStore
|
||||
requestBody.Prompt = input
|
||||
requestBody.Stream = false
|
||||
|
@ -131,8 +131,8 @@ func (app *application) chatGeneralContext(target, input string) {
|
|||
func (app *application) generateNoContext(target, input string) {
|
||||
var requestBody ollamaRequest
|
||||
|
||||
requestBody.Model = app.config.ollamaModel
|
||||
requestBody.System = app.config.ollamaSystem
|
||||
requestBody.Model = app.cfg.ollamaModel
|
||||
requestBody.System = app.cfg.ollamaSystem
|
||||
requestBody.Prompt = input
|
||||
requestBody.Stream = false
|
||||
|
||||
|
|
30
main.go
30
main.go
|
@ -20,14 +20,12 @@ type config struct {
|
|||
type application struct {
|
||||
twitchClient *twitch.Client
|
||||
log *zap.SugaredLogger
|
||||
config config
|
||||
cfg config
|
||||
userMsgStore map[string][]ollamaMessage
|
||||
msgStore []ollamaMessage
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cfg config
|
||||
|
||||
logger := zap.NewExample()
|
||||
defer func() {
|
||||
if err := logger.Sync(); err != nil {
|
||||
|
@ -43,22 +41,24 @@ func main() {
|
|||
sugar.Fatal("Error loading .env")
|
||||
}
|
||||
|
||||
cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
|
||||
cfg.twitchOauth = os.Getenv("TWITCH_OAUTH")
|
||||
cfg.ollamaModel = os.Getenv("OLLAMA_MODEL")
|
||||
cfg.ollamaContext = os.Getenv("OLLAMA_CONTEXT")
|
||||
cfg.ollamaSystem = os.Getenv("OLLAMA_SYSTEM")
|
||||
tc := twitch.NewClient(cfg.twitchUsername, cfg.twitchOauth)
|
||||
//tc := twitch.NewClient(config.twitchUsername, config.twitchOauth)
|
||||
|
||||
userMsgStore := make(map[string][]ollamaMessage)
|
||||
|
||||
app := &application{
|
||||
twitchClient: tc,
|
||||
log: sugar,
|
||||
config: cfg,
|
||||
userMsgStore: userMsgStore,
|
||||
}
|
||||
|
||||
app.cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
|
||||
app.cfg.twitchOauth = os.Getenv("TWITCH_OAUTH")
|
||||
app.cfg.ollamaModel = os.Getenv("OLLAMA_MODEL")
|
||||
app.cfg.ollamaContext = os.Getenv("OLLAMA_CONTEXT")
|
||||
app.cfg.ollamaSystem = os.Getenv("OLLAMA_SYSTEM")
|
||||
|
||||
tc := twitch.NewClient(app.cfg.twitchUsername, app.cfg.twitchOauth)
|
||||
app.twitchClient = tc
|
||||
|
||||
// Received a PrivateMessage (normal chat message).
|
||||
app.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
||||
// roomId is the Twitch UserID of the channel the message originated from.
|
||||
|
@ -81,9 +81,11 @@ func main() {
|
|||
|
||||
app.twitchClient.OnConnect(func() {
|
||||
app.log.Info("Successfully connected to Twitch Servers")
|
||||
app.log.Info("Ollama Context: ", app.config.ollamaContext)
|
||||
app.log.Info("Ollama System: ", app.config.ollamaSystem)
|
||||
|
||||
app.log.Infow("Ollama",
|
||||
"Context: ", app.cfg.ollamaContext,
|
||||
"Model: ", app.cfg.ollamaModel,
|
||||
"System: ", app.cfg.ollamaSystem,
|
||||
)
|
||||
})
|
||||
|
||||
channels := os.Getenv("TWITCH_CHANNELS")
|
||||
|
|
Loading…
Reference in a new issue