hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Talking to the AI services. |
| 2 | //! |
| 3 | //! The AI features live in separate processes (separate repos, likely separate |
| 4 | //! languages), so this is the only seam between them and the API. It is a QUIC |
| 5 | //! bridge: the backend listens, services dial in and register the capabilities |
| 6 | //! they serve, and each request rides its own QUIC bidirectional stream over |
| 7 | //! the service's single long-lived connection. |
| 8 | //! |
| 9 | //! Why QUIC rather than HTTP: stream multiplexing is in the transport, so N |
| 10 | //! concurrent requests to one service need no correlation-id bookkeeping and |
| 11 | //! no head-of-line blocking — a 30-second inference on stream 7 does not delay |
| 12 | //! the answer on stream 9. Connection setup happens once, not per request. |
| 13 | //! |
| 14 | //! * [`api`] — which REST paths a service may read back through the bridge |
| 15 | //! * [`protocol`] — frames on the wire |
| 16 | //! * [`capability`] — the capabilities the **backend** serves, and their scopes |
| 17 | //! * [`chat`] — the JSON payloads carried for the `chat.reply` capability |
| 18 | //! * [`rag`] — the `rag.index` payloads, and the course-note dispatch behind them |
| 19 | //! * [`rag_chat`] — the `rag.chat` payloads: a scoped question and the citations behind its answer |
| 20 | //! * [`rag_study`] — the `rag.summarize`/`rag.questions` payloads: one range of one corpus, answered in one shot |
| 21 | //! * [`podcast`] — the `podcast.*` job payloads, the relay behind submit/cancel, |
| 22 | //! and the job-state report the service calls back |
| 23 | //! * [`server`] — the listener, handshake, and [`server::AiBridge::dispatch`] |
| 24 | //! * [`registry`] — who is connected here, and who gets the next request |
| 25 | //! * [`tls`] — the listener's certificate |
| 26 | //! |
| 27 | //! The transport is generic; the features land on top of it. So far that is |
| 28 | //! the chatbot (`web::chatbot`), which routes on the `chat.reply` capability, |
| 29 | //! course-note indexing (`web::course_notes`), which routes on `rag.index`, |
| 30 | //! and the podcast relay (`web::podcast`), which dispatches `podcast.submit`/ |
| 31 | //! `podcast.cancel`, serves `podcast.report`, and streams the ingested audio. |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | pub use ; |
| 48 | pub use AiError; |
| 49 | pub use |
| 50 | |
| 51 | ; |
| 52 | pub use ; |
| 53 | pub use |
| 54 | |
| 55 | ; |
| 56 | pub use ; |
| 57 | pub use ; |
| 58 | |
| 59 | use crateConfig; |
| 60 | |
| 61 | /// Start the QUIC bridge the AI services dial into, if one is configured. |
| 62 | /// |
| 63 | /// Unconfigured is a supported deployment, not a degraded one: the school API |
| 64 | /// predates the AI features and must keep running without them, so an absent |
| 65 | /// `AI_QUIC_ADDR` returns `None` and nothing else changes. A *misconfigured* |
| 66 | /// bridge is the opposite — a bad address, an unreadable certificate or a |
| 67 | /// missing token means the operator asked for AI and would otherwise get a |
| 68 | /// silently dead feature, so that fails the boot. |
| 69 | /// |
| 70 | /// In particular a set address with no `AI_SHARED_TOKEN` must never fall back |
| 71 | /// to listening: an unauthenticated bridge would let anyone who can reach the |
| 72 | /// UDP port register a worker and answer real users' messages. |
| 73 | pub async |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 |