diff --git a/main.go b/main.go index fb2b278..afdece1 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,8 @@ func main() { ui := tui.NewGPTUI(cnf) ui.Run() + // p := gpt.NewGPTPrompt(cnf) + // p.DownloadPrompt() // spark := iflytek.NewSpark(cnf) // spark.SendMsg([]openai.ChatCompletionMessage{ // {Role: openai.ChatMessageRoleUser, Content: "你好"}, diff --git a/pkgs/cmd/gogptm/gogpt.go b/pkgs/cmd/gogptm/gogpt.go index e3d75c7..cc9e759 100644 --- a/pkgs/cmd/gogptm/gogpt.go +++ b/pkgs/cmd/gogptm/gogpt.go @@ -2,9 +2,13 @@ package main import ( "os" + "path/filepath" + "github.com/moqsien/gogpt/pkgs/config" + "github.com/moqsien/gogpt/pkgs/gpt" "github.com/moqsien/gogpt/pkgs/tui" "github.com/moqsien/goutils/pkgs/gtea/gprint" + "github.com/moqsien/goutils/pkgs/gutils" "github.com/postfinance/single" ) @@ -19,6 +23,12 @@ func main() { }() cnf := tui.GetDefaultConfig() + cnf.OpenAI.PromptMsgUrl = config.PromptUrl + promptPath := filepath.Join(cnf.GetWorkDir(), gpt.PromptFileName) + if ok, _ := gutils.PathIsExist(promptPath); !ok { + prompt := gpt.NewGPTPrompt(cnf) + prompt.DownloadPrompt() + } ui := tui.NewGPTUI(cnf) ui.Run() } diff --git a/pkgs/gpt/prompt.go b/pkgs/gpt/prompt.go index f668ec7..d5f3352 100644 --- a/pkgs/gpt/prompt.go +++ b/pkgs/gpt/prompt.go @@ -2,6 +2,7 @@ package gpt import ( "encoding/json" + "fmt" "os" "path/filepath" "time" @@ -48,7 +49,10 @@ func (that *GPTPrompt) DownloadPrompt() { f := request.NewFetcher() f.SetUrl(that.CNF.OpenAI.PromptMsgUrl) f.Timeout = 10 * time.Second - f.GetFile(that.path, true) + size := f.GetFile(that.path, true) + if size == 0 { + fmt.Println("download failed") + } } func (that *GPTPrompt) PromptStr() string { @@ -68,5 +72,6 @@ func (that *GPTPrompt) GetPromptByTile(title string) (p string) { return pItem.Msg } } - return + that.prompt = "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible." + return that.prompt }