(
state: web::Data<Arc<RwLock<Master<M>>>>,
req: HttpRequest,
body: web::Json<ChatRequest>,
)
| 99 | } |
| 100 | |
| 101 | pub async fn generate_text<M: Model>( |
| 102 | state: web::Data<Arc<RwLock<Master<M>>>>, |
| 103 | req: HttpRequest, |
| 104 | body: web::Json<ChatRequest>, |
| 105 | ) -> impl Responder { |
| 106 | let client = req |
| 107 | .peer_addr() |
| 108 | .map(|a| a.to_string()) |
| 109 | .unwrap_or_else(|| "unknown".to_string()); |
| 110 | let stream = body.0.stream.unwrap_or(false); |
| 111 | |
| 112 | log::info!("starting chat for {} (stream={}) ...", &client, stream); |
| 113 | |
| 114 | if stream { |
| 115 | generate_text_stream(state, body.0).await |
| 116 | } else { |
| 117 | generate_text_blocking(state, body.0).await |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | async fn generate_text_blocking<M: Model>( |
| 122 | state: web::Data<Arc<RwLock<Master<M>>>>, |
nothing calls this directly
no test coverage detected