mirror of https://github.com/ollama/ollama.git
				
				
				
			allow for starting llava queries with filepath (#1549)
This commit is contained in:
		
							parent
							
								
									a607d922f0
								
							
						
					
					
						commit
						fabf2f3467
					
				
							
								
								
									
										25
									
								
								cmd/cmd.go
								
								
								
								
							
							
						
						
									
										25
									
								
								cmd/cmd.go
								
								
								
								
							|  | @ -928,8 +928,23 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error { | ||||||
| 			return nil | 			return nil | ||||||
| 		case strings.HasPrefix(line, "/"): | 		case strings.HasPrefix(line, "/"): | ||||||
| 			args := strings.Fields(line) | 			args := strings.Fields(line) | ||||||
|  | 			isFile := false | ||||||
|  | 
 | ||||||
|  | 			if multiModal { | ||||||
|  | 				for _, f := range extractFileNames(line) { | ||||||
|  | 					if strings.HasPrefix(f, args[0]) { | ||||||
|  | 						isFile = true | ||||||
|  | 						break | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			if isFile { | ||||||
|  | 				prompt += line | ||||||
|  | 			} else { | ||||||
| 				fmt.Printf("Unknown command '%s'. Type /? for help\n", args[0]) | 				fmt.Printf("Unknown command '%s'. Type /? for help\n", args[0]) | ||||||
| 				continue | 				continue | ||||||
|  | 			} | ||||||
| 		default: | 		default: | ||||||
| 			prompt += line | 			prompt += line | ||||||
| 		} | 		} | ||||||
|  | @ -937,7 +952,7 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error { | ||||||
| 		if len(prompt) > 0 && multiline == MultilineNone { | 		if len(prompt) > 0 && multiline == MultilineNone { | ||||||
| 			opts.Prompt = prompt | 			opts.Prompt = prompt | ||||||
| 			if multiModal { | 			if multiModal { | ||||||
| 				newPrompt, images, err := extractFileNames(prompt) | 				newPrompt, images, err := extractFileData(prompt) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					return err | 					return err | ||||||
| 				} | 				} | ||||||
|  | @ -991,13 +1006,17 @@ func normalizeFilePath(fp string) string { | ||||||
| 	return fp | 	return fp | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func extractFileNames(input string) (string, []ImageData, error) { | func extractFileNames(input string) []string { | ||||||
| 	// Regex to match file paths starting with / or ./ and include escaped spaces (\ or %20)
 | 	// Regex to match file paths starting with / or ./ and include escaped spaces (\ or %20)
 | ||||||
| 	// and followed by more characters and a file extension
 | 	// and followed by more characters and a file extension
 | ||||||
| 	regexPattern := `(?:\./|/)[\S\\ ]+?\.(?i:jpg|jpeg|png|svg)\b` | 	regexPattern := `(?:\./|/)[\S\\ ]+?\.(?i:jpg|jpeg|png|svg)\b` | ||||||
| 	re := regexp.MustCompile(regexPattern) | 	re := regexp.MustCompile(regexPattern) | ||||||
| 
 | 
 | ||||||
| 	filePaths := re.FindAllString(input, -1) | 	return re.FindAllString(input, -1) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func extractFileData(input string) (string, []ImageData, error) { | ||||||
|  | 	filePaths := extractFileNames(input) | ||||||
| 	var imgs []ImageData | 	var imgs []ImageData | ||||||
| 
 | 
 | ||||||
| 	for _, fp := range filePaths { | 	for _, fp := range filePaths { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue