interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / agora / fake-upstream.om

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