Михаил Капелько 2 settimane fa
parent
commit
a9083dc0b4
4 ha cambiato i file con 27 aggiunte e 0 eliminazioni
  1. +8
    -0
      v4/llm.cpp
  2. +1
    -0
      v4/llm.h
  3. +4
    -0
      v4/llm.py
  4. +14
    -0
      v4/main.cpp

+ 8
- 0
v4/llm.cpp Vedi File

@@ -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);
}

+ 1
- 0
v4/llm.h Vedi File

@@ -4,6 +4,7 @@
#include <string>

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

+ 4
- 0
v4/llm.py Vedi File

@@ -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)

+ 14
- 0
v4/main.cpp Vedi File

@@ -1,7 +1,9 @@
#include <iostream>
#include <string>
#include <vector>
#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<std::string>(c.field(c.recentField))
<< std::endl;
}
};
ctrl.registerCallback(printOutput);
ctrl.registerFieldCallback("exit", [](memory_Context c) { exit(0); });

/*

auto c = shell_createContext();


Loading…
Annulla
Salva