Skip to content

Commit

Permalink
Merge pull request #3 from zzxwill/response
Browse files Browse the repository at this point in the history
fix: provide function to convert genai.GenerateContentResponse to string
  • Loading branch information
zzxwill authored Apr 25, 2024
2 parents ac04a1f + 39c13f7 commit ab425b3
Show file tree
Hide file tree
Showing 49 changed files with 75 additions and 24,328 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/go.yml

This file was deleted.

38 changes: 0 additions & 38 deletions CONTRIBUTING.md

This file was deleted.

201 changes: 0 additions & 201 deletions LICENSE

This file was deleted.

38 changes: 38 additions & 0 deletions gemini/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package gemini

import (
"fmt"
"strings"

"github.com/google/generative-ai-go/genai"
)

func ResponseToString(resp *genai.GenerateContentResponse) string {
return responseString(resp)
}

// responseString is copied from https://github.com/google/generative-ai-go/blob/2813ecb3f680192c8742eccfbf44d1eebb659829/genai/client_test.go#L529
func responseString(resp *genai.GenerateContentResponse) string {
var b strings.Builder
for i, cand := range resp.Candidates {
if len(resp.Candidates) > 1 {
fmt.Fprintf(&b, "%d:", i+1)
}
b.WriteString(contentString(cand.Content))
}
return b.String()
}

func contentString(c *genai.Content) string {
var b strings.Builder
if c == nil || c.Parts == nil {
return ""
}
for i, part := range c.Parts {
if i > 0 {
fmt.Fprintf(&b, ";")
}
fmt.Fprintf(&b, "%v", part)
}
return b.String()
}
71 changes: 0 additions & 71 deletions genai/chat.go

This file was deleted.

Loading

0 comments on commit ab425b3

Please sign in to comment.