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. Here’s a quick confirmation:
- Ollama Framework: You're using Ollama to run language models locally. The server is started with
ollama serveand it listens for HTTP commands. - Communication: You've implemented a
Networkclass usingcpp-httplibto handle HTTP GET, POST, and DELETE requests to communicate with the Ollama server. - Data Handling: The
nlohmann/jsonlibrary is being used to handle JSON data exchanged in this communication. - wxWidgets Application: You plan to build a desktop application using wxWidgets that will interface with the Ollama server, leveraging the mentioned libraries for HTTP and JSON communication.
With this setup understood, we can proceed to your next set of questions, requirements, or specific pieces of code you need help with. How can I assist you further?
- Ollama Framework: You're using Ollama to run language models locally. The server is started with
- User
- Assistant
- User
Perfect, So far, it works if I save in the same folder but I want to save to a different folder, how can I create all subfolders if they don't exist?
- Assistant
- User
Great! It works! Now can you refactor this code to not duplicate code?
void FrameMain::OnSaveCloseConversationClick(wxCommandEvent& event) { if (!loadedModel.empty()) { bool save = !chat->GetFilename().empty() && !chat->GetConversationName().empty();
if (!save && loadedConversationFilename.empty() && loadedConversationFilename.empty()) { DialogSaveConversation dialogSaveConversation(this, &loadedConversationFilename, &loadedConversationName); if (dialogSaveConversation.ShowModal() == wxID_OK) { save = true; chat->SetFilename(exePath + "/conversations/" + loadedConversationFilename); chat->SetConversationName(loadedConversationName); } } if (save) { chat->SaveConversation(); wxCommandEvent newEvent; OnCloseConversationClick(newEvent); } }}
void FrameMain::OnSaveConversationClick(wxCommandEvent& event) { if (!loadedModel.empty()) { bool save = !chat->GetFilename().empty() && !chat->GetConversationName().empty();
- Assistant
- User
Perfect! Now I want to do something a little bit more complex, I want to the LoadConversation method to re-write the chat again, this rewrite doesn't have to use the server nor send messages to the server, this is a client part. So the wxRichTextCtrl has to recreate the chat as it were before the save and loading, this will mean, filling it with the correct format.
- Assistant
- User
Ok, It works but it make a linebreak in the first line which is wrong, compared to the original:
Original: "Hi! Hi! 👋 It's great to hear from you. How can I assist you today? 😊 "
Loaded string: " Hi! Hi! 👋 It's great to hear from you. How can I assist you today? 😊 "
How can I fix this? Doesn't rewrite everything, only the changes.
- Assistant
- User
No you missunderstood, I don't want to write this line break, you are writing it in the code you wrote! Also don't rewrite anything but the changes!
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.