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 `<h1>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<h1>b" ```
This commit is contained in:
parent
ed19d10aa5
commit
62d29b2157
2 changed files with 24 additions and 1 deletions
|
@ -9,7 +9,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -21,6 +20,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/jmorganca/ollama/api"
|
"github.com/jmorganca/ollama/api"
|
||||||
"github.com/jmorganca/ollama/llm"
|
"github.com/jmorganca/ollama/llm"
|
||||||
|
|
23
server/images_test.go
Normal file
23
server/images_test.go
Normal file
|
@ -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: "<h1>",
|
||||||
|
}
|
||||||
|
s, err := m.Prompt(req, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := "a<h1>b"
|
||||||
|
if s != want {
|
||||||
|
t.Errorf("got %q, want %q", s, want)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue