Improvements to ollama run
for multimodal models (#2300)
This commit is contained in:
parent
bfbf2f7cf7
commit
7913104527
1 changed files with 11 additions and 21 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -98,6 +99,11 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
||||||
fmt.Fprintln(os.Stderr, " /? shortcuts Help for keyboard shortcuts")
|
fmt.Fprintln(os.Stderr, " /? shortcuts Help for keyboard shortcuts")
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
fmt.Fprintln(os.Stderr, "Use \"\"\" to begin a multi-line message.")
|
fmt.Fprintln(os.Stderr, "Use \"\"\" to begin a multi-line message.")
|
||||||
|
|
||||||
|
if opts.MultiModal {
|
||||||
|
fmt.Fprintf(os.Stderr, "Use %s to include .jpg or .png images.\n", filepath.FromSlash("/path/to/file"))
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +213,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
||||||
switch multiline {
|
switch multiline {
|
||||||
case MultilineSystem:
|
case MultilineSystem:
|
||||||
opts.System = sb.String()
|
opts.System = sb.String()
|
||||||
|
opts.Messages = append(opts.Messages, api.Message{Role: "system", Content: opts.System})
|
||||||
fmt.Println("Set system message.")
|
fmt.Println("Set system message.")
|
||||||
sb.Reset()
|
sb.Reset()
|
||||||
case MultilineTemplate:
|
case MultilineTemplate:
|
||||||
|
@ -226,7 +233,6 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
||||||
fmt.Fprintln(&sb)
|
fmt.Fprintln(&sb)
|
||||||
multiline = MultilinePrompt
|
multiline = MultilinePrompt
|
||||||
scanner.Prompt.UseAlt = true
|
scanner.Prompt.UseAlt = true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
case scanner.Pasting:
|
case scanner.Pasting:
|
||||||
fmt.Fprintln(&sb, line)
|
fmt.Fprintln(&sb, line)
|
||||||
|
@ -349,10 +355,13 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
||||||
|
|
||||||
if args[1] == "system" {
|
if args[1] == "system" {
|
||||||
opts.System = sb.String()
|
opts.System = sb.String()
|
||||||
|
opts.Messages = append(opts.Messages, api.Message{Role: "system", Content: opts.System})
|
||||||
fmt.Println("Set system message.")
|
fmt.Println("Set system message.")
|
||||||
|
sb.Reset()
|
||||||
} else if args[1] == "template" {
|
} else if args[1] == "template" {
|
||||||
opts.Template = sb.String()
|
opts.Template = sb.String()
|
||||||
fmt.Println("Set prompt template.")
|
fmt.Println("Set prompt template.")
|
||||||
|
sb.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.Reset()
|
sb.Reset()
|
||||||
|
@ -488,28 +497,9 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newMessage.Content = msg
|
newMessage.Content = msg
|
||||||
|
newMessage.Images = images
|
||||||
// reset the context if we find another image
|
|
||||||
if len(images) > 0 {
|
|
||||||
newMessage.Images = append(newMessage.Images, images...)
|
|
||||||
// reset the context for the new image
|
|
||||||
opts.Messages = []api.Message{}
|
|
||||||
} else {
|
|
||||||
if len(opts.Messages) > 1 {
|
|
||||||
newMessage.Images = append(newMessage.Images, opts.Messages[len(opts.Messages)-2].Images...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(newMessage.Images) == 0 {
|
|
||||||
fmt.Println("This model requires you to add a jpeg, png, or svg image.")
|
|
||||||
fmt.Println()
|
|
||||||
sb.Reset()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.System != "" {
|
|
||||||
opts.Messages = append(opts.Messages, api.Message{Role: "system", Content: opts.System})
|
|
||||||
}
|
|
||||||
opts.Messages = append(opts.Messages, newMessage)
|
opts.Messages = append(opts.Messages, newMessage)
|
||||||
|
|
||||||
assistant, err := chat(cmd, opts)
|
assistant, err := chat(cmd, opts)
|
||||||
|
|
Loading…
Reference in a new issue