hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Payload contract for the `rag.summarize` and `rag.questions` capabilities. |
| 2 | //! |
| 3 | //! Same transport as every other capability: JSON inside a |
| 4 | //! [`Request::payload`](crate::ai::protocol::Request::payload) and coming back |
| 5 | //! inside [`Response::Ok`](crate::ai::protocol::Response::Ok)`::payload`. What |
| 6 | //! differs from [`super::rag_chat`] is the shape of a turn: those are |
| 7 | //! thread-bound and asynchronous (a `202`, a stored row, a poll), while these |
| 8 | //! two are **one-shot** — the caller names exactly one corpus and a range |
| 9 | //! inside it and waits for the artifact itself (a summary, or a set of |
| 10 | //! practice questions). Nothing is stored on either side of the bridge, so the |
| 11 | //! reply *is* the answer. |
| 12 | //! |
| 13 | //! The scope is one `(sinif, ders)` pair plus the page/span range inside it. |
| 14 | //! Which pairs the asker may name is the backend's own derivation |
| 15 | //! ([`crate::service::rag_scope`]) and the caller's body only picks a target |
| 16 | //! within them, so the pair that travels here is already the authorized one. |
| 17 | //! The asker rides along for the same reason it does on `rag.chat`: the service |
| 18 | //! may read that person's own data back through the bridge's api reads |
| 19 | //! (`on_behalf_of`). |
| 20 | |
| 21 | use Duration; |
| 22 | |
| 23 | use ; |
| 24 | |
| 25 | use crateAiBridge; |
| 26 | use crate |
| 27 | |
| 28 | |
| 29 | ; |
| 30 | use crateSchoolId; |
| 31 | |
| 32 | /// The one corpus a study request is addressed to, and where inside it. |
| 33 | /// |
| 34 | /// One scope, never a list: a summary or a question set is *about* the |
| 35 | /// material the caller selected, and a range spanning several corpora has no |
| 36 | /// single thing to be about. |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | /// What the backend asks a RAG service to summarize (`rag.summarize`). |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | /// What the backend asks a RAG service for (`rag.questions`). |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | /// One passage a summary drew on, inside the reply's `citations`. |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | /// The service's summary, inside `Response::Ok { payload }`. |
| 121 | /// |
| 122 | /// Handled failures do *not* come back here — they use the existing |
| 123 | /// [`Response::Err`](crate::ai::protocol::Response::Err) `{ code, message }`, |
| 124 | /// so there is exactly one failure shape on the bridge for every capability. |
| 125 | /// A refusal that is part of the answer (nothing in the named range to |
| 126 | /// summarize, a guard) rides here with `abstained: true` and a `reason`: the |
| 127 | /// request completes, and nothing is reported as an error. |
| 128 | /// |
| 129 | /// Unlike `rag.chat`'s citations, these carry **no corpus `doc_id`** — a |
| 130 | /// summary is addressed to a range the caller selected, not scoped to one |
| 131 | /// document — so nothing here resolves to a course-note file. |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | /// One generated practice question, inside the reply's `items`. |
| 159 | /// |
| 160 | /// The keys are the **service's** own (`soru`/`cevap`/`zorluk`) — the wire |
| 161 | /// mirrors the service's vocabulary exactly as `rag.chat` mirrors its own, and |
| 162 | /// the HTTP door is where they become this API's English field names. |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | /// The service's generated question set, inside `Response::Ok { payload }`. |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | /// Ask a RAG service to summarize one range of one corpus. |
| 197 | /// |
| 198 | /// `Err` is a short, stable code for the door's refusal table — a transport |
| 199 | /// failure, the service's own `Response::Err` verdict, or `bad_reply` when the |
| 200 | /// reply was unreadable. Two codes are special: `role_required` and |
| 201 | /// `scope_mismatch` mean the **backend** composed a request the service may not |
| 202 | /// answer (the pair or the role it sent), so they are logged as bugs here and |
| 203 | /// reach the caller as a `502` — the same posture `rag.chat` takes. |
| 204 | pub async |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | /// Ask a RAG service to generate practice questions over one range of one |
| 226 | /// corpus. The refusal vocabulary is [`summarize`]'s, code for code. |
| 227 | pub async |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | /// Encode one payload; a payload that cannot be encoded is this side's bug, so |
| 249 | /// it is logged and reported as `internal` rather than as a service verdict. |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | /// Decode one service reply, wrapped in the capability's name. An unreadable |
| 258 | /// payload is `bad_reply`: the answer is not safe to guess at, and a service |
| 259 | /// that changed its shape must be seen failing rather than half-read. |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | /// The two verdicts that mean the **backend** built a bad request: the scope or |
| 271 | /// the role it sent is not something the service may answer. The request still |
| 272 | /// fails — an artifact is not safe to invent — but this side of the bridge is |
| 273 | /// the bug, so it is logged as one rather than as an ordinary service refusal. |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | /// A dispatch failure as a short, stable code the frontend can branch on. The |
| 285 | /// same mapping the chatbot nest applies to its own round trip. |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 |