瀏覽代碼

append image tags to user content

Michael Yang 1 年之前
父節點
當前提交
b4e11be8ef
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 6 1
      server/images.go
  2. 4 0
      server/routes.go

+ 6 - 1
server/images.go

@@ -179,8 +179,13 @@ func (m *Model) ChatPrompts(msgs []api.Message) (*ChatHistory, error) {
 				prompts = append(prompts, currentVars)
 				prompts = append(prompts, currentVars)
 				currentVars = PromptVars{}
 				currentVars = PromptVars{}
 			}
 			}
+
 			currentVars.Prompt = msg.Content
 			currentVars.Prompt = msg.Content
-			currentImages = msg.Images
+			for i := range msg.Images {
+				currentVars.Prompt += fmt.Sprintf(" [img-%d]", len(currentImages)+i)
+			}
+
+			currentImages = append(currentImages, msg.Images...)
 		case "assistant":
 		case "assistant":
 			currentVars.Response = msg.Content
 			currentVars.Response = msg.Content
 			prompts = append(prompts, currentVars)
 			prompts = append(prompts, currentVars)

+ 4 - 0
server/routes.go

@@ -244,6 +244,10 @@ func GenerateHandler(c *gin.Context) {
 			promptVars.System = model.System
 			promptVars.System = model.System
 		}
 		}
 
 
+		for i := range req.Images {
+			promptVars.Prompt += fmt.Sprintf(" [img-%d]", i)
+		}
+
 		p, err := model.PreResponsePrompt(promptVars)
 		p, err := model.PreResponsePrompt(promptVars)
 		if err != nil {
 		if err != nil {
 			c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
 			c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})