MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / create_lm_server

Function create_lm_server

src/server/server.cpp:864–1090  ·  view source on GitHub ↗

@brief create lm server @param models the model list @param downloader the downloader @param default_tag the default tag @param port the port @return the server

Source from the content-addressed store, hash-verified

862///@param port the port
863///@return the server
864std::unique_ptr<WebServer> create_lm_server(model_list& models, ModelDownloader& downloader, program_args_t& args) {
865 auto server = std::make_unique<WebServer>(args.host, args.port, args.cors);
866 auto rest_handler = std::make_shared<RestHandler>(models, downloader, args);
867
868 // Register Ollama-compatible routes
869 server->register_handler("POST", "/api/show",
870 [rest_handler](const http::request<http::string_body>& req,
871 std::function<void(const json&)> send_response,
872 std::function<void(const json&, bool)> send_streaming_response,
873 std::shared_ptr<HttpSession> session,
874 std::shared_ptr<CancellationToken> cancellation_token) {
875 json request_json;
876 if (!req.body().empty()) {
877 request_json = json::parse(req.body());
878 }
879 rest_handler->handle_show(request_json, send_response, send_streaming_response);
880 });
881
882 server->register_handler("POST", "/api/generate",
883 [rest_handler](const http::request<http::string_body>& req,
884 std::function<void(const json&)> send_response,
885 std::function<void(const json&, bool)> send_streaming_response,
886 std::shared_ptr<HttpSession> session,
887 std::shared_ptr<CancellationToken> cancellation_token) {
888 json request_json;
889 if (!req.body().empty()) {
890 request_json = json::parse(req.body());
891 }
892 rest_handler->handle_generate(request_json, send_response, send_streaming_response, cancellation_token);
893 });
894
895 server->register_handler("POST", "/api/chat",
896 [rest_handler](const http::request<http::string_body>& req,
897 std::function<void(const json&)> send_response,
898 std::function<void(const json&, bool)> send_streaming_response,
899 std::shared_ptr<HttpSession> session,
900 std::shared_ptr<CancellationToken> cancellation_token) {
901 json request_json;
902 if (!req.body().empty()) {
903 request_json = json::parse(req.body());
904 }
905 rest_handler->handle_chat(request_json, send_response, send_streaming_response, cancellation_token);
906 });
907
908 server->register_handler("GET", "/api/ps",
909 [rest_handler](const http::request<http::string_body>& req,
910 std::function<void(const json&)> send_response,
911 std::function<void(const json&, bool)> send_streaming_response,
912 std::shared_ptr<HttpSession> session,
913 std::shared_ptr<CancellationToken> cancellation_token) {
914 json request_json;
915 rest_handler->handle_ps(request_json, send_response, send_streaming_response);
916 });
917
918 server->register_handler("POST", "/api/embeddings",
919 [rest_handler](const http::request<http::string_body>& req,
920 std::function<void(const json&)> send_response,
921 std::function<void(const json&, bool)> send_streaming_response,

Callers 1

mainFunction · 0.85

Calls 15

parseFunction · 0.85
parse_multipartFunction · 0.85
register_handlerMethod · 0.80
handle_showMethod · 0.80
handle_generateMethod · 0.80
handle_chatMethod · 0.80
handle_psMethod · 0.80
handle_embeddingsMethod · 0.80
handle_modelsMethod · 0.80
handle_versionMethod · 0.80
handle_pullMethod · 0.80
handle_models_openaiMethod · 0.80

Tested by

no test coverage detected