Skip to content

Commit a449065

Browse files
committed
New llama-run
- Added readline.cpp include - Created run_chat_mode(): - Initializes readline with command history - Maintains conversation history - Applies chat templates to format messages - Submits completion tasks to the server queue - Displays assistant responses interactively Signed-off-by: Eric Curtin <[email protected]>
1 parent ddf9f94 commit a449065

File tree

21 files changed

+4316
-5994
lines changed

21 files changed

+4316
-5994
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,6 @@ $ echo "source ~/.llama-completion.bash" >> ~/.bashrc
610610
- [stb-image](https://github.com/nothings/stb) - Single-header image format decoder, used by multimodal subsystem - Public domain
611611
- [nlohmann/json](https://github.com/nlohmann/json) - Single-header JSON library, used by various tools/examples - MIT License
612612
- [minja](https://github.com/google/minja) - Minimal Jinja parser in C++, used by various tools/examples - MIT License
613-
- [linenoise.cpp](./tools/run/linenoise.cpp/linenoise.cpp) - C++ library that provides readline-like line editing capabilities, used by `llama-run` - BSD 2-Clause License
613+
- [readline.cpp](https://github.com/ericcurtin/readline.cpp) - C++ library that provides readline-like line editing capabilities, used by `llama-run` - MIT License
614614
- [curl](https://curl.se/) - Client-side URL transfer library, used by various tools/examples - [CURL License](https://curl.se/docs/copyright.html)
615615
- [miniaudio.h](https://github.com/mackron/miniaudio) - Single-header audio format decoder, used by multimodal subsystem - Public domain

common/download.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ std::pair<long, std::vector<char>> common_remote_get_content(const std::string &
430430
curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
431431
curl_easy_setopt(curl.get(), CURLOPT_NOPROGRESS, 1L);
432432
curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
433-
curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 1L);
433+
curl_easy_setopt(curl.get(), CURLOPT_VERBOSE, 0L);
434434
typedef size_t(*CURLOPT_WRITEFUNCTION_PTR)(void * ptr, size_t size, size_t nmemb, void * data);
435435
auto write_callback = [](void * ptr, size_t size, size_t nmemb, void * data) -> size_t {
436436
auto data_vec = static_cast<std::vector<char> *>(data);

tools/run/CMakeLists.txt

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
set(TARGET llama-run)
2-
add_executable(${TARGET} run.cpp linenoise.cpp/linenoise.cpp)
2+
3+
if (MINGW)
4+
# fix: https://github.com/ggml-org/llama.cpp/actions/runs/9651004652/job/26617901362?pr=8006
5+
add_compile_definitions(_WIN32_WINNT=${GGML_WIN_VER})
6+
endif()
7+
8+
if (NOT LLAMA_HTTPLIB)
9+
message(FATAL_ERROR "LLAMA_HTTPLIB is OFF, cannot build llama-run. Hint: to skip building run, set -DLLAMA_BUILD_RUN=OFF")
10+
endif()
11+
12+
# Include server source files (except server.cpp which has its own main())
13+
set(SERVER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../server)
14+
set(TARGET_SRCS
15+
run.cpp
16+
${SERVER_DIR}/server-http.cpp
17+
${SERVER_DIR}/server-http.h
18+
${SERVER_DIR}/server-task.cpp
19+
${SERVER_DIR}/server-task.h
20+
${SERVER_DIR}/server-queue.cpp
21+
${SERVER_DIR}/server-queue.h
22+
${SERVER_DIR}/server-common.cpp
23+
${SERVER_DIR}/server-common.h
24+
${CMAKE_CURRENT_SOURCE_DIR}/run-chat.cpp
25+
${CMAKE_CURRENT_SOURCE_DIR}/run-chat.h
26+
${CMAKE_CURRENT_SOURCE_DIR}/readline.cpp/src/readline.cpp
27+
${CMAKE_CURRENT_SOURCE_DIR}/readline.cpp/src/buffer.cpp
28+
${CMAKE_CURRENT_SOURCE_DIR}/readline.cpp/src/history.cpp
29+
${CMAKE_CURRENT_SOURCE_DIR}/readline.cpp/src/terminal.cpp
30+
)
31+
32+
# Generate public asset headers (needed by server-http.cpp)
33+
set(PUBLIC_ASSETS
34+
index.html.gz
35+
loading.html
36+
)
37+
38+
foreach(asset ${PUBLIC_ASSETS})
39+
set(input "${SERVER_DIR}/public/${asset}")
40+
set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp")
41+
list(APPEND TARGET_SRCS ${output})
42+
add_custom_command(
43+
DEPENDS "${input}"
44+
OUTPUT "${output}"
45+
COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/scripts/xxd.cmake"
46+
)
47+
set_source_files_properties(${output} PROPERTIES GENERATED TRUE)
48+
endforeach()
49+
50+
add_executable(${TARGET} ${TARGET_SRCS})
351

452
# TODO: avoid copying this code block from common/CMakeLists.txt
553
set(LLAMA_RUN_EXTRA_LIBS "")
@@ -19,5 +67,17 @@ if (CMAKE_SYSTEM_NAME MATCHES "AIX")
1967
target_link_libraries(${TARGET} PRIVATE -lbsd)
2068
endif()
2169

22-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${LLAMA_RUN_EXTRA_LIBS})
70+
# Include directories for server headers and readline
71+
target_include_directories(${TARGET} PRIVATE ${SERVER_DIR})
72+
target_include_directories(${TARGET} PRIVATE ${SERVER_DIR}/../mtmd)
73+
target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR})
74+
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/readline.cpp/include)
75+
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
76+
77+
target_link_libraries(${TARGET} PRIVATE common mtmd llama cpp-httplib ${CMAKE_THREAD_LIBS_INIT} ${LLAMA_RUN_EXTRA_LIBS})
78+
79+
if (WIN32)
80+
target_link_libraries(${TARGET} PRIVATE ws2_32)
81+
endif()
82+
2383
target_compile_features(${TARGET} PRIVATE cxx_std_17)

0 commit comments

Comments
 (0)