瀏覽代碼

fix prompting

Patrick Devine 6 月之前
父節點
當前提交
af613bab33
共有 2 個文件被更改,包括 29 次插入1 次删除
  1. 1 1
      server/prompt.go
  2. 28 0
      server/prompt_test.go

+ 1 - 1
server/prompt.go

@@ -77,7 +77,7 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
 
 
 	if isMllama {
 	if isMllama {
 		lastMsgIdx := len(msgs) - 1
 		lastMsgIdx := len(msgs) - 1
-		for i := lastMsgIdx; i > currMsgIdx; i-- {
+		for i := lastMsgIdx; i >= currMsgIdx; i-- {
 			if len(msgs[i].Images) > 0 {
 			if len(msgs[i].Images) > 0 {
 				data, aspectRatioID, err := imageproc.Preprocess(msgs[i].Images[0])
 				data, aspectRatioID, err := imageproc.Preprocess(msgs[i].Images[0])
 				if err != nil {
 				if err != nil {

+ 28 - 0
server/prompt_test.go

@@ -229,6 +229,19 @@ func TestChatPrompt(t *testing.T) {
 				prompt: "You're a test, Harry! I-I'm a what? A test. And a thumping good one at that, I'd wager. ",
 				prompt: "You're a test, Harry! I-I'm a what? A test. And a thumping good one at that, I'd wager. ",
 			},
 			},
 		},
 		},
+		{
+			name:  "messages with mllama single prompt",
+			model: mllamaModel,
+			limit: 2048,
+			msgs: []api.Message{
+				{Role: "user", Content: "How many hotdogs are in this image?", Images: []api.ImageData{imgBuf}},
+			},
+			expect: expect{
+				prompt:        "<|image|>How many hotdogs are in this image? ",
+				images:        [][]byte{imgBuf},
+				aspectRatioID: 1,
+			},
+		},
 		{
 		{
 			name:  "messages with mllama",
 			name:  "messages with mllama",
 			model: mllamaModel,
 			model: mllamaModel,
@@ -259,6 +272,21 @@ func TestChatPrompt(t *testing.T) {
 				aspectRatioID: 1,
 				aspectRatioID: 1,
 			},
 			},
 		},
 		},
+		{
+			name:  "earlier image with mllama",
+			model: mllamaModel,
+			limit: 2048,
+			msgs: []api.Message{
+				{Role: "user", Content: "How many hotdogs are in this image?", Images: []api.ImageData{imgBuf}},
+				{Role: "assistant", Content: "There are four hotdogs."},
+				{Role: "user", Content: "Which ones have mustard?"},
+			},
+			expect: expect{
+				prompt:        "<|image|>How many hotdogs are in this image? There are four hotdogs. Which ones have mustard? ",
+				images:        [][]byte{imgBuf},
+				aspectRatioID: 1,
+			},
+		},
 		{
 		{
 			name:  "too many images with mllama",
 			name:  "too many images with mllama",
 			model: mllamaModel,
 			model: mllamaModel,