Skip to content

Commit c99e7c5

Browse files
committed
test: fix gte-small tests to pass with the new ai refactors
- Improving tests by checking the result types: success or errors - Testing invalid `gte-small` type name
1 parent d413c5d commit c99e7c5

File tree

1 file changed

+56
-16
lines changed
  • crates/base/test_cases/supabase-ai

1 file changed

+56
-16
lines changed

crates/base/test_cases/supabase-ai/index.ts

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
import { assertGreater, assertLessOrEqual } from "jsr:@std/assert";
1+
import {
2+
assertEquals,
3+
assertExists,
4+
assertGreater,
5+
assertIsError,
6+
assertLessOrEqual,
7+
assertStringIncludes,
8+
assertThrows,
9+
} from 'jsr:@std/assert';
210

3-
const session = new Supabase.ai.Session("gte-small");
11+
const session = new Supabase.ai.Session('gte-small');
12+
13+
assertThrows(() => {
14+
const _ = new Supabase.ai.Session('gte-small_wrong_name');
15+
}, "invalid 'Session' type");
416

517
function dotProduct(a: number[], b: number[]) {
618
let result = 0;
@@ -15,27 +27,55 @@ export default {
1527
async fetch() {
1628
// Generate embedding
1729
// @ts-ignore unkwnow type
18-
const meow: number[] = await session.run("meow", {
19-
mean_pool: true,
20-
normalize: true,
21-
});
30+
const [meow, meowError] = await session.run('meow') as [
31+
number[],
32+
undefined,
33+
];
34+
console.log('cat', meow, meowError);
2235

2336
// @ts-ignore unkwnow type
24-
const love: number[] = await session.run("I love cats", {
37+
const [love, loveError] = await session.run('I love cats', {
2538
mean_pool: true,
2639
normalize: true,
27-
});
40+
}) as [number[], undefined];
41+
42+
// "Valid input should result in ok value"
43+
{
44+
assertExists(meow);
45+
assertExists(love);
46+
47+
assertEquals(meowError, undefined);
48+
assertEquals(loveError, undefined);
49+
}
50+
51+
// "Invalid input should result in error value"
52+
{
53+
const [notCat, notCatError] = await session.run({
54+
bad_input: { 'not a cat': 'let fail' },
55+
}) as [undefined, { message: string; inner: Error }];
56+
57+
assertEquals(notCat, undefined);
58+
59+
assertExists(notCatError);
60+
assertIsError(notCatError.inner);
61+
assertStringIncludes(
62+
notCatError.message,
63+
'must provide a valid prompt value',
64+
);
65+
}
2866

29-
// Ensures `mean_pool` and `normalize`
30-
const sameScore = dotProduct(meow, meow);
31-
const diffScore = dotProduct(meow, love);
67+
// "Ensures `mean_pool` and `normalize`"
68+
{
69+
const sameScore = dotProduct(meow, meow);
70+
const diffScore = dotProduct(meow, love);
3271

33-
assertGreater(sameScore, 0.9);
34-
assertGreater(diffScore, 0.5);
35-
assertGreater(sameScore, diffScore);
72+
assertGreater(sameScore, 0.9);
73+
assertGreater(diffScore, 0.5);
74+
assertGreater(sameScore, diffScore);
3675

37-
assertLessOrEqual(sameScore, 1);
38-
assertLessOrEqual(diffScore, 1);
76+
assertLessOrEqual(sameScore, 1);
77+
assertLessOrEqual(diffScore, 1);
78+
}
3979

4080
return new Response(
4181
null,

0 commit comments

Comments
 (0)