Skip to content

Commit 305970d

Browse files
committed
fix(ext/ai): moving types to global.d.ts
1 parent 910673b commit 305970d

File tree

5 files changed

+298
-309
lines changed

5 files changed

+298
-309
lines changed

examples/ort-raw-session/index.ts

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// /// <reference path="./types.d.ts" />
2-
31
/*
42
const modelUrl = 'https://huggingface.co/kalleby/hp-to-miles/resolve/main/model.onnx?download=true';
53
const modelConfigUrl =
@@ -71,45 +69,45 @@ Deno.serve(async (_req: Request) => {
7169
});
7270
*/
7371

74-
const { Tensor, RawSession } = Supabase.ai;
72+
const { RawTensor, RawSession } = Supabase.ai;
7573

7674
const session = await RawSession.fromHuggingFace('kallebysantos/vehicle-emission', {
77-
path: {
78-
modelFile: 'model.onnx',
79-
},
75+
path: {
76+
modelFile: 'model.onnx',
77+
},
8078
});
8179

8280
Deno.serve(async (_req: Request) => {
83-
// sample data could be a JSON request
84-
const carsBatchInput = [{
85-
'Model_Year': 2021,
86-
'Engine_Size': 2.9,
87-
'Cylinders': 6,
88-
'Fuel_Consumption_in_City': 13.9,
89-
'Fuel_Consumption_in_City_Hwy': 10.3,
90-
'Fuel_Consumption_comb': 12.3,
91-
'Smog_Level': 3,
92-
}, {
93-
'Model_Year': 2023,
94-
'Engine_Size': 2.4,
95-
'Cylinders': 4,
96-
'Fuel_Consumption_in_City': 9.9,
97-
'Fuel_Consumption_in_City_Hwy': 7.0,
98-
'Fuel_Consumption_comb': 8.6,
99-
'Smog_Level': 3,
100-
}];
101-
102-
// Parsing objects to tensor input
103-
const inputTensors: Record<string, Supabase.Tensor<'float32'>> = {};
104-
session.inputs.forEach((inputKey) => {
105-
const values = carsBatchInput.map((item) => item[inputKey]);
106-
107-
inputTensors[inputKey] = new Tensor('float32', values, [values.length, 1]);
108-
});
109-
110-
const { emissions } = await session.run(inputTensors);
111-
console.log(emissions);
112-
// [ 289.01, 199.53]
113-
114-
return Response.json({ result: emissions });
81+
// sample data could be a JSON request
82+
const carsBatchInput = [{
83+
'Model_Year': 2021,
84+
'Engine_Size': 2.9,
85+
'Cylinders': 6,
86+
'Fuel_Consumption_in_City': 13.9,
87+
'Fuel_Consumption_in_City_Hwy': 10.3,
88+
'Fuel_Consumption_comb': 12.3,
89+
'Smog_Level': 3,
90+
}, {
91+
'Model_Year': 2023,
92+
'Engine_Size': 2.4,
93+
'Cylinders': 4,
94+
'Fuel_Consumption_in_City': 9.9,
95+
'Fuel_Consumption_in_City_Hwy': 7.0,
96+
'Fuel_Consumption_comb': 8.6,
97+
'Smog_Level': 3,
98+
}];
99+
100+
// Parsing objects to tensor input
101+
const inputTensors: Record<string, Supabase.ai.RawTensor<'float32'>> = {};
102+
session.inputs.forEach((inputKey) => {
103+
const values = carsBatchInput.map((item) => item[inputKey]);
104+
105+
inputTensors[inputKey] = new RawTensor('float32', values, [values.length, 1]);
106+
});
107+
108+
const { emissions } = await session.run(inputTensors);
109+
console.log(emissions);
110+
// [ 289.01, 199.53]
111+
112+
return Response.json({ result: emissions });
115113
});

examples/ort-raw-session/types.d.ts

Lines changed: 0 additions & 163 deletions
This file was deleted.

examples/text-to-audio/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// Setup type definitions for built-in Supabase Runtime APIs
2-
import 'jsr:@supabase/functions-js/edge-runtime.d.ts';
31
import { PreTrainedTokenizer } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';
42

53
// import 'phonemize' code from Kokoro.js repo
64
import { phonemize } from './phonemizer.js';
75

8-
const { Tensor, RawSession } = Supabase.ai;
6+
const { RawTensor, RawSession } = Supabase.ai;
97

108
/* NOTE: Reference [original paper](https://arxiv.org/pdf/2306.07691#Model%20Training):
119
> All datasets were resampled to 24 kHz to match LibriTTS, and the texts

0 commit comments

Comments
 (0)