Skip to content

Commit

Permalink
Use the file cache and set the content type
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Feb 21, 2024
1 parent e09858f commit 20219d1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions engine/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,20 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, _

// .prompt files contains a content type and a prompt that is converted to data in a reproducible way, with a newline between them
case ".prompt":
if data, err := os.ReadFile(filename); err == nil { // success
lines := strings.Split(string(data), "\n")
if promptblock, err := ac.ReadAndLogErrors(w, filename, ext); err == nil { // success
lines := strings.Split(promptblock.String(), "\n")
if len(lines) < 3 {
log.Error(filename + " must contain a content type, a blank line and then a prompt to be usable")
} else if strings.TrimSpace(lines[1]) != "" {
log.Error(filename + " must contain a content type, a blank line and then a prompt to be usable")
} else {
contentType := strings.TrimSpace(lines[0])
prompt := strings.TrimSpace(strings.Join(lines[2:], "\n"))
w.Header().Add("Conent-Type", contentType)
w.Header().Add("Content-Type", contentType)
oc := ollamaclient.NewWithModel("tinyllama")
ollamaclient.HTTPClient = &http.Client{
Timeout: time.Duration(ac.writeTimeout) * time.Second,
}
if err := oc.PullIfNeeded(true); err == nil { // success
if output, err := oc.GetOutput(prompt, true); err == nil { // success
if strings.Contains(output, "<") && strings.Contains(output, ">") {
Expand Down

0 comments on commit 20219d1

Please sign in to comment.