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
Yes, I understand your setup. You are using the Ollama framework to build and run language models locally, communicating with the Ollama server via HTTP requests using the cpp-httplib library. You are also utilizing the nlohmann/json library to handle JSON data for communication with the server. You are planning to build a wxWidgets application as an interface to interact with the Ollama server. If you need any help or further clarification, feel free to ask!
- User
- Assistant
Yes, I understand the concept of streaming responses in the chat interface, where multiple messages are received one after the other before a final "done" message indicating the completion of the conversation. In the context of your Ollama chat application, you are looking to handle these multi-response messages in your code.
Please go ahead and share your problem description and the code you have implemented so far. Once I have a clear understanding of your current implementation, we can discuss how to address the issue of handling these multi-response messages efficiently.
- User
- Assistant
Thank you for providing the code snippets related to your Frame, Chat, and Network classes. I will review the code to understand the implementation and identify potential reasons why the messages are not being displayed in real-time as they arrive. Once I have identified the issue, I will provide guidance on how to resolve it effectively. Let me analyze the code first.
- User
So?
- Assistant
After reviewing your code, I see a potential reason why the messages are not being displayed in real-time as they arrive. The issue lies in the fact that you are creating a separate thread for each message sent by the user, leading to multiple threads trying to update the GUI at the same time. This could cause synchronization issues and affect the real-time display of messages.
One approach to address this issue is to process the streaming response in a separate thread but handle the GUI updates in the main thread to ensure proper synchronization. You can achieve this by utilizing the event handling mechanisms provided by wxWidgets to update the GUI from the main thread.
Here are some steps you can consider to improve the real-time display of messages:
-
Modify the
HTTPPostStreammethod in theNetworkclass to handle the streaming response in a separate thread but trigger events to update the GUI in the main thread.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.