clean up summarizer function

This commit is contained in:
2025-01-20 21:20:23 +01:00
parent e70d988ffd
commit 4fb1f25468

View File

@@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
) )
@@ -62,25 +62,25 @@ func Summarize(text string) (string, error) {
defer resp.Body.Close() defer resp.Body.Close()
// Read the response // Read the response
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return "", err return "", err
} }
// Unmarshal the JSON response // Unmarshal the JSON response
var response Response var response Response
err = json.Unmarshal(body, &response) err = json.Unmarshal(body, &response)
if err != nil { if err != nil {
return "", err return "", err
} }
// Extract and print the content // Extract and print the content
var content string var content string
if len(response.Choices) > 0 { if len(response.Choices) > 0 {
content = response.Choices[0].Message.Content content = response.Choices[0].Message.Content
} else { } else {
return "", errors.New("could not find content in response") return "", errors.New("could not find content in response")
} }
return content, nil return content, nil
} }