llama-impl.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * llama.cpp - commit 8962422b1c6f9b8b15f5aeaea42600bcc2d44177 - do not edit this file
  3. *
  4. * MIT License
  5. *
  6. * Copyright (c) 2023-2024 The ggml authors
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all
  16. * copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. */
  26. #pragma once
  27. #define LLAMA_API_INTERNAL
  28. #include "llama.h"
  29. #ifdef __GNUC__
  30. #ifdef __MINGW32__
  31. #define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
  32. #else
  33. #define LLAMA_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
  34. #endif
  35. #else
  36. #define LLAMA_ATTRIBUTE_FORMAT(...)
  37. #endif
  38. //
  39. // logging
  40. //
  41. LLAMA_ATTRIBUTE_FORMAT(2, 3)
  42. void llama_log_internal (ggml_log_level level, const char * format, ...);
  43. void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data);
  44. #define LLAMA_LOG_INFO(...) llama_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
  45. #define LLAMA_LOG_WARN(...) llama_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__)
  46. #define LLAMA_LOG_ERROR(...) llama_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__)
  47. //
  48. // helpers
  49. //
  50. static void replace_all(std::string & s, const std::string & search, const std::string & replace) {
  51. if (search.empty()) {
  52. return;
  53. }
  54. std::string builder;
  55. builder.reserve(s.length());
  56. size_t pos = 0;
  57. size_t last_pos = 0;
  58. while ((pos = s.find(search, last_pos)) != std::string::npos) {
  59. builder.append(s, last_pos, pos - last_pos);
  60. builder.append(replace);
  61. last_pos = pos + search.length();
  62. }
  63. builder.append(s, last_pos, std::string::npos);
  64. s = std::move(builder);
  65. }