Skip to content

Commit

Permalink
Merge pull request #84 from basenana/fix/summary
Browse files Browse the repository at this point in the history
skip summary if content has less than 300 token
  • Loading branch information
hyponet authored Dec 16, 2023
2 parents 00aeb13 + d508e05 commit 37b58cc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.13.26
github.com/aws/aws-sdk-go-v2/service/s3 v1.36.0
github.com/aws/smithy-go v1.13.5
github.com/basenana/friday v0.0.0-20231209065908-7ba12e67f748
github.com/basenana/friday v0.0.0-20231216063336-c2c9735897d8
github.com/blevesearch/bleve/v2 v2.3.10
github.com/bluele/gcache v0.0.2
github.com/getsentry/sentry-go v0.22.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ github.com/basenana/friday v0.0.0-20231207142041-8f7eb86afc78 h1:PPj10ZL8OUIzT2w
github.com/basenana/friday v0.0.0-20231207142041-8f7eb86afc78/go.mod h1:OGCCDNAXqN/ZTqO8EsaGGUBt5GrVwb/BVdnDQA4KbZI=
github.com/basenana/friday v0.0.0-20231209065908-7ba12e67f748 h1:STmXI0Q6G3P55zZJRpkgJKQrcyb3/bTgKD/f2QJSU2Y=
github.com/basenana/friday v0.0.0-20231209065908-7ba12e67f748/go.mod h1:OGCCDNAXqN/ZTqO8EsaGGUBt5GrVwb/BVdnDQA4KbZI=
github.com/basenana/friday v0.0.0-20231216063336-c2c9735897d8 h1:jGuzKXoNJ4lIHe/SJmCfMZWSmo3DdDu7evZWNmxXkcs=
github.com/basenana/friday v0.0.0-20231216063336-c2c9735897d8/go.mod h1:OGCCDNAXqN/ZTqO8EsaGGUBt5GrVwb/BVdnDQA4KbZI=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
9 changes: 8 additions & 1 deletion pkg/plugin/buildin/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"

"github.com/basenana/friday/pkg/utils/files"
"go.uber.org/zap"

"github.com/basenana/nanafs/pkg/friday"
Expand All @@ -33,6 +34,7 @@ import (
const (
SummaryPluginName = "summary"
SummaryPluginVersion = "1.0"
DefaultSummaryToken = 300
)

type SummaryPlugin struct {
Expand Down Expand Up @@ -84,7 +86,12 @@ func (i *SummaryPlugin) Run(ctx context.Context, request *pluginapi.Request) (*p
}

trimmedContent := utils.ContentTrim(docType, buf.String())
i.logger(ctx).Infow("get docs", "length", len(trimmedContent), "entryId", request.EntryId)
length := files.Length(trimmedContent)
if length <= DefaultSummaryToken {
i.logger(ctx).Infow("skip summary, length less than default summary token.", "length", length, "default token", DefaultSummaryToken, "entryId", request.EntryId)
return pluginapi.NewResponseWithResult(map[string]any{}), nil
}
i.logger(ctx).Infow("get docs", "length", length, "entryId", request.EntryId)
summary, usage, err := friday.SummaryFile(ctx, fmt.Sprintf("entry_%d", request.EntryId), trimmedContent)
if err != nil {
return pluginapi.NewFailedResponse(fmt.Sprintf("summary documents failed: %s", err)), nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ github.com/aws/smithy-go/waiter
## explicit
github.com/aymerick/douceur/css
github.com/aymerick/douceur/parser
# github.com/basenana/friday v0.0.0-20231209065908-7ba12e67f748
# github.com/basenana/friday v0.0.0-20231216063336-c2c9735897d8
## explicit; go 1.20
github.com/basenana/friday/config
github.com/basenana/friday/pkg/build/withvector
Expand Down

0 comments on commit 37b58cc

Please sign in to comment.