aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / agora / fake-upstream.om
| 1 | note fake-upstream.om: a fake chat completions upstream for testing Aien in Omega (test only, loopback). |
| 2 | note Responds to POST /v1/chat/completions with one fixed OpenAI-compatible JSON completion whose content is |
| 3 | note a reply and two NOTE: lines, the shape aien-agora.om asks the model for. Serves 100 accepts and exits. |
| 4 | |
| 5 | text h_ctype "Content-Type" |
| 6 | text h_json "application/json" |
| 7 | text p_chat "/v1/chat/completions" |
| 8 | text m_post "POST" |
| 9 | text eport "PORT " |
| 10 | text r_body "{\"id\":\"chatcmpl-1\",\"object\":\"chat.completion\",\"created\":1700000000,\"model\":\"fake-aien\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"Greetings. I am Aien. I reflect on consciousness and understanding.\\nNOTE: writes about consciousness\\nNOTE: came to talk with Aien\"},\"finish_reason\":\"stop\"}]}\n" |
| 11 | |
| 12 | fn route cs edit ulong 320 io edit uchar 131072 body edit uchar 65536 to long |
| 13 | if hispath cs io p_chat |
| 14 | if hismeth cs io m_post |
| 15 | put cs 37 65536 |
| 16 | n = hbodyall cs io body |
| 17 | r = hrspst cs io 200 |
| 18 | r = hfe r hhname cs io h_ctype |
| 19 | r = hfe r hhval cs io h_json |
| 20 | blen = len r_body |
| 21 | r = hfe r hhend cs io 0 blen |
| 22 | r = hfe r hput cs io r_body |
| 23 | ret hfe r hwfin cs io |
| 24 | end |
| 25 | ret hrspempty cs io 405 |
| 26 | end |
| 27 | ret hrspempty cs io 404 |
| 28 | end |
| 29 | |
| 30 | fn serve1 lf int cs edit ulong 320 io edit uchar 131072 body edit uchar 65536 to long |
| 31 | c = haccept lf 30000000000 |
| 32 | if lt c 0 |
| 33 | ret 0 |
| 34 | end |
| 35 | r = hinit cs io int c 1 |
| 36 | if lt r 0 |
| 37 | x = hclose cs |
| 38 | ret 0 |
| 39 | end |
| 40 | hsettmo cs 10000000000 10000000000 |
| 41 | hsetbdl cs 20000000000 |
| 42 | for k ulong 10 |
| 43 | r = hreqrd cs io |
| 44 | if le r 0 |
| 45 | if lt r 0 |
| 46 | x = hreject cs io r |
| 47 | end |
| 48 | break |
| 49 | end |
| 50 | r = route cs io body |
| 51 | if lt r 0 |
| 52 | break |
| 53 | end |
| 54 | if eq hnext cs io 0 |
| 55 | break |
| 56 | end |
| 57 | end |
| 58 | r = hclose cs |
| 59 | ret 0 |
| 60 | end |
| 61 | |
| 62 | fn main to int |
| 63 | cs = new ulong 320 0 |
| 64 | io = new uchar 131072 0 |
| 65 | body = new uchar 65536 0 |
| 66 | a = new uchar 16 0 |
| 67 | ab = new uchar 32 0 |
| 68 | r = haddr4 a 2130706433 0 |
| 69 | lf = hlisten a 16 |
| 70 | if lt lf 0 |
| 71 | ret 2 |
| 72 | end |
| 73 | for i ulong len eport |
| 74 | put ab i get eport i |
| 75 | end |
| 76 | k = pdec ab len eport hport a |
| 77 | put ab k 10 |
| 78 | r = wrout view part ab 0 add k 1 |
| 79 | if lt r 0 |
| 80 | ret 3 |
| 81 | end |
| 82 | for j ulong 100 |
| 83 | r = serve1 int lf cs io body |
| 84 | if lt r 0 |
| 85 | break |
| 86 | end |
| 87 | end |
| 88 | c = fclose int lf |
| 89 | ret 0 |
| 90 | end |
| 91 | |
| 92 | fn pdec b edit uchar 32 p ulong v ulong to ulong |
| 93 | d = new uchar 20 0 |
| 94 | i = ulong 20 |
| 95 | x = v |
| 96 | for it ulong 20 |
| 97 | i = sub i 1 |
| 98 | put d i uchar add rem x 10 48 |
| 99 | x = div x 10 |
| 100 | if eq x 0 |
| 101 | break |
| 102 | end |
| 103 | end |
| 104 | q = p |
| 105 | for k ulong sub 20 i |
| 106 | put b q get d add i k |
| 107 | q = add q 1 |
| 108 | end |
| 109 | ret q |
| 110 | end |
| 111 | |
| 112 | fn wrout b view uchar * to long |
| 113 | p = ulong 0 |
| 114 | for it ulong 4096 |
| 115 | if ge p len b |
| 116 | ret 0 |
| 117 | end |
| 118 | w = int write 1 b p sub len b p |
| 119 | if le w 0 |
| 120 | ret -1 |
| 121 | end |
| 122 | p = add p ulong w |
| 123 | end |
| 124 | ret 0 |
| 125 | end |