Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ add_library(${TARGET} STATIC
arg.cpp
arg.h
base64.hpp
chat.cpp
chat.h
chat-parser.cpp
chat-parser.h
chat.cpp
chat.h
common.cpp
common.h
console.cpp
console.h
json-schema-to-grammar.cpp
json.hpp
json-partial.h
json-partial.cpp
json-partial.h
json-schema-to-grammar.cpp
llguidance.cpp
log.cpp
log.h
minja/chat-template.hpp
minja/minja.hpp
ngram-cache.cpp
ngram-cache.h
nlohmann/json.hpp
regex-partial.cpp
regex-partial.h
sampling.cpp
Expand Down
3 changes: 2 additions & 1 deletion common/chat-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#include "chat.h"
#include "json-partial.h"
#include "json.hpp"
#include "regex-partial.h"

#include "nlohmann/json.hpp"

#include <optional>
#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion common/json-partial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "log.h"
#include <string>

#include <json.hpp>
#include <nlohmann/json.hpp>

using json = nlohmann::ordered_json;

Expand Down
2 changes: 1 addition & 1 deletion common/json-partial.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <json.hpp>
#include <nlohmann/json.hpp>

// Healing marker (empty if the JSON was fully parsed / wasn't healed).
struct common_healing_marker {
Expand Down
2 changes: 1 addition & 1 deletion common/json-schema-to-grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "ggml.h"
// Change JSON_ASSERT from assert() to GGML_ASSERT:
#define JSON_ASSERT GGML_ASSERT
#include "json.hpp"
#include "nlohmann/json.hpp"

std::string json_schema_to_grammar(const nlohmann::ordered_json & schema,
bool force_gbnf = false);
Expand Down
2 changes: 1 addition & 1 deletion common/minja/chat-template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string>
#include <vector>

#include <json.hpp>
#include <nlohmann/json.hpp>

using json = nlohmann::ordered_json;

Expand Down
2 changes: 1 addition & 1 deletion common/minja/minja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <utility>
#include <vector>

#include <json.hpp>
#include <nlohmann/json.hpp>

using json = nlohmann::ordered_json;

Expand Down
5,294 changes: 3,027 additions & 2,267 deletions common/json.hpp → common/nlohmann/json.hpp

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions scripts/sync_vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

import urllib.request

vendor = {
"https://github.com/nlohmann/json/releases/latest/download/json.hpp": "common/nlohmann/json.hpp",

# sync manually
# "https://raw.githubusercontent.com/ochafik/minja/refs/heads/main/include/minja/minja.hpp": "common/minja/minja.hpp",
# "https://raw.githubusercontent.com/ochafik/minja/refs/heads/main/include/minja/chat-template.hpp": "common/minja/chat-template.hpp",

"https://raw.githubusercontent.com/nothings/stb/refs/heads/master/stb_image.h": "tools/mtmd/vendor/stb_image.h",

"https://github.com/mackron/miniaudio/raw/refs/tags/0.11.22/miniaudio.h": "tools/mtmd/vendor/miniaudio.h",

"https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.20.1/httplib.h": "tools/server/httplib.h",
}

for url, filename in vendor.items():
print(f"downloading {url} to {filename}") # noqa: NP100
urllib.request.urlretrieve(url, filename)
3 changes: 2 additions & 1 deletion tests/test-chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
//
#include <fstream>
#include <iostream>
#include <json.hpp>
#include <string>

#include <nlohmann/json.hpp>

#include "chat.h"

#include "../src/unicode.h"
Expand Down
5 changes: 3 additions & 2 deletions tools/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@

#include "chat.h"
#include "common.h"
#include "json.hpp"
#include "linenoise.cpp/linenoise.h"
#include "llama-cpp.h"
#include "log.h"

#include "nlohmann/json.hpp"
#include "linenoise.cpp/linenoise.h"

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
[[noreturn]] static void sigint_handler(int) {
printf("\n" LOG_COL_DEFAULT);
Expand Down
18 changes: 15 additions & 3 deletions tools/server/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_HTTPLIB_H

#define CPPHTTPLIB_VERSION "0.20.0"
#define CPPHTTPLIB_VERSION "0.20.1"

/*
* Configuration
Expand Down Expand Up @@ -145,6 +145,10 @@
#define CPPHTTPLIB_LISTEN_BACKLOG 5
#endif

#ifndef CPPHTTPLIB_MAX_LINE_LENGTH
#define CPPHTTPLIB_MAX_LINE_LENGTH 32768
#endif

/*
* Headers
*/
Expand Down Expand Up @@ -3067,6 +3071,11 @@ inline bool stream_line_reader::getline() {
#endif

for (size_t i = 0;; i++) {
if (size() >= CPPHTTPLIB_MAX_LINE_LENGTH) {
// Treat exceptionally long lines as an error to
// prevent infinite loops/memory exhaustion
return false;
}
char byte;
auto n = strm_.read(&byte, 1);

Expand Down Expand Up @@ -6055,6 +6064,8 @@ inline void calc_actual_timeout(time_t max_timeout_msec, time_t duration_msec,
auto actual_timeout_msec =
(std::min)(max_timeout_msec - duration_msec, timeout_msec);

if (actual_timeout_msec < 0) { actual_timeout_msec = 0; }

actual_timeout_sec = actual_timeout_msec / 1000;
actual_timeout_usec = (actual_timeout_msec % 1000) * 1000;
}
Expand Down Expand Up @@ -7327,8 +7338,9 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
}

// Setup `is_connection_closed` method
req.is_connection_closed = [&]() {
return !detail::is_socket_alive(strm.socket());
auto sock = strm.socket();
req.is_connection_closed = [sock]() {
return !detail::is_socket_alive(sock);
};

// Routing
Expand Down
2 changes: 1 addition & 1 deletion tools/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// Change JSON_ASSERT from assert() to GGML_ASSERT:
#define JSON_ASSERT GGML_ASSERT
#include "json.hpp"
#include "nlohmann/json.hpp"
// mime type for sending response
#define MIMETYPE_JSON "application/json; charset=utf-8"

Expand Down
4 changes: 2 additions & 2 deletions tools/server/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base64.hpp"
#include "mtmd.h"
#include "mtmd-helper.h"
#include "chat.h"

// increase max payload length to allow use of larger context size
#define CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH 1048576
Expand All @@ -16,8 +17,7 @@

// Change JSON_ASSERT from assert() to GGML_ASSERT:
#define JSON_ASSERT GGML_ASSERT
#include "json.hpp"
#include "chat.h"
#include "nlohmann/json.hpp"

#include <random>
#include <sstream>
Expand Down
3 changes: 2 additions & 1 deletion tools/tts/tts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "sampling.h"
#include "log.h"
#include "llama.h"
#include "json.hpp"

#include "nlohmann/json.hpp"

#include <algorithm>
#include <cmath>
Expand Down
Loading