Skip to content

Commit 79069a0

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 <eric.curtin@docker.com>
1 parent 00c361f commit 79069a0

File tree

19 files changed

+1739
-3519
lines changed

19 files changed

+1739
-3519
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ $ 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
616616
- [subprocess.h](https://github.com/sheredom/subprocess.h) - Single-header process launching solution for C and C++ - Public domain

scripts/sync_vendor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
"https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.28.0/httplib.h": "vendor/cpp-httplib/httplib.h",
2020

2121
"https://raw.githubusercontent.com/sheredom/subprocess.h/b49c56e9fe214488493021017bf3954b91c7c1f5/subprocess.h": "vendor/sheredom/subprocess.h",
22+
23+
# readline.cpp: multi-file library for interactive line editing
24+
# sync manually - no upstream repository yet
25+
# located in vendor/readline.cpp/
2226
}
2327

2428
for url, filename in vendor.items():

tools/run/CMakeLists.txt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
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+
# Include server source files (except server.cpp which has its own main())
9+
set(SERVER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../server)
10+
set(READLINE_DIR ${PROJECT_SOURCE_DIR}/vendor/readline.cpp)
11+
set(TARGET_SRCS
12+
run.cpp
13+
${SERVER_DIR}/server-context.cpp
14+
${SERVER_DIR}/server-context.h
15+
${SERVER_DIR}/server-task.cpp
16+
${SERVER_DIR}/server-task.h
17+
${SERVER_DIR}/server-queue.cpp
18+
${SERVER_DIR}/server-queue.h
19+
${SERVER_DIR}/server-common.cpp
20+
${SERVER_DIR}/server-common.h
21+
${CMAKE_CURRENT_SOURCE_DIR}/run-chat.cpp
22+
${CMAKE_CURRENT_SOURCE_DIR}/run-chat.h
23+
${READLINE_DIR}/src/readline.cpp
24+
${READLINE_DIR}/src/buffer.cpp
25+
${READLINE_DIR}/src/history.cpp
26+
${READLINE_DIR}/src/terminal.cpp
27+
)
28+
29+
add_executable(${TARGET} ${TARGET_SRCS})
330

431
# TODO: avoid copying this code block from common/CMakeLists.txt
532
set(LLAMA_RUN_EXTRA_LIBS "")
@@ -19,5 +46,17 @@ if (CMAKE_SYSTEM_NAME MATCHES "AIX")
1946
target_link_libraries(${TARGET} PRIVATE -lbsd)
2047
endif()
2148

22-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${LLAMA_RUN_EXTRA_LIBS})
49+
# Include directories for server headers and readline
50+
target_include_directories(${TARGET} PRIVATE ${SERVER_DIR})
51+
target_include_directories(${TARGET} PRIVATE ${SERVER_DIR}/../mtmd)
52+
target_include_directories(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR})
53+
target_include_directories(${TARGET} PRIVATE ${READLINE_DIR}/include)
54+
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
55+
56+
target_link_libraries(${TARGET} PRIVATE common mtmd llama ${CMAKE_THREAD_LIBS_INIT} ${LLAMA_RUN_EXTRA_LIBS})
57+
58+
if (WIN32)
59+
target_link_libraries(${TARGET} PRIVATE ws2_32)
60+
endif()
61+
2362
target_compile_features(${TARGET} PRIVATE cxx_std_17)

0 commit comments

Comments
 (0)