I am making a C++ wxWidgets application, my desktop program is an interface for an LLM…
- User
I am making a C++ wxWidgets application, my desktop program is an interface for an LLM chat external command-line application, called Ollama.
Ollama is a lightweight, extensible framework for building and running language models on the local machine. It provides a simple API for creating, running, and managing models, as well as a library of pre-built models that can be easily used in a variety of applications.
It works like this,
- First, we run in one terminal: "ollama serve", which in that terminal starts a server that listen all the commands and works as a webserver inside localhost, and the only way to turn it off is by killing the process.
- Second, in another terminal, we can use "ollama run MODEL_NAME", to start a chat with said model, communicating with the server using HTTP and JSON.
I Have a Network class using cpp-httplib, with methods like HTTPGet, HTTPPost and HTTPDelete, to deal with the HTTP requests.
And for the JSON part I am using nlohmann/json library.
Here’s a quick recap to make sure we’re both on the same page:
-
Ollama Framework: I am using the Ollama framework to build and run language models locally. The framework starts a server when you run ollama serve and it listens for commands, which you then interact with using HTTP requests.
-
Communication: For communication with the Ollama server, I have a Network class utilizing the cpp-httplib library to make HTTP requests (GET, POST, DELETE).
-
Data Handling: I am using the nlohmann/json library to handle JSON data, which is used for communication with the Ollama server.
I am planning to build a wxWidgets application that acts as an interface to communicate with the Ollama server, allowing you to interact with language models via HTTP and JSON.
Tell me if you understand my setup so we can continue.
- Assistant
I understand your setup. You have an Ollama framework for building and running language models locally, a Network class to handle HTTP requests using the cpp-httplib library, and the nlohmann/json library for handling JSON data. You are planning to build a wxWidgets application as an interface to communicate with the Ollama server. Let me know how I can assist you further in implementing this application.
- User
I will be implementing markdown support in a wxRichTextCtrl, you can begin with a basic feature set and gradually expand the functionality. Here is a suggested order to implement features incrementally:
- Basic Markdown Features:
- Add support for basic markdown formatting such as bold, italic, and underline. Implement parsing logic to recognize and apply these formatting styles to the messages.
- Headers and Lists:
- Introduce support for headers and lists in markdown messages. Allow users to create structured content using headers and bullet/numbered lists.
- Code Blocks and Blockquotes:
- Add support for displaying code blocks and blockquotes in markdown messages. Implement formatting logic to differentiate code snippets and quoted text.
- Advanced Features (optional):
- Consider implementing more advanced markdown features such as tables, task lists, etc.
- Live Preview (optional - TBA):
- Provide a live preview option for users to see the formatted text as they type in the chat input. This can enhance the user experience by showing real-time markdown rendering.
Let me know if you understood this so we can move to my current code and how we can start dealing with the markdown support.
- Assistant
I understand the plan to implement markdown support incrementally in a wxRichTextCtrl. We will start with basic markdown features like bold, italic, and underline, then move on to headers and lists, and later include code blocks and blockquotes. If you choose to proceed with advanced features like tables and task lists or a live preview option, we can address those as well. Please share your current code related to the wxRichTextCtrl, and we can discuss how to begin implementing markdown support.
- User
- Assistant
Thank you for sharing your code. The
Chatclass includes functions for appending messages, handling streaming text, checking if the chat history ends with a newline, trimming trailing whitespace from a string, formatting messages, and rewriting the chat history.To implement markdown support in the
Chatclass using awxRichTextCtrl, we can start by adding basic markdown formatting features like bold, italic, and underline. Here's a general approach to get you started:- Create a function to parse and apply basic markdown formatting styles.
- Modify the
AppendMessagefunction to recognize and apply markdown formatting to the message before displaying it in thewxRichTextCtrl. - Update the
FormatMessageStringfunction to handle markdown syntax conversion.
Let's start by implementing basic markdown formatting features in your
Chatclass. Feel free to ask specific questions or discuss any changes you'd like to make. - User
OK In what part of my code should I add the for example, bold support. In the example page shows this:
r.BeginBold(); r.WriteText(wxT("bold ")); r.EndBold();
So it has to be added in the write text part, but I already write the entire text as a plain text in the appendmessage. should I create a new function to write the text or just use the appenmessage? Also how would we start parsing the string, for example if found the first "" it should do the r.BeginBold();, then the next "" should relate to r.EndBold();.
- Assistant
To add support for basic Markdown formatting like bold in your
Chatclass usingwxRichTextCtrl, you can extend the existingAppendMessagefunction to handle parsing of the message text and apply the corresponding Markdown formatting styles. Here's how you can approach this: - User
it works perfectly, but bold text should be two asterisks not one
- Assistant
If you want to use two asterisks "**" instead of one "*" to denote bold text in your Markdown formatting implementation, you can adjust the parsing logic accordingly in your
AppendMessagefunction. Here's how you can modify the code to detect bold text enclosed in double asterisks:cpp
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.