-
Notifications
You must be signed in to change notification settings - Fork 75
/
main_deno.mjs
741 lines (723 loc) · 22.1 KB
/
main_deno.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
// node_modules/.deno/itty-router@5.0.17/node_modules/itty-router/Router.mjs
var r = ({ base: r2 = "", routes: e = [], ...a } = {}) => ({ __proto__: new Proxy({}, { get: (a2, t, o, c) => (a3, ...l) => e.push([t.toUpperCase?.(), RegExp(`^${(c = (r2 + a3).replace(/\/+(\/|$)/g, "$1")).replace(/(\/?\.?):(\w+)\+/g, "($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g, "($1(?<$2>[^$1/]+?))").replace(/\./g, "\\.").replace(/(\/?)\*/g, "($1.*)?")}/*$`), l, c]) && o }), routes: e, ...a, async fetch(r3, ...t) {
let o, c, l = new URL(r3.url), p = r3.query = { __proto__: null };
for (let [r4, e2] of l.searchParams) p[r4] = p[r4] ? [].concat(p[r4], e2) : e2;
r: try {
for (let e2 of a.before || []) if (null != (o = await e2(r3.proxy ?? r3, ...t))) break r;
e: for (let [a2, p2, f, h] of e) if ((a2 == r3.method || "ALL" == a2) && (c = l.pathname.match(p2))) {
r3.params = c.groups || {}, r3.route = h;
for (let e2 of f) if (null != (o = await e2(r3.proxy ?? r3, ...t))) break e;
}
} catch (e2) {
if (!a.catch) throw e2;
o = await a.catch(e2, r3.proxy ?? r3, ...t);
}
try {
for (let e2 of a.finally || []) o = await e2(o, r3.proxy ?? r3, ...t) ?? o;
} catch (e2) {
if (!a.catch) throw e2;
o = await a.catch(e2, r3.proxy ?? r3, ...t);
}
return o;
} });
// src/gemini-proxy.ts
async function geminiProxy(rawReq) {
const url = new URL(rawReq.url);
url.host = "generativelanguage.googleapis.com";
url.port = "";
url.protocol = "https:";
const req = new Request(url, rawReq);
const resp = await fetch(req);
return new Response(resp.body, resp);
}
// src/utils.ts
function getToken(headers) {
for (const [k, v] of headers.entries()) {
if (k.toLowerCase() !== "authorization") continue;
const rawApikey = v.substring(v.indexOf(" ") + 1);
if (!rawApikey.includes("#")) {
return {
apikey: rawApikey,
useBeta: false
};
}
const apikey = rawApikey.substring(0, rawApikey.indexOf("#"));
const params = new URLSearchParams(rawApikey.substring(rawApikey.indexOf("#") + 1));
return {
apikey,
useBeta: params.has("useBeta")
};
}
return null;
}
function parseBase64(base64) {
if (!base64.startsWith("data:")) {
return { text: "" };
}
const [m, data, ..._arr] = base64.split(",");
const mimeType = m.match(/:(?<mime>.*?);/)?.groups?.mime ?? "img/png";
return {
inlineData: {
mimeType,
data
}
};
}
function openAiMessageToGeminiMessage(messages) {
const result = messages.flatMap(({ role, content }) => {
if (role === "system") {
return [
{ role: "user", parts: [{ text: content }] },
{ role: "model", parts: [{ text: "" }] }
];
}
const parts = content == null || typeof content === "string" ? [{ text: content?.toString() ?? "" }] : content.map((item) => item.type === "text" ? { text: item.text } : parseBase64(item.image_url.url));
return [{ role: "user" === role ? "user" : "model", parts }];
}).flatMap((item, idx, arr) => {
if (item.role === arr.at(idx + 1)?.role && item.role === "user") {
return [item, { role: "model", parts: [{ text: "" }] }];
}
return [item];
});
return result;
}
function genModel(req) {
const model = ModelMapping[req.model] ?? "gemini-1.0-pro-latest";
let functions = req.tools?.filter((it) => it.type === "function")?.map((it) => it.function) ?? [];
functions = functions.concat(req.functions ?? []);
const responseMimeType = req.response_format?.type === "json_object" ? "application/json" : "text/plain";
const generateContentRequest = {
contents: openAiMessageToGeminiMessage(req.messages),
generationConfig: {
maxOutputTokens: req.max_tokens ?? void 0,
temperature: req.temperature ?? void 0,
topP: req.top_p ?? void 0,
responseMimeType
},
tools: functions.length === 0 ? void 0 : [
{
functionDeclarations: functions
}
],
safetySettings: [
"HARM_CATEGORY_HATE_SPEECH",
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
"HARM_CATEGORY_DANGEROUS_CONTENT",
"HARM_CATEGORY_HARASSMENT"
].map((category) => ({
category,
threshold: "BLOCK_NONE"
}))
};
return [model, generateContentRequest];
}
var ModelMapping = {
"gpt-3.5-turbo": "gemini-1.0-pro-latest",
"gpt-4": "gemini-1.5-pro-latest",
"gpt-4o": "gemini-1.5-flash-latest",
"gpt-4-vision-preview": "gemini-1.0-pro-vision-latest",
"gpt-4-turbo": "gemini-1.5-pro-latest",
"gpt-4-turbo-preview": "gemini-1.5-pro-latest"
};
function getRuntimeKey() {
const global = globalThis;
if (global?.Deno !== void 0) {
return "deno";
}
if (global?.Bun !== void 0) {
return "bun";
}
if (typeof global?.WebSocketPair === "function") {
return "workerd";
}
if (typeof global?.EdgeRuntime === "string") {
return "edge-light";
}
if (global?.fastly !== void 0) {
return "fastly";
}
if (global?.process?.release?.name === "node") {
return "node";
}
return "other";
}
// src/hello.ts
function hello(req) {
const origin = new URL(req.url).origin;
return new Response(`
Hello Gemini-OpenAI-Proxy from ${getRuntimeKey()}!
You can try it with:
curl ${origin}/v1/chat/completions \\
-H "Authorization: Bearer $YOUR_GEMINI_API_KEY" \\
-H "Content-Type: application/json" \\
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello"}],
"temperature": 0.7
}'
`);
}
// src/itty-router/cors.ts
function cors(options = {}) {
const { origin = "*", credentials = false, allowMethods = "*", allowHeaders, exposeHeaders, maxAge } = options;
const getAccessControlOrigin = (request) => {
const requestOrigin = request?.headers.get("origin");
if (!requestOrigin) return void 0;
if (origin === true) return requestOrigin;
if (origin instanceof RegExp) return origin.test(requestOrigin) ? requestOrigin : void 0;
if (Array.isArray(origin)) return origin.includes(requestOrigin) ? requestOrigin : void 0;
if (origin instanceof Function) return origin(requestOrigin);
return origin === "*" && credentials ? requestOrigin : origin;
};
const appendHeadersAndReturn = (response, headers) => {
for (const [key, value] of Object.entries(headers)) {
if (value) response.headers.append(key, value);
}
return response;
};
const preflight2 = (request) => {
if (request.method === "OPTIONS") {
const response = new Response(null, { status: 204 });
return appendHeadersAndReturn(response, {
"access-control-allow-origin": getAccessControlOrigin(request),
"access-control-allow-methods": [allowMethods].flat().join(","),
// include allowed methods
"access-control-expose-headers": [exposeHeaders].flat().join(","),
// include allowed headers
"access-control-allow-headers": [allowHeaders].flat().join?.(",") || request.headers.get("access-control-request-headers") || "",
// include allowed headers
"access-control-max-age": maxAge?.toString(),
"access-control-allow-credentials": credentials.toString()
});
}
};
const corsify2 = (response, request) => {
if (response?.headers?.get("access-control-allow-origin") || response.status === 101) return response;
return appendHeadersAndReturn(response, {
"access-control-allow-origin": getAccessControlOrigin(request),
"access-control-allow-credentials": credentials.toString()
});
};
return { corsify: corsify2, preflight: preflight2 };
}
// src/log.ts
var LEVEL = ["debug", "info", "warn", "error"];
var Logger = class {
config;
debug;
info;
warn;
error;
constructor(config) {
const level = LEVEL.find((it) => it === config?.level) ?? "warn";
this.config = {
prefix: config?.prefix ?? "",
level
};
for (const m of LEVEL) {
this[m] = (...data) => this.#write(m, ...data);
}
}
#write(level, ...data) {
const { level: configLevel, prefix } = this.config;
if (LEVEL.indexOf(level) < LEVEL.indexOf(configLevel)) {
return;
}
console[level](`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase()}${prefix ? ` ${prefix}` : ""}`, ...data);
}
};
// node_modules/.deno/eventsource-parser@1.1.2/node_modules/eventsource-parser/dist/index.js
function createParser(onParse) {
let isFirstChunk;
let buffer;
let startingPosition;
let startingFieldLength;
let eventId;
let eventName;
let data;
reset();
return {
feed,
reset
};
function reset() {
isFirstChunk = true;
buffer = "";
startingPosition = 0;
startingFieldLength = -1;
eventId = void 0;
eventName = void 0;
data = "";
}
function feed(chunk) {
buffer = buffer ? buffer + chunk : chunk;
if (isFirstChunk && hasBom(buffer)) {
buffer = buffer.slice(BOM.length);
}
isFirstChunk = false;
const length = buffer.length;
let position = 0;
let discardTrailingNewline = false;
while (position < length) {
if (discardTrailingNewline) {
if (buffer[position] === "\n") {
++position;
}
discardTrailingNewline = false;
}
let lineLength = -1;
let fieldLength = startingFieldLength;
let character;
for (let index = startingPosition; lineLength < 0 && index < length; ++index) {
character = buffer[index];
if (character === ":" && fieldLength < 0) {
fieldLength = index - position;
} else if (character === "\r") {
discardTrailingNewline = true;
lineLength = index - position;
} else if (character === "\n") {
lineLength = index - position;
}
}
if (lineLength < 0) {
startingPosition = length - position;
startingFieldLength = fieldLength;
break;
} else {
startingPosition = 0;
startingFieldLength = -1;
}
parseEventStreamLine(buffer, position, fieldLength, lineLength);
position += lineLength + 1;
}
if (position === length) {
buffer = "";
} else if (position > 0) {
buffer = buffer.slice(position);
}
}
function parseEventStreamLine(lineBuffer, index, fieldLength, lineLength) {
if (lineLength === 0) {
if (data.length > 0) {
onParse({
type: "event",
id: eventId,
event: eventName || void 0,
data: data.slice(0, -1)
// remove trailing newline
});
data = "";
eventId = void 0;
}
eventName = void 0;
return;
}
const noValue = fieldLength < 0;
const field = lineBuffer.slice(index, index + (noValue ? lineLength : fieldLength));
let step = 0;
if (noValue) {
step = lineLength;
} else if (lineBuffer[index + fieldLength + 1] === " ") {
step = fieldLength + 2;
} else {
step = fieldLength + 1;
}
const position = index + step;
const valueLength = lineLength - step;
const value = lineBuffer.slice(position, position + valueLength).toString();
if (field === "data") {
data += value ? "".concat(value, "\n") : "\n";
} else if (field === "event") {
eventName = value;
} else if (field === "id" && !value.includes("\0")) {
eventId = value;
} else if (field === "retry") {
const retry = parseInt(value, 10);
if (!Number.isNaN(retry)) {
onParse({
type: "reconnect-interval",
value: retry
});
}
}
}
}
var BOM = [239, 187, 191];
function hasBom(buffer) {
return BOM.every((charCode, index) => buffer.charCodeAt(index) === charCode);
}
// node_modules/.deno/eventsource-parser@1.1.2/node_modules/eventsource-parser/dist/stream.js
var EventSourceParserStream = class extends TransformStream {
constructor() {
let parser;
super({
start(controller) {
parser = createParser((event) => {
if (event.type === "event") {
controller.enqueue(event);
}
});
},
transform(chunk) {
parser.feed(chunk);
}
});
}
};
// src/gemini-api-client/errors.ts
var GoogleGenerativeAIError = class extends Error {
constructor(message) {
super(`[GoogleGenerativeAI Error]: ${message}`);
}
};
var GoogleGenerativeAIResponseError = class extends GoogleGenerativeAIError {
constructor(message, response) {
super(message);
this.response = response;
}
};
// src/gemini-api-client/response-helper.ts
function addHelpers(response) {
;
response.result = () => {
if (response.candidates && response.candidates.length > 0) {
if (response.candidates.length > 1) {
console.warn(
`This response had ${response.candidates.length} candidates. Returning text from the first candidate only. Access response.candidates directly to use the other candidates.`
);
}
if (hadBadFinishReason(response.candidates[0])) {
throw new GoogleGenerativeAIResponseError(
`${formatBlockErrorMessage(response)}`,
response
);
}
return getText(response);
}
if (response.promptFeedback) {
throw new GoogleGenerativeAIResponseError(
`Text not available. ${formatBlockErrorMessage(response)}`,
response
);
}
return "";
};
return response;
}
function getText(response) {
if (response.candidates?.[0].content?.parts?.[0]?.text) {
return response.candidates[0].content.parts[0].text;
}
if (response.candidates?.[0].content?.parts?.[0]?.functionCall) {
return response.candidates[0].content.parts[0].functionCall;
}
return "";
}
var badFinishReasons = ["RECITATION", "SAFETY"];
function hadBadFinishReason(candidate) {
return !!candidate.finishReason && badFinishReasons.includes(candidate.finishReason);
}
function formatBlockErrorMessage(response) {
let message = "";
if ((!response.candidates || response.candidates.length === 0) && response.promptFeedback) {
message += "Response was blocked";
if (response.promptFeedback?.blockReason) {
message += ` due to ${response.promptFeedback.blockReason}`;
}
if (response.promptFeedback?.blockReasonMessage) {
message += `: ${response.promptFeedback.blockReasonMessage}`;
}
} else if (response.candidates?.[0]) {
const firstCandidate = response.candidates[0];
if (hadBadFinishReason(firstCandidate)) {
message += `Candidate was blocked due to ${firstCandidate.finishReason}`;
if (firstCandidate.finishMessage) {
message += `: ${firstCandidate.finishMessage}`;
}
}
}
return message;
}
// src/gemini-api-client/gemini-api-client.ts
async function* generateContent(apiParam, model, params, requestOptions) {
const url = new RequestUrl(model, "streamGenerateContent" /* STREAM_GENERATE_CONTENT */, true, apiParam);
const response = await makeRequest(url, JSON.stringify(params), requestOptions);
const body = response.body;
if (body == null) {
return;
}
for await (const event of body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream())) {
const responseJson = JSON.parse(event.data);
const enhancedResponse = addHelpers(responseJson);
yield {
response: enhancedResponse
};
}
}
async function makeRequest(url, body, requestOptions) {
let response;
try {
response = await fetch(url.toURL(), {
...buildFetchOptions(requestOptions),
method: "POST",
headers: {
"Content-Type": "application/json"
},
body
});
if (!response.ok) {
let message = "";
try {
const errResp = await response.json();
message = errResp.error.message;
if (errResp.error.details) {
message += ` ${JSON.stringify(errResp.error.details)}`;
}
} catch (_e) {
}
throw new Error(`[${response.status} ${response.statusText}] ${message}`);
}
} catch (e) {
console.log(e);
const err = new GoogleGenerativeAIError(`Error fetching from google -> ${e.message}`);
err.stack = e.stack;
throw err;
}
return response;
}
var RequestUrl = class {
constructor(model, task, stream, apiParam) {
this.model = model;
this.task = task;
this.stream = stream;
this.apiParam = apiParam;
}
toURL() {
const api_version = "v1beta" /* v1beta */;
const url = new URL(`${BASE_URL}/${api_version}/models/${this.model}:${this.task}`);
url.searchParams.append("key", this.apiParam.apikey);
if (this.stream) {
url.searchParams.append("alt", "sse");
}
return url;
}
};
var BASE_URL = "https://generativelanguage.googleapis.com";
function buildFetchOptions(requestOptions) {
const fetchOptions = {};
if (requestOptions?.timeout) {
const abortController = new AbortController();
const signal = abortController.signal;
setTimeout(() => abortController.abort(), requestOptions.timeout);
fetchOptions.signal = signal;
}
return fetchOptions;
}
// src/openai/chat/completions/NonStreamingChatProxyHandler.ts
async function nonStreamingChatProxyHandler(req, apiParam, log) {
const [model, geminiReq] = genModel(req);
let geminiResp = "";
try {
for await (const it of generateContent(apiParam, model, geminiReq)) {
const data = it.response.result();
if (typeof data === "string") {
geminiResp += data;
} else {
geminiResp = data;
break;
}
}
} catch (err) {
log?.error(req);
log?.error(err?.message ?? err.toString());
geminiResp = err?.message ?? err.toString();
}
log?.debug(req);
log?.debug(geminiResp);
function genOpenAiResp(content) {
if (typeof content === "string") {
return {
id: "chatcmpl-abc123",
object: "chat.completion",
created: Math.floor(Date.now() / 1e3),
model: req.model,
choices: [
{
message: { role: "assistant", content },
finish_reason: "stop",
index: 0,
logprobs: null
}
]
};
}
return {
id: "chatcmpl-abc123",
object: "chat.completion",
created: Math.floor(Date.now() / 1e3),
model: req.model,
choices: [
{
message: {
role: "assistant",
content: null,
function_call: {
name: content.name ?? "",
arguments: JSON.stringify(content.args)
}
},
finish_reason: "function_call",
index: 0,
logprobs: null
}
]
};
}
return genOpenAiResp(geminiResp);
}
// src/openai/chat/completions/StreamingChatProxyHandler.ts
async function* streamingChatProxyHandler(req, apiParam) {
const [model, geminiReq] = genModel(req);
try {
for await (const it of generateContent(apiParam, model, geminiReq)) {
const data = it.response.result();
yield genOpenAiResp(data, false);
}
} catch (error) {
yield genOpenAiResp(error?.message ?? error.toString(), true);
}
yield genOpenAiResp("", true);
return void 0;
function genOpenAiResp(content, stop) {
if (typeof content === "string") {
return {
id: "chatcmpl-abc123",
object: "chat.completion.chunk",
created: Math.floor(Date.now() / 1e3),
model: req.model,
choices: [
{
delta: { role: "assistant", content },
finish_reason: stop ? "stop" : null,
index: 0
}
]
};
}
return {
id: "chatcmpl-abc123",
object: "chat.completion.chunk",
created: Math.floor(Date.now() / 1e3),
model: req.model,
choices: [
{
delta: { role: "assistant", function_call: content },
finish_reason: stop ? "function_call" : null,
index: 0
}
]
};
}
}
// src/openai/chat/completions/ChatProxyHandler.ts
async function chatProxyHandler(rawReq) {
const req = await rawReq.json();
const headers = rawReq.headers;
const apiParam = getToken(headers);
if (apiParam == null) {
return new Response("Unauthorized", { status: 401 });
}
rawReq.logger?.debug(req);
if (req.stream !== true) {
const resp = await nonStreamingChatProxyHandler(req, apiParam, rawReq.logger);
rawReq.logger?.debug(resp);
return Response.json(resp);
}
const respArr = streamingChatProxyHandler(req, apiParam);
return sseResponse(
async function* () {
for await (const data of respArr) {
rawReq.logger?.debug("streamingChatProxyHandler", data);
yield JSON.stringify(data);
}
yield "[DONE]";
return void 0;
}()
);
}
var encoder = new TextEncoder();
function sseResponse(dataStream) {
const s = new ReadableStream({
async pull(controller) {
const { value, done } = await dataStream.next();
if (done) {
controller.close();
} else {
controller.enqueue(encoder.encode(toSseMsg({ data: value })));
}
}
});
const response = new Response(s, {
status: 200,
headers: new Headers({
"Content-Type": "text/event-stream"
})
});
return response;
}
function toSseMsg(sseEvent) {
const { event, data, id } = sseEvent;
let result = `data: ${data}
`;
if (event) {
result += `event: ${event ?? ""}
`;
}
if (id) {
result += `id: ${id ?? ""}
`;
}
return `${result}
`;
}
// src/openai/models.ts
var modelData = Object.keys(ModelMapping).map((model) => ({
created: 1677610602,
object: "model",
owned_by: "openai",
id: model
}));
var models = () => {
return {
object: "list",
data: modelData
};
};
var modelDetail = (model) => {
return modelData.find((it) => it.id === model);
};
// src/app.ts
var { preflight, corsify } = cors({ allowHeaders: "*" });
var app = r({
before: [
preflight,
(req) => {
req.logger = new Logger({ prefix: crypto.randomUUID().toString() });
req.logger.warn(`--> ${req.method} ${req.url}`);
}
],
finally: [
corsify,
(_, req) => {
req.logger?.warn(`<-- ${req.method} ${req.url}`);
}
]
});
app.get("/", hello);
app.post("/v1/chat/completions", chatProxyHandler);
app.get("/v1/models", () => Response.json(models()));
app.get("/v1/models/:model", (c) => Response.json(modelDetail(c.params.model)));
app.post(":model_version/models/:model_and_action", geminiProxy);
app.all("*", () => new Response("Page Not Found", { status: 404 }));
// main_deno.ts
Deno.serve({ port: 8e3 }, app.fetch);