Skip to content

feat(systemcontext): handle non-existent custom templates #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/systemcontext/systemmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/intility/cwc/pkg/templates"
)

const (
defaultTemplateName = "default"
)

type SystemMessageGenerator interface {
GenerateSystemMessage() (string, error)
}
Expand Down Expand Up @@ -49,6 +53,11 @@ func (smg *TemplatedSystemMessageGenerator) GenerateSystemMessage() (string, err
// if no template found, create a basic template as fallback
if err != nil {
if errors.IsTemplateNotFoundError(err) {
// exit with error if the user has requested a custom template and it is not found
if smg.templateName != defaultTemplateName {
return "", fmt.Errorf("template not found: %w", err)
}

return CreateBuiltinSystemMessageFromContext(ctx), nil
}

Expand Down
Loading