feat: Add response with ai

This commit is contained in:
Siwoo Jeon 2025-05-31 22:53:44 +09:00
parent 3dc47791b4
commit 8205d85303
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
2 changed files with 52 additions and 43 deletions

View file

@ -54,6 +54,18 @@ func (c *Chatbot) SetMode(mode ChatbotMode) *Chatbot {
return c
}
func (c *Chatbot) ReloadPrompt() error {
bin, err := os.ReadFile(configs.Config.Chatbot.Gemini.PromptPath)
if err != nil {
return err
}
ChatBot.config = &genai.GenerateContentConfig{
SystemInstruction: genai.NewContentFromText(string(bin), genai.RoleUser),
}
return nil
}
func getDefaultResponse(s *discordgo.Session, question string) string {
var data []databases.Text
var learnData []databases.Learn
@ -109,6 +121,7 @@ func getAIResponse(question string) string {
result, err := ChatBot.Gemini.Models.GenerateContent(context.TODO(), configs.Config.Chatbot.Gemini.Model, genai.Text(question), ChatBot.config)
if err != nil {
ChatBot.Mode = ChatbotDefault
fmt.Println(err)
return "AI에 문제가 생겼ㅇ어요."
}
return result.Text()
@ -119,6 +132,6 @@ func (c *Chatbot) GetResponse(question string) string {
case ChatbotDefault:
return getDefaultResponse(c.s, question)
default:
return ""
return getAIResponse(question)
}
}

80
main.go
View file

@ -3,7 +3,6 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
@ -17,10 +16,7 @@ import (
"git.wh64.net/muffin/goMuffin/databases"
"git.wh64.net/muffin/goMuffin/handler"
"git.wh64.net/muffin/goMuffin/modals"
"git.wh64.net/muffin/goMuffin/scripts"
"github.com/bwmarrin/discordgo"
"github.com/devproje/commando"
"github.com/devproje/commando/types"
)
func init() {
@ -38,48 +34,48 @@ func init() {
}
func main() {
command := commando.NewCommando(os.Args[1:])
// command := commando.NewCommando(os.Args[1:])
config := configs.Config
if len(os.Args) > 1 {
command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
types.OptionData{
Name: "id",
Desc: "봇의 디스코드 아이디",
Type: types.STRING,
},
types.OptionData{
Name: "isYes",
Short: []string{"y"},
Type: types.BOOLEAN,
},
)
// if len(os.Args) > 1 {
// command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
// types.OptionData{
// Name: "id",
// Desc: "봇의 디스코드 아이디",
// Type: types.STRING,
// },
// types.OptionData{
// Name: "isYes",
// Short: []string{"y"},
// Type: types.BOOLEAN,
// },
// )
command.Root("export", "머핀봇의 데이터를 추출합니다.", scripts.ExportData,
types.OptionData{
Name: "type",
Desc: "파일형식을 지정합니다. (json, jsonl, finetune)",
Type: types.STRING,
},
types.OptionData{
Name: "export-path",
Desc: "데이터를 저장할 위치를 지정합니다.",
Type: types.STRING,
},
types.OptionData{
Name: "refined",
Desc: "머핀 데이터를 있는 그대로 추출할 지, 가려내서 추출할 지를 지정합니다.",
Type: types.BOOLEAN,
},
)
// command.Root("export", "머핀봇의 데이터를 추출합니다.", scripts.ExportData,
// types.OptionData{
// Name: "type",
// Desc: "파일형식을 지정합니다. (json, jsonl, finetune)",
// Type: types.STRING,
// },
// types.OptionData{
// Name: "export-path",
// Desc: "데이터를 저장할 위치를 지정합니다.",
// Type: types.STRING,
// },
// types.OptionData{
// Name: "refined",
// Desc: "머핀 데이터를 있는 그대로 추출할 지, 가려내서 추출할 지를 지정합니다.",
// Type: types.BOOLEAN,
// },
// )
err := command.Execute()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return
}
// err := command.Execute()
// if err != nil {
// _, _ = fmt.Fprintln(os.Stderr, err)
// os.Exit(1)
// }
// return
// }
isAI := flag.Bool("ai", false, "시작할 때 AI모드로 설정합니다.")