@@ -18,6 +18,7 @@ import (
1818type ChatCmd struct {
1919 Model string `arg:"" help:"Model name"`
2020 NoStream bool `flag:"nostream" help:"Disable streaming"`
21+ NoTools bool `flag:"nostream" help:"Disable tool calling"`
2122 System string `flag:"system" help:"Set the system prompt"`
2223}
2324
@@ -39,16 +40,17 @@ func (cmd *ChatCmd) Run(globals *Globals) error {
3940 // Set the options
4041 opts := []llm.Opt {}
4142 if ! cmd .NoStream {
42- opts = append (opts , llm .WithStream (func (cc llm.ContextContent ) {
43- if text := cc .Text (); text != "" {
44- fmt .Println (text )
43+ opts = append (opts , llm .WithStream (func (cc llm.Completion ) {
44+ if text := cc .Text (0 ); text != "" {
45+ text = strings .ReplaceAll (text , "\n " , " " )
46+ fmt .Print ("\r " + text )
4547 }
4648 }))
4749 }
4850 if cmd .System != "" {
4951 opts = append (opts , llm .WithSystemPrompt (cmd .System ))
5052 }
51- if globals .toolkit != nil {
53+ if globals .toolkit != nil && ! cmd . NoTools {
5254 opts = append (opts , llm .WithToolKit (globals .toolkit ))
5355 }
5456
@@ -77,12 +79,12 @@ func (cmd *ChatCmd) Run(globals *Globals) error {
7779
7880 // Repeat call tools until no more calls are made
7981 for {
80- calls := session .ToolCalls ()
82+ calls := session .ToolCalls (0 )
8183 if len (calls ) == 0 {
8284 break
8385 }
84- if session .Text () != "" {
85- globals .term .Println (session .Text ())
86+ if session .Text (0 ) != "" {
87+ globals .term .Println (session .Text (0 ))
8688 } else {
8789 var names []string
8890 for _ , call := range calls {
@@ -98,7 +100,7 @@ func (cmd *ChatCmd) Run(globals *Globals) error {
98100 }
99101
100102 // Print the response
101- globals .term .Println ("\n " + session .Text () + "\n " )
103+ globals .term .Println ("\n " + session .Text (0 ) + "\n " )
102104 }
103105 })
104106}
0 commit comments