Skip to content

Commit 47bb30a

Browse files
committed
update change function to retrive conversation and remove gpt response word block filter
1 parent bff754d commit 47bb30a

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ WHASTAPP_GPT_BLOCKED_WORD=
1717
# -----------------------------------
1818
# OpenAI Configuration
1919
# -----------------------------------
20-
OPENAI_HOST=
20+
OPENAI_HOST=https://api.openai.com
2121
OPENAI_HOST_PATH=/v1
2222
OPENAI_API_KEY=
2323
OPENAI_GPT_MODEL_NAME=gpt-3.5-turbo

pkg/gpt/gpt.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func init() {
185185
}
186186
}
187187

188-
func GPT3Response(question string) (response string, err error) {
188+
func GPTResponse(question string) (response string, err error) {
189189
if bool(WAGPTBlockedWordRegex.MatchString(question)) {
190190
return "Sorry, the AI can not response due to it is containing some blocked word 🥺", nil
191191
}
@@ -247,10 +247,6 @@ func GPT3Response(question string) (response string, err error) {
247247
OAIGPTResponseBuffer = strings.TrimLeft(OAIGPTResponseBuffer, ".\n")
248248
OAIGPTResponseBuffer = strings.TrimLeft(OAIGPTResponseBuffer, "\n")
249249

250-
if bool(WAGPTBlockedWordRegex.MatchString(OAIGPTResponseBuffer)) {
251-
return "Sorry, the AI can not response due to it is containing some blocked word 🥺", nil
252-
}
253-
254250
return OAIGPTResponseBuffer, nil
255251

256252
default:
@@ -309,10 +305,6 @@ func GPT3Response(question string) (response string, err error) {
309305
OGPTResponseBuffer = strings.TrimLeft(OGPTResponseBuffer, ".\n")
310306
OGPTResponseBuffer = strings.TrimLeft(OGPTResponseBuffer, "\n")
311307

312-
if bool(WAGPTBlockedWordRegex.MatchString(OGPTResponseBuffer)) {
313-
return "Sorry, the AI can not response due to it is containing some blocked word 🥺", nil
314-
}
315-
316308
return OGPTResponseBuffer, nil
317309
}
318310
}

pkg/whatsapp/whatsapp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func WhatsAppHandler(event interface{}) {
333333
maskRJID = realRJID[0:len(realRJID)-4] + "xxxx" + "@" + splitRJID[1]
334334
}
335335

336-
rMessage := strings.TrimSpace(*evt.Message.Conversation)
336+
rMessage := strings.TrimSpace(evt.Message.GetConversation())
337337

338338
if bool(WhatsAppGPTTagRegex.MatchString(rMessage)) {
339339
rMessageSplit := WhatsAppGPTTagRegex.Split(rMessage, 2)
@@ -354,7 +354,7 @@ func WhatsAppHandler(event interface{}) {
354354
WhatsAppPresence(false)
355355
}()
356356

357-
response, err := gpt.GPT3Response(question)
357+
response, err := gpt.GPTResponse(question)
358358
if err != nil || len(response) == 0 {
359359
log.Println(log.LogLevelError, err.Error())
360360
response = "Sorry, the AI can not response for this time. Please try again after a few moment 🥺"

0 commit comments

Comments
 (0)