feat: Add response with ai
This commit is contained in:
parent
3dc47791b4
commit
8205d85303
2 changed files with 52 additions and 43 deletions
|
@ -54,6 +54,18 @@ func (c *Chatbot) SetMode(mode ChatbotMode) *Chatbot {
|
||||||
return c
|
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 {
|
func getDefaultResponse(s *discordgo.Session, question string) string {
|
||||||
var data []databases.Text
|
var data []databases.Text
|
||||||
var learnData []databases.Learn
|
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)
|
result, err := ChatBot.Gemini.Models.GenerateContent(context.TODO(), configs.Config.Chatbot.Gemini.Model, genai.Text(question), ChatBot.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ChatBot.Mode = ChatbotDefault
|
ChatBot.Mode = ChatbotDefault
|
||||||
|
fmt.Println(err)
|
||||||
return "AI에 문제가 생겼ㅇ어요."
|
return "AI에 문제가 생겼ㅇ어요."
|
||||||
}
|
}
|
||||||
return result.Text()
|
return result.Text()
|
||||||
|
@ -119,6 +132,6 @@ func (c *Chatbot) GetResponse(question string) string {
|
||||||
case ChatbotDefault:
|
case ChatbotDefault:
|
||||||
return getDefaultResponse(c.s, question)
|
return getDefaultResponse(c.s, question)
|
||||||
default:
|
default:
|
||||||
return ""
|
return getAIResponse(question)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
80
main.go
80
main.go
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -17,10 +16,7 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/handler"
|
"git.wh64.net/muffin/goMuffin/handler"
|
||||||
"git.wh64.net/muffin/goMuffin/modals"
|
"git.wh64.net/muffin/goMuffin/modals"
|
||||||
"git.wh64.net/muffin/goMuffin/scripts"
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/devproje/commando"
|
|
||||||
"github.com/devproje/commando/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -38,48 +34,48 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
command := commando.NewCommando(os.Args[1:])
|
// command := commando.NewCommando(os.Args[1:])
|
||||||
config := configs.Config
|
config := configs.Config
|
||||||
|
|
||||||
if len(os.Args) > 1 {
|
// if len(os.Args) > 1 {
|
||||||
command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
|
// command.Root("delete-all-commands", "봇의 모든 슬래시 커맨드를 삭제합니다.", scripts.DeleteAllCommands,
|
||||||
types.OptionData{
|
// types.OptionData{
|
||||||
Name: "id",
|
// Name: "id",
|
||||||
Desc: "봇의 디스코드 아이디",
|
// Desc: "봇의 디스코드 아이디",
|
||||||
Type: types.STRING,
|
// Type: types.STRING,
|
||||||
},
|
// },
|
||||||
types.OptionData{
|
// types.OptionData{
|
||||||
Name: "isYes",
|
// Name: "isYes",
|
||||||
Short: []string{"y"},
|
// Short: []string{"y"},
|
||||||
Type: types.BOOLEAN,
|
// Type: types.BOOLEAN,
|
||||||
},
|
// },
|
||||||
)
|
// )
|
||||||
|
|
||||||
command.Root("export", "머핀봇의 데이터를 추출합니다.", scripts.ExportData,
|
// command.Root("export", "머핀봇의 데이터를 추출합니다.", scripts.ExportData,
|
||||||
types.OptionData{
|
// types.OptionData{
|
||||||
Name: "type",
|
// Name: "type",
|
||||||
Desc: "파일형식을 지정합니다. (json, jsonl, finetune)",
|
// Desc: "파일형식을 지정합니다. (json, jsonl, finetune)",
|
||||||
Type: types.STRING,
|
// Type: types.STRING,
|
||||||
},
|
// },
|
||||||
types.OptionData{
|
// types.OptionData{
|
||||||
Name: "export-path",
|
// Name: "export-path",
|
||||||
Desc: "데이터를 저장할 위치를 지정합니다.",
|
// Desc: "데이터를 저장할 위치를 지정합니다.",
|
||||||
Type: types.STRING,
|
// Type: types.STRING,
|
||||||
},
|
// },
|
||||||
types.OptionData{
|
// types.OptionData{
|
||||||
Name: "refined",
|
// Name: "refined",
|
||||||
Desc: "머핀 데이터를 있는 그대로 추출할 지, 가려내서 추출할 지를 지정합니다.",
|
// Desc: "머핀 데이터를 있는 그대로 추출할 지, 가려내서 추출할 지를 지정합니다.",
|
||||||
Type: types.BOOLEAN,
|
// Type: types.BOOLEAN,
|
||||||
},
|
// },
|
||||||
)
|
// )
|
||||||
|
|
||||||
err := command.Execute()
|
// err := command.Execute()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
// _, _ = fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
// os.Exit(1)
|
||||||
}
|
// }
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
isAI := flag.Bool("ai", false, "시작할 때 AI모드로 설정합니다.")
|
isAI := flag.Bool("ai", false, "시작할 때 AI모드로 설정합니다.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue