forked from third-party-mirrors/ollama
Compare commits
2 Commits
main
...
pdevine/ne
Author | SHA1 | Date | |
---|---|---|---|
|
b8af12ceaf | ||
|
6f041ddfa4 |
@ -30,6 +30,11 @@ const (
|
|||||||
MultilineSystem
|
MultilineSystem
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
scannerPrompt = ">>> "
|
||||||
|
scannerAltPrompt = "... "
|
||||||
|
)
|
||||||
|
|
||||||
func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
||||||
usage := func() {
|
usage := func() {
|
||||||
fmt.Fprintln(os.Stderr, "Available Commands:")
|
fmt.Fprintln(os.Stderr, "Available Commands:")
|
||||||
@ -111,8 +116,8 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scanner, err := readline.New(readline.Prompt{
|
scanner, err := readline.New(readline.Prompt{
|
||||||
Prompt: ">>> ",
|
Prompt: scannerPrompt,
|
||||||
AltPrompt: "... ",
|
AltPrompt: scannerAltPrompt,
|
||||||
Placeholder: "Send a message (/? for help)",
|
Placeholder: "Send a message (/? for help)",
|
||||||
AltPlaceholder: `Use """ to end multi-line input`,
|
AltPlaceholder: `Use """ to end multi-line input`,
|
||||||
})
|
})
|
||||||
@ -144,6 +149,11 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
|||||||
scanner.Prompt.UseAlt = false
|
scanner.Prompt.UseAlt = false
|
||||||
sb.Reset()
|
sb.Reset()
|
||||||
|
|
||||||
|
continue
|
||||||
|
case errors.Is(err, readline.ErrNewLineDetected):
|
||||||
|
sb.WriteString(line)
|
||||||
|
fmt.Fprintln(&sb)
|
||||||
|
scanner.Prompt.Prompt = scannerAltPrompt
|
||||||
continue
|
continue
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return err
|
return err
|
||||||
@ -169,7 +179,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
|||||||
|
|
||||||
multiline = MultilineNone
|
multiline = MultilineNone
|
||||||
scanner.Prompt.UseAlt = false
|
scanner.Prompt.UseAlt = false
|
||||||
case strings.HasPrefix(line, `"""`):
|
case strings.HasPrefix(line, `"""`) && !scanner.Pasting:
|
||||||
line := strings.TrimPrefix(line, `"""`)
|
line := strings.TrimPrefix(line, `"""`)
|
||||||
line, ok := strings.CutSuffix(line, `"""`)
|
line, ok := strings.CutSuffix(line, `"""`)
|
||||||
sb.WriteString(line)
|
sb.WriteString(line)
|
||||||
@ -433,7 +443,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
|||||||
sb.WriteString(line)
|
sb.WriteString(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sb.Len() > 0 && multiline == MultilineNone {
|
if sb.Len() > 0 && strings.TrimSpace(sb.String()) != "" && multiline == MultilineNone {
|
||||||
newMessage := api.Message{Role: "user", Content: sb.String()}
|
newMessage := api.Message{Role: "user", Content: sb.String()}
|
||||||
|
|
||||||
if opts.MultiModal {
|
if opts.MultiModal {
|
||||||
@ -464,6 +474,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sb.Reset()
|
sb.Reset()
|
||||||
|
scanner.Prompt.Prompt = scannerPrompt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInterrupt = errors.New("Interrupt")
|
var (
|
||||||
|
ErrInterrupt = errors.New("Interrupt")
|
||||||
|
ErrNewLineDetected = errors.New("new line detected")
|
||||||
|
)
|
||||||
|
|
||||||
type InterruptError struct {
|
type InterruptError struct {
|
||||||
Line []rune
|
Line []rune
|
||||||
|
@ -225,6 +225,9 @@ func (i *Instance) Readline() (string, error) {
|
|||||||
buf.MoveToEnd()
|
buf.MoveToEnd()
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
|
if r == CharCtrlJ {
|
||||||
|
return output, ErrNewLineDetected
|
||||||
|
}
|
||||||
return output, nil
|
return output, nil
|
||||||
default:
|
default:
|
||||||
if metaDel {
|
if metaDel {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user