llama-impl.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #define LLAMA_API_INTERNAL
  3. #include "llama.h"
  4. #ifdef __GNUC__
  5. #ifdef __MINGW32__
  6. #define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
  7. #else
  8. #define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
  9. #endif
  10. #else
  11. #define LLAMA_ATTRIBUTE_FORMAT(...)
  12. #endif
  13. //
  14. // logging
  15. //
  16. LLAMA_ATTRIBUTE_FORMAT(2, 3)
  17. void llama_log_internal (ggml_log_level level, const char * format, ...);
  18. void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data);
  19. #define LLAMA_LOG_INFO(...) llama_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
  20. #define LLAMA_LOG_WARN(...) llama_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__)
  21. #define LLAMA_LOG_ERROR(...) llama_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
  22. //
  23. // helpers
  24. //
  25. static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
  26. if (search.empty()) {
  27. return; // Avoid infinite loop if 'search' is an empty string
  28. }
  29. size_t pos = 0;
  30. while ((pos = s.find(search, pos)) != std::string::npos) {
  31. s.replace(pos, search.length(), replace);
  32. pos += replace.length();
  33. }
  34. }