Description
Motivation
As seen on #4216 , one of the important task is to refactor / clean up the server code so that it's easier to maintain. However, without a detailed plan, personally I feel like it's unlikely to be archived.
This issue is created so that we can discuss about how to refactor or clean up the code.
The goal is to help existing and new contributors to easily find out where to work in the code base.
Current architecture
The current server implementation has 2 thread: one for HTTP part and one for inference.
- The direction from HTTP ==> inference thread is done by
llama_server_queue.post(task)
- The direction from inference ==> HTTP thread is done by
llama_server_response.send(result)
Ideas
Feel free to suggest any ideas that you find helpful (please keep in mind that we do not introduce new features here, just to re-write the code):
-
Abstract out
llama_server_queue
andllama_server_response
, mutexes are now bound to these 2 structs (already finished)
Server: try to refactor server.cpp #5065 -
Renaming and move structs to
utils.hpp
: Clean up server code #5762 (comment)
Server: normalize naming #5779 -
Investigate httplib to see if we can use more functions already exist in this lib, for example CORS can be done using
set_post_routing_handler
(the same idea with "middleware" in high level web frameworks) -
Merge handlers of
/v1/{endpoints}
and/{endpoints}
to prevent code duplications
Add "/chat/completions" as alias for "/v1/chat/completions" #5722 -
No more hard-coding js files into hpp, as these files pollute the code base. They should be converted to hpp by using code generation (like how
build-info.cpp
is generated incommon.cpp
)
build
: generate hex dump of server assets during build #6661