From 62d29b2157d8fec5ec45de7a9fa70fc6fcf02408 Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Fri, 1 Sep 2023 17:12:20 -0500 Subject: [PATCH] do not HTML-escape prompt The `html/template` package automatically HTML-escapes interpolated strings in templates. This behavior is undesirable because it causes prompts like `

hello` to be escaped to `<h1>hello` before being passed to the LLM. The included test case passes, but before the code change, it failed: ``` --- FAIL: TestModelPrompt images_test.go:21: got "a<h1>b", want "a

b" ``` --- server/images.go | 2 +- server/images_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 server/images_test.go diff --git a/server/images.go b/server/images.go index 40e38256..a3b3eb4c 100644 --- a/server/images.go +++ b/server/images.go @@ -9,7 +9,6 @@ import ( "encoding/json" "errors" "fmt" - "html/template" "io" "log" "net/http" @@ -21,6 +20,7 @@ import ( "runtime" "strconv" "strings" + "text/template" "github.com/jmorganca/ollama/api" "github.com/jmorganca/ollama/llm" diff --git a/server/images_test.go b/server/images_test.go new file mode 100644 index 00000000..eb3c32d9 --- /dev/null +++ b/server/images_test.go @@ -0,0 +1,23 @@ +package server + +import ( + "testing" + + "github.com/jmorganca/ollama/api" +) + +func TestModelPrompt(t *testing.T) { + var m Model + req := api.GenerateRequest{ + Template: "a{{ .Prompt }}b", + Prompt: "

", + } + s, err := m.Prompt(req, "") + if err != nil { + t.Fatal(err) + } + want := "a

b" + if s != want { + t.Errorf("got %q, want %q", s, want) + } +}