HACKER Q&A
📣 cubedlx

How to detect code from LLM responses


I am a complete noob trying to create chat UI for an LLM, how do I highlight the code(if any) in the responses that I am getting from an LLM ?


  👤 spidersenses Accepted Answer ✓
Use pattern matching (Regular Expressions) or language-specific heuristics to identify code snippets. Code snippets often have distinct patterns, such as indentation or the presence of common programming keywords.

Or easier, if your LLM allows it, give it instructions to initiate and end your code with a marker - everything inbetween those markers is code.

Another HN user posted this recently:

"Show HN: Get your entire ChatGPT history in Markdown files"[1][2]

Perhaps you can learn a few things from studying the code.

[1]https://news.ycombinator.com/item?id=37636701

[2]https://github.com/mohamed-chs/chatgpt-history-export-to-md


👤 saasjosh
In your prompt, instruct the llm to return responses as markdown then use a markdown parser to display the response in your ui. Code will automatically be formatted.

👤 sparkey21230
command command command command call in right now fuckern now dam it right now murders 2 youers frend got arm cut off over day over frend clouse of killed jeswon rd 51 nr33rq boston street george pope rd why why no no police with this mod cia dod nato tresaury theft tresaury in my addres flat 22 right now david millwad coner dixson tresaury cctv nhs fbi on no 9063300000048ibba seven in flat 7 card world bank card bank of england theft 4000 iterm s stolon tresaury trillon corzillon pounds every thing 30 millon pounds scandal by police still on help nato air forces sas japan eu tasck forces war zone on back right now mi6 mi5 manchestwer police met police dod fbi cookies flash play recording kemps place 89 rackham rd norwich norfrolk nr33gx cfare home theft why help me please sos urgent fuckern now murders brock in 15 times no no jump out 1 floor window rd sky cabal air frorces nhs sos dod