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:
|
run:
|
||||||
./Nourybot.out
|
./Nourybot.out
|
||||||
|
|
||||||
|
jq:
|
||||||
|
./Nourybot.out | jq
|
||||||
|
|
||||||
|
|
||||||
up:
|
up:
|
||||||
docker compose down
|
docker compose down
|
||||||
docker compose build
|
docker compose build
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
||||||
if msgLen < 2 {
|
if msgLen < 2 {
|
||||||
reply = "Not enough arguments provided. Usage: ()gpt <query>"
|
reply = "Not enough arguments provided. Usage: ()gpt <query>"
|
||||||
} else {
|
} else {
|
||||||
switch app.config.ollamaContext {
|
switch app.cfg.ollamaContext {
|
||||||
case "none":
|
case "none":
|
||||||
app.generateNoContext(message.Channel, message.Message[6:len(message.Message)])
|
app.generateNoContext(message.Channel, message.Message[6:len(message.Message)])
|
||||||
return
|
return
|
||||||
|
|
12
generate.go
12
generate.go
|
@ -41,8 +41,8 @@ func (app *application) chatUserContext(target, username, input string) {
|
||||||
olm.Content = input
|
olm.Content = input
|
||||||
app.userMsgStore[username] = append(app.userMsgStore[username], olm)
|
app.userMsgStore[username] = append(app.userMsgStore[username], olm)
|
||||||
|
|
||||||
requestBody.Model = app.config.ollamaModel
|
requestBody.Model = app.cfg.ollamaModel
|
||||||
requestBody.System = app.config.ollamaSystem
|
requestBody.System = app.cfg.ollamaSystem
|
||||||
requestBody.Messages = app.userMsgStore[username]
|
requestBody.Messages = app.userMsgStore[username]
|
||||||
requestBody.Prompt = input
|
requestBody.Prompt = input
|
||||||
requestBody.Stream = false
|
requestBody.Stream = false
|
||||||
|
@ -89,8 +89,8 @@ func (app *application) chatGeneralContext(target, input string) {
|
||||||
olm.Content = input
|
olm.Content = input
|
||||||
app.msgStore = append(app.msgStore, olm)
|
app.msgStore = append(app.msgStore, olm)
|
||||||
|
|
||||||
requestBody.Model = app.config.ollamaModel
|
requestBody.Model = app.cfg.ollamaModel
|
||||||
requestBody.System = app.config.ollamaSystem
|
requestBody.System = app.cfg.ollamaSystem
|
||||||
requestBody.Messages = app.msgStore
|
requestBody.Messages = app.msgStore
|
||||||
requestBody.Prompt = input
|
requestBody.Prompt = input
|
||||||
requestBody.Stream = false
|
requestBody.Stream = false
|
||||||
|
@ -131,8 +131,8 @@ func (app *application) chatGeneralContext(target, input string) {
|
||||||
func (app *application) generateNoContext(target, input string) {
|
func (app *application) generateNoContext(target, input string) {
|
||||||
var requestBody ollamaRequest
|
var requestBody ollamaRequest
|
||||||
|
|
||||||
requestBody.Model = app.config.ollamaModel
|
requestBody.Model = app.cfg.ollamaModel
|
||||||
requestBody.System = app.config.ollamaSystem
|
requestBody.System = app.cfg.ollamaSystem
|
||||||
requestBody.Prompt = input
|
requestBody.Prompt = input
|
||||||
requestBody.Stream = false
|
requestBody.Stream = false
|
||||||
|
|
||||||
|
|
30
main.go
30
main.go
|
@ -20,14 +20,12 @@ type config struct {
|
||||||
type application struct {
|
type application struct {
|
||||||
twitchClient *twitch.Client
|
twitchClient *twitch.Client
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
config config
|
cfg config
|
||||||
userMsgStore map[string][]ollamaMessage
|
userMsgStore map[string][]ollamaMessage
|
||||||
msgStore []ollamaMessage
|
msgStore []ollamaMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var cfg config
|
|
||||||
|
|
||||||
logger := zap.NewExample()
|
logger := zap.NewExample()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := logger.Sync(); err != nil {
|
if err := logger.Sync(); err != nil {
|
||||||
|
@ -43,22 +41,24 @@ func main() {
|
||||||
sugar.Fatal("Error loading .env")
|
sugar.Fatal("Error loading .env")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.twitchUsername = os.Getenv("TWITCH_USERNAME")
|
//tc := twitch.NewClient(config.twitchUsername, config.twitchOauth)
|
||||||
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)
|
|
||||||
|
|
||||||
userMsgStore := make(map[string][]ollamaMessage)
|
userMsgStore := make(map[string][]ollamaMessage)
|
||||||
|
|
||||||
app := &application{
|
app := &application{
|
||||||
twitchClient: tc,
|
|
||||||
log: sugar,
|
log: sugar,
|
||||||
config: cfg,
|
|
||||||
userMsgStore: userMsgStore,
|
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).
|
// Received a PrivateMessage (normal chat message).
|
||||||
app.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
app.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
||||||
// roomId is the Twitch UserID of the channel the message originated from.
|
// roomId is the Twitch UserID of the channel the message originated from.
|
||||||
|
@ -81,9 +81,11 @@ func main() {
|
||||||
|
|
||||||
app.twitchClient.OnConnect(func() {
|
app.twitchClient.OnConnect(func() {
|
||||||
app.log.Info("Successfully connected to Twitch Servers")
|
app.log.Info("Successfully connected to Twitch Servers")
|
||||||
app.log.Info("Ollama Context: ", app.config.ollamaContext)
|
app.log.Infow("Ollama",
|
||||||
app.log.Info("Ollama System: ", app.config.ollamaSystem)
|
"Context: ", app.cfg.ollamaContext,
|
||||||
|
"Model: ", app.cfg.ollamaModel,
|
||||||
|
"System: ", app.cfg.ollamaSystem,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
channels := os.Getenv("TWITCH_CHANNELS")
|
channels := os.Getenv("TWITCH_CHANNELS")
|
||||||
|
|
Loading…
Reference in a new issue