Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Use float to string conversion
Justine Tunney263d39b48e65
diff --git a/llamafile/server/json.cpp b/llamafile/server/json.cppindex 8f03c57b..4e62c4d0 100644--- a/llamafile/server/json.cpp+++ b/llamafile/server/json.cpp@@ -76,10 +76,19 @@ encode_json(char* p, unsigned long x) noexceptreturn FormatUint64(p, x);}+char*+encode_json(char* p, float x) noexcept+{+ double_conversion::StringBuilder b(p, 256);+ kDoubleToJson.ToShortestSingle(x, &b);+ b.Finalize();+ return p + strlen(p);+}+char*encode_json(char* p, double x) noexcept{- double_conversion::StringBuilder b(p, 128);+ double_conversion::StringBuilder b(p, 256);kDoubleToJson.ToShortest(x, &b);b.Finalize();return p + strlen(p);diff --git a/llamafile/server/json.h b/llamafile/server/json.hindex 99ab5e0d..0bee2b0c 100644--- a/llamafile/server/json.h+++ b/llamafile/server/json.h@@ -27,6 +27,9 @@ encode_json(char*, int) noexcept;char*encode_json(char*, long) noexcept;+char*+encode_json(char*, float) noexcept;+char*encode_json(char*, double) noexcept;