ibigio / shell-ai

A delightfully minimal, yet remarkably powerful AI Shell Assistant.
GNU General Public License v3.0
266 stars 25 forks source link

Fix stream / final response content discrepancy (MISSING) #7

Closed ibigio closed 1 year ago

ibigio commented 1 year ago

Context

I noticed with the prompt print first 20 prime numbers (on version v0.3.0) that the streaming response looks ok, but when it gets tea.Printfed it suddenyl has a (MISSING) in the text that didn't used to be there. Weird. Might have to do with the rendering in tea.Printf the final response vs the stream string returned in View()...

https://github.com/ibigio/shell-ai/assets/25421602/58091ba6-fafc-4de0-a75e-1a4353feb529

Task

Investigate and fix it.

ibigio commented 1 year ago

Findings

Responses containing % in them were being interpreted as format string params, and with no arguments passed to tea.Printf() were being turned to (MISSING) by Go.

Before switching to tea.Printf in 750a33e28d59e8934e21721a9553ce4bb24aa5ff I was using a fmt.Printf("%s", m.drawBuffer) so accidentally escaping everything correctly :)

Solution

Pass the string as a format parameter in tea.Printf(). Fixed: e324e3586c0c622846e96f2b79f53dc7120a457a