From b93392a01a85d53834520afb1b69ef1f447199b9 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 11 Apr 2025 12:19:32 -0500 Subject: [PATCH] text wrapping --- modules/Ollama/src/Ollama.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/Ollama/src/Ollama.cpp b/modules/Ollama/src/Ollama.cpp index 853aca3..d035a5c 100644 --- a/modules/Ollama/src/Ollama.cpp +++ b/modules/Ollama/src/Ollama.cpp @@ -61,6 +61,22 @@ void Ollama::run() { ImGui::InputText("url: ", &url); + static const std::string replace = "\\n"; + static const std::string replace_by = "\n"; + static std::string print = jsonObj["response"].dump(); print = jsonObj["response"].dump(); + static auto pos = print.find(replace); pos = print.find(replace); + + while (pos != std::string::npos) { + // Replace the substring with the specified string + print.replace(pos, replace.size(), replace_by); + + // Find the next occurrence of the substring + pos = print.find(replace, + pos + replace_by.size()); + } + print = "\n\n\n" + print + "\n\n\n"; + ImGui::TextWrapped("%s", print.c_str()); + ImGui::InputTextMultiline("prompt: ", &s); if(ImGui::Button("send")) { @@ -77,8 +93,7 @@ void Ollama::run() { result = std::async(curl_easy_perform, curl); inFlight = true; } - - ImGui::Text("%s", jsonObj["response"].dump().c_str()); + ImGui::Text("ms per frame: %f", 1000 / io.Framerate); ImGui::End(); @@ -90,6 +105,8 @@ void Ollama::run() { CURLcode code = result.get(); response = oss.str(); oss.str(""); + + if(code != CURLE_OK) { std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl; app->stopModule(getName());