psugihara / FreeChat

llama.cpp based AI chat app for macOS
https://www.freechat.run
MIT License
425 stars 37 forks source link

Response text should be easily selectable #22

Open psugihara opened 11 months ago

psugihara commented 11 months ago

Currently you can only select text 1 paragraph at a time due to the markdown package we use. This is incredibly annoying! There's an issue tracking that here but no line of sight to a solution https://github.com/gonzalezreal/swift-markdown-ui/issues/264

An alternative to get this functionality could be to use libcmark_gfm directly like FSNotes does here then put the resulting HTML in a web view. https://github.com/glushchenko/fsnotes/blob/2d15de3f8148eba312fd3552e86725f264f1497b/FSNotes/Business/Markdown.swift#L13

Maybe there's an even better solution, idk

cleesmith commented 10 months ago

I know Markdown is a very common thing with it's simple formatting, and looks nice on a screen. But as a writer or just doing research, it would be great to just have plain text; no formatting and no bulleted/numbered lists ... it becomes a tedious editing step after doing a copy/paste into Sublime, Textedit, or Google Docs. Maybe a user selectable on/off option for Markdown would be great.

psugihara commented 10 months ago

Good suggestion @cleesmith, thanks. Let's definitely implement that! A checkbox in Settings would be a good way to handle it.

psugihara commented 10 months ago

just have plain text

hey @cleesmith... small clarification. Is your request to see the output as plaintext (e.g. unrendered markdown)? That's what I originally thought you were asking for, but note that it would still include numbered lists, etc. To get it to have a different format you'd need to ask the model (either through the system prompt or your chat). The default system prompt includes a request for markdown, so take that out if you don't want it.

Here's an example of what that would look like (unrendered markdown).

Screenshot 2023-11-30 at 11 37 55 AM
finallyblueskies commented 5 months ago

I've started my own OS MacOS chat client and am forking FreeChat to get the job done. This issue really bugged me, so I spent some time looking for a solution. Markdown rendering solutions for MacOS swift UI are not that great, but @psugihara's webview suggestion seems to be pretty workable. I have a small writeup with my findings.

Summarised, I use Ink to parse markdown into HTML and render it into a custom WKWebView, which autosizes itself based on the content inside. Scroll events are passed on to the next responder to prevent the WKWebView from consuming them.

The result is a pretty fast MD renderer with reasonable default styling, good customisability and most importantly, freely selectable text.

WKWebView didn't work out so well. This was my solution after some wrangling.

psugihara commented 5 months ago

Good to know it worked. Happy for any contribution back if the component is portable.