MCPcopy
hub / github.com/mudler/LocalAI / evaluateTemplate

Method evaluateTemplate

core/templates/cache.go:83–107  ·  view source on GitHub ↗
(templateType TemplateType, templateNameOrContent string, in any)

Source from the content-addressed store, hash-verified

81}
82
83func (tc *templateCache) evaluateTemplate(templateType TemplateType, templateNameOrContent string, in any) (string, error) {
84 tc.mu.Lock()
85 defer tc.mu.Unlock()
86
87 tc.initializeTemplateMapKey(templateType)
88 m, ok := tc.templates[templateType][templateNameOrContent]
89 if !ok {
90 // return "", fmt.Errorf("template not loaded: %s", templateName)
91 loadErr := tc.loadTemplateIfExists(templateType, templateNameOrContent)
92 if loadErr != nil {
93 return "", loadErr
94 }
95 m = tc.templates[templateType][templateNameOrContent] // ok is not important since we check m on the next line, and wealready checked
96 }
97 if m == nil {
98 return "", fmt.Errorf("failed loading a template for %s", templateNameOrContent)
99 }
100
101 var buf bytes.Buffer
102
103 if err := m.Execute(&buf, in); err != nil {
104 return "", err
105 }
106 return buf.String(), nil
107}

Callers 2

Calls 5

loadTemplateIfExistsMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected