|
|
|
|
|
by frumiousirc
264 days ago
|
|
I just asked Gemini Flash to do this. I included the instruction to use regular expressions to do the conversion to ANSI. It gave me a reasonable Python function which boils down to calling `re.sub()` for each of bold, italic and underline. For italics: text = re.sub(r'(\*|_)(.+?)\1', replace_italic, text, flags=re.DOTALL)
The `replace_italic` is a one line callback function surrounding the re's match with the ANSI codes.Knowing what technique is "best" and telling the LLM to use it produces better results (on average) than giving the LLM freedom to choose. For some problems, the specification of the prompt needed to get good output becomes more work than just thinking and writing for myself. For very complex things, I myself can not put the design into English in my own head but can "see" the correct answer as code concepts. I don't know if this is universal for all developers. If it is, it shows a limit of LLM's usefulness. |
|
In a separate chat, I asked it to suggest some ways to do it first, and it provided three alternatives, but suggested I started with regex.
FWIW I used Open WebUI, which uses the API (via OpenRouter). I've seen people here mentioning that the API produces much better results than the chat app, for whatever reason.
For reference, here's prompt and the zero-shot result, minus the rigorous comments it added:
I need a Python function that will take in markdown in a string and return a string with ansi codes for bold, italics and underline. Can you write me such a function?