From a9083dc0b4c70b44e8f6839581527bf2e18374f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sat, 8 Jun 2024 22:23:42 +0300 Subject: [PATCH] d --- v4/llm.cpp | 8 ++++++++ v4/llm.h | 1 + v4/llm.py | 4 ++++ v4/main.cpp | 14 ++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/v4/llm.cpp b/v4/llm.cpp index a617851..808492a 100644 --- a/v4/llm.cpp +++ b/v4/llm.cpp @@ -6,6 +6,14 @@ bool llm_isDigit(const std::string &str) { str.find_first_not_of("0123456789") == std::string::npos; } +bool llm_startsWith( + const std::string &str, + const std::string &prefix +) { + // https://stackoverflow.com/a/40441240 + return str.rfind(prefix, 0) == 0; +} + int llm_strToInt(const std::string &str) { return std::stoi(str); } diff --git a/v4/llm.h b/v4/llm.h index 645cf30..bd7deab 100644 --- a/v4/llm.h +++ b/v4/llm.h @@ -4,6 +4,7 @@ #include bool llm_isDigit(const std::string &str); +bool llm_startsWith(const std::string &str, const std::string &prefix); int llm_strToInt(const std::string &str); #endif // llm_HEADER diff --git a/v4/llm.py b/v4/llm.py index b8848a0..0ca860f 100644 --- a/v4/llm.py +++ b/v4/llm.py @@ -13,6 +13,10 @@ def llm_by_value(f): def llm_isDigit(s): return s.isdigit() +# Tell if string starts with certain prefix. +def llm_startsWith(s, prefix): + return s.startswith(prefix) + # Convert string to integer def llm_strToInt(s): return int(s) diff --git a/v4/main.cpp b/v4/main.cpp index 3ff71de..b955a8f 100644 --- a/v4/main.cpp +++ b/v4/main.cpp @@ -1,7 +1,9 @@ #include #include #include +#include "any.h" #include "ctx_test2.h" +#include "llm.h" #include "main.h" #include "memory_Context.h" @@ -94,6 +96,18 @@ int main() { memory_hideMatchingItems, memory_selectItem, }); + + + auto printOutput = [](memory_Context c) { + if (llm_startsWith(c.recentField, "output")) { + std::cout + << libany::any_cast(c.field(c.recentField)) + << std::endl; + } + }; + ctrl.registerCallback(printOutput); + ctrl.registerFieldCallback("exit", [](memory_Context c) { exit(0); }); + /* auto c = shell_createContext();