mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-21 14:08:11 +02:00
Lot 8 : téléchargements de modèles tenus par la façade (LOKI_DOWNLOADS=rust)
La façade Rust mène les téléchargements de .gguf quand LOKI_DOWNLOADS=rust (expérimental ; le Go reste le défaut) : sonde, lancement, suivi, annulation, avec les mêmes contrats et la même mécanique que le Go (tranches rapatriées en entier, plages d'octets parallèles, reprise, place disque vérifiée sur le total, jeton réservé aux hôtes Hugging Face, refus traduits, .part vidés au démarrage). Côté Go : facade_downloads.go remet ces routes à la façade quand elles arrivent par le tunnel du relais, et le Go ne vide plus les .part qu'elle mène. Parité : journal des fonctions pures tiré du Go (parity_dl_test.go) et rejoué en Rust ; téléchargements de bout en bout contre un faux Hugging Face (tests/downloads.rs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016tcGfJWefW5kUGoC2wL8cv
This commit is contained in:
20 files changed
+2820
-17
No files matched your search
@@ -427,7 +427,16 @@ async fn handle(st: Arc<FakeGo>, req: Request<Incoming>) -> Response<Full<Bytes>
|
||||
/// Lance le faux Go puis la façade devant lui ; rend (adresse de la façade,
|
||||
/// état du faux Go, garde d'arrêt).
|
||||
pub async fn start(home: std::path::PathBuf) -> (SocketAddr, Arc<FakeGo>, oneshot::Sender<()>) {
|
||||
let (f, st, tx, _) = start_opts(home, false, None).await;
|
||||
let (f, st, tx, _) = start_opts(home, false, None, false).await;
|
||||
(f, st, tx)
|
||||
}
|
||||
|
||||
/// Comme [`start`], avec les téléchargements de modèles tenus par la façade
|
||||
/// (`LOKI_DOWNLOADS=rust`).
|
||||
pub async fn start_downloads(
|
||||
home: std::path::PathBuf,
|
||||
) -> (SocketAddr, Arc<FakeGo>, oneshot::Sender<()>) {
|
||||
let (f, st, tx, _) = start_opts(home, false, None, true).await;
|
||||
(f, st, tx)
|
||||
}
|
||||
|
||||
@@ -442,7 +451,7 @@ pub async fn start_chat(
|
||||
oneshot::Sender<()>,
|
||||
Arc<loki_rs::chat::generate::ChatService>,
|
||||
) {
|
||||
let (f, st, tx, chat) = start_opts(home, true, Some(engine_port)).await;
|
||||
let (f, st, tx, chat) = start_opts(home, true, Some(engine_port), false).await;
|
||||
(f, st, tx, chat.unwrap())
|
||||
}
|
||||
|
||||
@@ -450,6 +459,7 @@ async fn start_opts(
|
||||
home: std::path::PathBuf,
|
||||
with_chat: bool,
|
||||
engine_port: Option<u16>,
|
||||
with_downloads: bool,
|
||||
) -> (
|
||||
SocketAddr,
|
||||
Arc<FakeGo>,
|
||||
@@ -506,6 +516,7 @@ async fn start_opts(
|
||||
service: "loki-engine".into(),
|
||||
},
|
||||
chat: chat.clone(),
|
||||
downloads: with_downloads.then(|| Arc::new(loki_rs::downloads::Downloads::new())),
|
||||
};
|
||||
tokio::spawn(loki_rs::proxy::serve(fl, cfg, async move {
|
||||
let _ = rx.await;
|
||||
@@ -513,6 +524,32 @@ async fn start_opts(
|
||||
(facade, st, tx, chat)
|
||||
}
|
||||
|
||||
/// Requête via la façade (corps JSON) : (code, corps).
|
||||
pub async fn send(
|
||||
facade: SocketAddr,
|
||||
method: &str,
|
||||
path: &str,
|
||||
headers: &[(&str, &str)],
|
||||
body: &str,
|
||||
) -> (StatusCode, Bytes) {
|
||||
use hyper_util::client::legacy::Client;
|
||||
use hyper_util::rt::TokioExecutor;
|
||||
let mut req = Request::builder()
|
||||
.method(method)
|
||||
.uri(format!("http://{facade}{path}"))
|
||||
.header("content-type", "application/json");
|
||||
for (k, v) in headers {
|
||||
req = req.header(*k, *v);
|
||||
}
|
||||
let client: Client<_, Full<Bytes>> = Client::builder(TokioExecutor::new()).build_http();
|
||||
let r = client
|
||||
.request(req.body(Full::new(Bytes::from(body.to_string()))).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
let (parts, body) = r.into_parts();
|
||||
(parts.status, body.collect().await.unwrap().to_bytes())
|
||||
}
|
||||
|
||||
/// GET via la façade : (code, en-têtes, corps).
|
||||
pub async fn get(
|
||||
facade: SocketAddr,
|
||||
|
||||
Reference in new issue
Block a user