feat(generation): score articles with selected relevance model (#48)
This commit is contained in:
@ -31,6 +31,9 @@ func newGemini(apiKey, model string) *geminiProvider {
|
||||
func (p *geminiProvider) Name() string { return "gemini" }
|
||||
|
||||
func (p *geminiProvider) Summarize(ctx context.Context, prompt string, opts GenOptions) (string, error) {
|
||||
if len(opts.JSONSchema) > 0 {
|
||||
return "", errStructuredOutputUnsupported
|
||||
}
|
||||
url := fmt.Sprintf(
|
||||
"https://generativelanguage.googleapis.com/v1beta/models/%s:generateContent?key=%s",
|
||||
neturl.PathEscape(p.model), neturl.QueryEscape(p.apiKey),
|
||||
@ -63,7 +66,8 @@ func (p *geminiProvider) Summarize(ctx context.Context, prompt string, opts GenO
|
||||
|
||||
var result struct {
|
||||
Candidates []struct {
|
||||
Content struct {
|
||||
FinishReason string `json:"finishReason"`
|
||||
Content struct {
|
||||
Parts []struct {
|
||||
Text string `json:"text"`
|
||||
} `json:"parts"`
|
||||
@ -76,6 +80,9 @@ func (p *geminiProvider) Summarize(ctx context.Context, prompt string, opts GenO
|
||||
if len(result.Candidates) == 0 || len(result.Candidates[0].Content.Parts) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
if opts.RequireComplete && result.Candidates[0].FinishReason != "STOP" {
|
||||
return "", errGenerationIncomplete
|
||||
}
|
||||
return result.Candidates[0].Content.Parts[0].Text, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user