diff options
author | Özgür Kesim <oec@codeblau.de> | 2025-03-09 17:49:17 +0100 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2025-03-09 17:49:17 +0100 |
commit | f6669e3e8cf74e8e0773bb7836beccdc6a108383 (patch) | |
tree | 497ee5339a595fe73239e9b369b90532160b45da | |
parent | d986a9e168ee90c8b51abb7d871df9785e8723cc (diff) |
-rw-r--r-- | main.go | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -14,7 +14,7 @@ import ( ) var ( - token = flag.String("token", os.Getenv("FASTGPT_API_TOKEN"), "API-Token, default from FASTGPT_API_TOKEN environment") + token = flag.String("token", "", "API-Token to use instead of $FASTGPT_API_TOKEN or ~/fastgpt_token") stdin = flag.Bool("stdin", true, "Use stdin instead of command-line arguments for search") cache = flag.Bool("cache", false, "Whether to allow cached requests & responses.") websearch = flag.Bool("websearch", true, "Whether to perform web searches to enrich answers. MUST be true for now.") @@ -81,6 +81,23 @@ func main() { buf := &bytes.Buffer{} flag.Parse() + + if *token == "" { + *token = os.Getenv("FASTGPT_API_TOKEN") + if *token == "" { + h, _ := os.UserHomeDir() + b, e := os.ReadFile(h + "/.fastgpt_token") + if e != nil { + panic(e) + } + *token = string(b) + } + } + + if *token == "" { + panic("token needed") + } + if *stdin { if _, e := io.Copy(buf, os.Stdin); e != nil { panic(e) |