hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! RAG message workflows: the turns of a thread. Sending is asynchronous by |
| 2 | //! design — the send path writes the user's question plus a `pending` |
| 3 | //! assistant row and answers at once; the answering task settles that row |
| 4 | //! later with [`complete`] or [`fail`], and the read paths present a |
| 5 | //! long-stale `pending` as failed via the domain's read-time projection |
| 6 | //! (see [`RagMessage::projected`]). The queries live in |
| 7 | //! [`crate::db::rag_message`]. |
| 8 | |
| 9 | use crateDatabase; |
| 10 | use craterag_message; |
| 11 | use crate; |
| 12 | use crateRagThreadId; |
| 13 | use crateUserId; |
| 14 | use crateAppError; |
| 15 | use Json; |
| 16 | |
| 17 | /// Append the user's question. Nothing is awaited for it, so it is born |
| 18 | /// complete. |
| 19 | pub async |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | /// Reserve the assistant's answer *before* the AI call: the row exists, |
| 29 | /// empty and `pending`, so a reload finds the turn and can wait on it. |
| 30 | pub async |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | /// The whole thread, oldest first — the order both the UI and the AI |
| 39 | /// history payload read in. |
| 40 | pub async |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | /// The last `limit` *settled* turns that carry text, still oldest-first — |
| 50 | /// the tail replayed to the AI service as context. |
| 51 | pub async |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | /// The user turn a reserved answer belongs to, by *identity*: the question |
| 60 | /// row of the very POST that reserved it, whose id the answering task |
| 61 | /// carries. |
| 62 | pub async |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | /// Read one turn only if `user` owns it — the poll loop's read. |
| 70 | pub async |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | /// Land the answer: its text and the service's reply (abstention, reason, |
| 79 | /// citations). Gated on `status = 'pending'`, so a late answer can't |
| 80 | /// overwrite a row that was already failed. |
| 81 | pub async |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | /// Mark the answer failed with a short code (`unavailable`, the service's |
| 91 | /// own error code, …). Same pending gate as [`complete`]. |
| 92 | pub async |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 |