| 111 | } |
| 112 | |
| 113 | // ─── piecewise keep-ratio curve ───────────────────────────────────────── |
| 114 | |
| 115 | static float pflash_keep_ratio(const ServerConfig & cfg, int n_tokens) { |
| 116 | if (cfg.pflash_curve.empty()) return cfg.pflash_keep_ratio; |
| 117 | const auto & curve = cfg.pflash_curve; |
| 118 | if (n_tokens <= curve.front().first) return curve.front().second; |
| 119 | if (n_tokens >= curve.back().first) return curve.back().second; |
| 120 | for (size_t i = 0; i + 1 < curve.size(); ++i) { |
| 121 | if (n_tokens <= curve[i + 1].first) { |
| 122 | float t = (float)(n_tokens - curve[i].first) / |
| 123 | (float)(curve[i + 1].first - curve[i].first); |
| 124 | return curve[i].second + t * (curve[i + 1].second - curve[i].second); |
| 125 | } |
| 126 | } |
| 127 | return curve.back().second; |
| 128 | } |
| 129 |
no test coverage detected