From 4dbbd9afd29ff8a46571e0deaa680cc6645f8d21 Mon Sep 17 00:00:00 2001 From: atomy Date: Tue, 7 Mar 2023 03:30:17 +0100 Subject: [PATCH 1/6] tweak --- utils/utils.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 1bfac7a..99fa047 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -171,7 +171,7 @@ func GetCommandAndArgs(content string) (string, string) { func AddPlayer(players *[]string, elem string) { if !SliceContains(*players, elem) { *players = append(*players, elem) - fmt.Println("adding:", elem, *players) + //fmt.Println("adding:", elem, *players) } } @@ -184,17 +184,6 @@ func SliceContains(slice []string, elem string) bool { return false } -func ExtractUsername(in string) string { - re := regexp.MustCompile(`(\w+)" \[U:\d:[0-9]+\]`) - match := re.FindStringSubmatch(in) - - if len(match) > 1 { - return match[1] - } - - return "" -} - // Check if supplied argument *in* is a chatline, if so, return: , , func GetChatSay(players []string, in string) (bool, string, string) { //fmt.Println("players:", players) From 4b1b6cdedd311cfb474c5e2bc5630628ac04ba57 Mon Sep 17 00:00:00 2001 From: atomy Date: Wed, 8 Mar 2023 02:21:47 +0100 Subject: [PATCH 2/6] shorten gpt response --- gpt/gpt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpt/gpt.go b/gpt/gpt.go index 9cfba9e..236b7d5 100644 --- a/gpt/gpt.go +++ b/gpt/gpt.go @@ -91,7 +91,7 @@ func Ask(question string) { Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, - Content: question, + Content: "Answer in one sentence: " + question, }, }, }, From 3d1386ad1efce25e675e50506f4e6e6ed7daaf49 Mon Sep 17 00:00:00 2001 From: atomy Date: Thu, 16 Mar 2023 02:08:30 +0100 Subject: [PATCH 3/6] added script for starting on dystopia --- runDystopia.bat | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 runDystopia.bat diff --git a/runDystopia.bat b/runDystopia.bat new file mode 100644 index 0000000..5ed0628 --- /dev/null +++ b/runDystopia.bat @@ -0,0 +1,9 @@ +@echo off + +set "MONGODB_URI=mongodb+srv://mongo:yKhJM60c5xITh1yedN81@cluster0.4gjncyl.mongodb.net/?retryWrites=true&w=majority" +#set TF2_LOGPATH=D:\\Program Files (x86)\\Steam\\steamapps\\common\\Team Fortress 2\\tf\\console.log +set TF2_LOGPATH=C:\\Steam\\steamapps\\common\\Dystopia\\dystopia\\console.log +set MONGODB_NAME=TeamFortress2 +set OPENAI_APIKEY=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 + +.\build\main-windows-amd64.exe \ No newline at end of file From cba651e24949f8cdb05028a818ce71e8f0d29725 Mon Sep 17 00:00:00 2001 From: atomy Date: Thu, 16 Mar 2023 03:06:48 +0100 Subject: [PATCH 4/6] improved !gpt command by soft and hard limiting to 121 chars --- commands/commands.go | 8 +++---- gpt/gpt.go | 53 ++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index b9a4aae..6941945 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -14,7 +14,7 @@ var SelfCommandMap = map[string]func(args string){ // Ask gpt API and print reponse "!gpt": func(args string) { fmt.Println(args) - gpt.Ask("In 1 sentence:" + args) + gpt.Ask(args) }, // Just a test command "!test": func(args string) { @@ -38,7 +38,7 @@ var OtherUsersCommandMap = map[string]func(args string){ // Stuff follows the : are only function pointers not function calls // Ask gpt API and print reponse "!gpt": func(args string) { - gpt.Ask("In 1 sentence:" + args) + gpt.Ask(args) }, "!nice": func(args string) { time.Sleep(1000 * time.Millisecond) @@ -74,7 +74,7 @@ func RunCommands(text string, isSelf bool) { } // Command is not configured - fmt.Printf("\nCommand '%s' unconfigured!\n", strings.TrimSuffix(strings.TrimSuffix(command, "\n"), "\r")) + fmt.Printf("\nSelfCommand '%s' unconfigured!\n", strings.TrimSuffix(strings.TrimSuffix(command, "\n"), "\r")) case false: @@ -90,7 +90,7 @@ func RunCommands(text string, isSelf bool) { } // Command is not configured - fmt.Printf("\nCommand '%s' unconfigured!\n", strings.TrimSuffix(strings.TrimSuffix(command, "\n"), "\r")) + fmt.Printf("\nOthersCommand '%s' unconfigured!\n", strings.TrimSuffix(strings.TrimSuffix(command, "\n"), "\r")) } } } diff --git a/gpt/gpt.go b/gpt/gpt.go index 6b9f4f1..693e223 100644 --- a/gpt/gpt.go +++ b/gpt/gpt.go @@ -7,6 +7,7 @@ import ( "tf2-rcon/network" "tf2-rcon/utils" "time" + "strings" openai "github.com/sashabaranov/go-openai" ) @@ -55,9 +56,10 @@ func Ask(question string) { Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, - Content: "Answer in one sentence: " + question, + Content: "Always limit your response to maximum of 121 characters, try to formulate a short answer that always fits that criteria. The question is: " + question, }, }, + MaxTokens: int(121), }, ) @@ -67,33 +69,26 @@ func Ask(question string) { } // Return Content node, remove empty lines from it beforehand - responses := utils.RemoveEmptyLines(resp.Choices[0].Message.Content) - - fmt.Println("!gpt - requesting:", question, "- Response:", responses) - - // Split the original string into chunks of 121 characters, the overall chat-say limit is 126, subtract any chars needed for prefix - // Have at max 2 interations cause we dont want to spam chat - chunk := "" - for i := 0; i < len(responses); i += 121 { - end := i + 121 - - if end > len(responses) { - end = len(responses) - } - - chunk = responses[i:end] - - // If no the 1st try, delay 1000 ms cause else we may get supressed - if i != 0 { - time.Sleep(1000 * time.Millisecond) - - network.RconExecute("say \"GPT> " + chunk + "\"") - break // only execute this once, we dont want to spam - - } - - // on first run only delay 500 ms - time.Sleep(500 * time.Millisecond) - network.RconExecute("say \"GPT> " + chunk + "\"") + responseText := utils.RemoveEmptyLines(resp.Choices[0].Message.Content) + + fmt.Println("!gpt - requesting:", question, "- Response:", responseText) + + // Remove any newlines and limit response to 121 characters + responseText = strings.Replace(responseText, "\n", " ", -1) + if len(responseText) > 121 { + responseText = strings.TrimSpace(responseText)[:121] + lastSpace := strings.LastIndex(responseText, " ") + + if lastSpace != -1 { + responseText = responseText[:lastSpace] + "..." + } else { + responseText += "..." + } + } else { + responseText = strings.TrimSpace(responseText) } + + // on first run only delay 500 ms + time.Sleep(500 * time.Millisecond) + network.RconExecute("say \"GPT> " + responseText + "\"") } From e24cf0b6eceb79b0462a76d0b2f2ae8e2f5aba83 Mon Sep 17 00:00:00 2001 From: atomy Date: Thu, 16 Mar 2023 03:09:54 +0100 Subject: [PATCH 5/6] remove api key, silly me --- .gitignore | 4 +++- runDystopia.bat | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index fb9c560..f3cfe65 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ main sample.txt run2.bat -run2.sh \ No newline at end of file +run2.sh +runDystopia2.bat +runDystopia2.sh \ No newline at end of file diff --git a/runDystopia.bat b/runDystopia.bat index 5ed0628..86238f6 100644 --- a/runDystopia.bat +++ b/runDystopia.bat @@ -1,9 +1,8 @@ @echo off set "MONGODB_URI=mongodb+srv://mongo:yKhJM60c5xITh1yedN81@cluster0.4gjncyl.mongodb.net/?retryWrites=true&w=majority" -#set TF2_LOGPATH=D:\\Program Files (x86)\\Steam\\steamapps\\common\\Team Fortress 2\\tf\\console.log set TF2_LOGPATH=C:\\Steam\\steamapps\\common\\Dystopia\\dystopia\\console.log set MONGODB_NAME=TeamFortress2 -set OPENAI_APIKEY=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 +set OPENAI_APIKEY=xxx .\build\main-windows-amd64.exe \ No newline at end of file From 67236b530c9ef283a2e35f22818942bc0124ec41 Mon Sep 17 00:00:00 2001 From: atomy Date: Thu, 16 Mar 2023 03:11:29 +0100 Subject: [PATCH 6/6] rm mongo --- runDystopia.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runDystopia.bat b/runDystopia.bat index 86238f6..736a175 100644 --- a/runDystopia.bat +++ b/runDystopia.bat @@ -1,6 +1,6 @@ @echo off -set "MONGODB_URI=mongodb+srv://mongo:yKhJM60c5xITh1yedN81@cluster0.4gjncyl.mongodb.net/?retryWrites=true&w=majority" +set "MONGODB_URI=mongodb+srv://mongo:x@x.x.mongodb.net/?retryWrites=true&w=majority" set TF2_LOGPATH=C:\\Steam\\steamapps\\common\\Dystopia\\dystopia\\console.log set MONGODB_NAME=TeamFortress2 set OPENAI_APIKEY=xxx