| 799 | } |
| 800 | |
| 801 | server_http_res_ptr server_models::proxy_request(const server_http_req & req, const std::string & method, const std::string & name, bool update_last_used) { |
| 802 | auto meta = get_meta(name); |
| 803 | if (!meta.has_value()) { |
| 804 | throw std::runtime_error("model name=" + name + " is not found"); |
| 805 | } |
| 806 | if (!meta->is_running()) { |
| 807 | throw std::invalid_argument("model name=" + name + " is not running"); |
| 808 | } |
| 809 | if (update_last_used) { |
| 810 | std::unique_lock<std::mutex> lk(mutex); |
| 811 | mapping[name].meta.last_used = ggml_time_ms(); |
| 812 | } |
| 813 | SRV_INF("proxying request to model %s on port %d\n", name.c_str(), meta->port); |
| 814 | std::string proxy_path = req.path; |
| 815 | if (!req.query_string.empty()) { |
| 816 | proxy_path += '?' + req.query_string; |
| 817 | } |
| 818 | auto proxy = std::make_unique<server_http_proxy>( |
| 819 | method, |
| 820 | "http", |
| 821 | CHILD_ADDR, |
| 822 | meta->port, |
| 823 | proxy_path, |
| 824 | req.headers, |
| 825 | req.body, |
| 826 | req.should_stop, |
| 827 | base_params.timeout_read, |
| 828 | base_params.timeout_write |
| 829 | ); |
| 830 | return proxy; |
| 831 | } |
| 832 | |
| 833 | bool server_models::is_child_server() { |
| 834 | const char * router_port = std::getenv("LLAMA_SERVER_ROUTER_PORT"); |
no test coverage detected