From cf2a4077bc300592da9a2c1fc1cd6438e25baa52 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 10 May 2024 15:45:35 -0400 Subject: adding chat to gemini --- main.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index a5ffbdd..c2c3565 100644 --- a/main.go +++ b/main.go @@ -80,14 +80,13 @@ type MemoryElement struct { Content string `json:"content"` } -func printResponse(resp *genai.GenerateContentResponse) string { +func returnGeminiResponse(resp *genai.GenerateContentResponse) string { result := "" for _, cand := range resp.Candidates { if cand.Content != nil { for _, part := range cand.Content.Parts { result += fmt.Sprintln(part) - log.Println(part) } } } @@ -241,6 +240,8 @@ func runIRC(appConfig TomlConfig, ircChan chan *girc.Client) { ctx, cancel := context.WithTimeout(context.Background(), time.Duration(appConfig.RequestTimeout)*time.Second) defer cancel() + // api and http client dont work together + // https://github.com/google/generative-ai-go/issues/80 // httpClient := http.Client{} // allProxy := os.Getenv("ALL_PROXY") // if allProxy != "" { @@ -287,10 +288,27 @@ func runIRC(appConfig TomlConfig, ircChan chan *girc.Client) { // return // } + geminiResponse := returnGeminiResponse(resp) + log.Println(geminiResponse) + + cs.History = append(cs.History, &genai.Content{ + Parts: []genai.Part{ + genai.Text(prompt), + }, + Role: "user", + }) + + cs.History = append(cs.History, &genai.Content{ + Parts: []genai.Part{ + genai.Text(geminiResponse), + }, + Role: "model", + }) + var writer bytes.Buffer err = quick.Highlight( &writer, - printResponse(resp), + geminiResponse, "markdown", appConfig.ChromaFormatter, appConfig.ChromaStyle) -- cgit v1.2.3