diff --git a/summarize.go b/summarize.go index ea2059d..6a60783 100644 --- a/summarize.go +++ b/summarize.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "strings" "time" readability "github.com/go-shiori/go-readability" @@ -31,23 +30,29 @@ func summarize(text string) string { if len(text) < 200 { return "" } - c := openai.NewClient(openaiApiKey) - ctx := context.Background() - req := openai.CompletionRequest{ - Model: openai.GPT3Dot5Turbo, - MaxTokens: 60, - Prompt: text + " \n\nTl;dr", - } - resp, err := c.CreateCompletion(ctx, req) + client := openai.NewClient(openaiApiKey) + resp, err := client.CreateChatCompletion( + context.Background(), + openai.ChatCompletionRequest{ + Model: openai.GPT3Dot5Turbo, + Messages: []openai.ChatCompletionMessage{ + { + Role: openai.ChatMessageRoleAssistant, + Content: "Summarize the following text:", + }, + { + Role: openai.ChatMessageRoleUser, + Content: text, + }, + }, + }, + ) + if err != nil { + fmt.Printf("ChatCompletion error: %v\n", err) return "" } - // append ... if text does not end with . - if !strings.HasSuffix(resp.Choices[0].Text, ".") { - resp.Choices[0].Text = resp.Choices[0].Text + "..." - } - - return resp.Choices[0].Text + return resp.Choices[0].Message.Content }