Skip to content

Commit 88337b8

Browse files
authored
Merge pull request #60 from JigsawStack/feat/embeddingsV2
Feat/embeddings v2
2 parents 2ddeac7 + 577d7ec commit 88337b8

File tree

11 files changed

+74
-35
lines changed

11 files changed

+74
-35
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
"scripts": {
3535
"build": "pkgroll --src=./",
3636
"format": "biome check --write .",
37-
"test": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/*.ts"
37+
"test": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/*.ts",
38+
"test:audio": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/audio.test.ts",
39+
"test:vision": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/vision.test.ts",
40+
"test:web": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/web.test.ts",
41+
"test:validate": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/validate.test.ts"
3842
},
3943
"dependencies": {
4044
"isomorphic-fetch": "^3.0.0",

src/audio/audio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class Audio {
3030
): Promise<SpeechToTextResponse | SpeechToTextWebhookResponse> {
3131
if (params instanceof Blob || params instanceof Buffer) {
3232
const formData = createFileUploadFormData(params, options);
33-
return await this.client.fetchJSS("/ai/transcribe", "POST", formData);
33+
return await this.client.fetchJSS("/v1/ai/transcribe", "POST", formData);
3434
}
35-
return await this.client.fetchJSS("/ai/transcribe", "POST", params);
35+
return await this.client.fetchJSS("/v1/ai/transcribe", "POST", params);
3636
}
3737
}
3838

src/classification/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Classification {
88
}
99

1010
classify = async (params: ClassificationParams): Promise<ClassificationResponse> => {
11-
return await this.client.fetchJSS("/classification", "POST", params);
11+
return await this.client.fetchJSS("/v1/classification", "POST", params);
1212
};
1313
}
1414

src/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const JigsawStack = (config?: BaseConfig) => {
4444
prediction: general.prediction,
4545
text_to_sql: general.text_to_sql,
4646
embedding: general.embedding,
47+
embeddingV2: general.embeddingV2,
4748
audio,
4849
vision: {
4950
vocr: createBoundMethod(vision, vision.vocr),

src/general/index.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { createFileUploadFormData } from "../utils";
55
import {
66
EmbeddingParams,
77
EmbeddingResponse,
8+
EmbeddingV2Params,
9+
EmbeddingV2Response,
810
ImageGenerationParams,
911
PredictionParams,
1012
PredictionResponse,
@@ -24,65 +26,76 @@ class General {
2426
this.client = client;
2527
this.summary = this.summary.bind(this);
2628
this.embedding = this.embedding.bind(this);
29+
this.embeddingV2 = this.embeddingV2.bind(this);
2730
}
2831

2932
translate = {
3033
text: async (params: TranslateParams): Promise<TranslateResponse | (BaseResponse & { translated_text: string[] })> => {
3134
if (Array.isArray(params.text)) {
32-
const resp = await this.client.fetchJSS("/ai/translate", "POST", params);
35+
const resp = await this.client.fetchJSS("/v1/ai/translate", "POST", params);
3336
return resp as BaseResponse & { translated_text: string[] };
3437
}
35-
return await this.client.fetchJSS("/ai/translate", "POST", params);
38+
return await this.client.fetchJSS("/v1/ai/translate", "POST", params);
3639
},
3740
image: async (
3841
params: Blob | Buffer | TranslateImageParams,
3942
options?: Omit<TranslateImageParams, "file_store_key" | "url">
4043
): Promise<ReturnType<typeof respToFileChoice>> => {
4144
if (params instanceof Blob || params instanceof Buffer) {
4245
const formData = createFileUploadFormData(params, options);
43-
const resp = await this.client.fetchJSS("/ai/translate/image", "POST", formData);
46+
const resp = await this.client.fetchJSS("/v1/ai/translate/image", "POST", formData);
4447
return respToFileChoice(resp);
4548
}
46-
const resp = await this.client.fetchJSS("/ai/translate/image", "POST", params);
49+
const resp = await this.client.fetchJSS("/v1/ai/translate/image", "POST", params);
4750
return respToFileChoice(resp);
4851
},
4952
};
5053

5154
sentiment = async (params: { text: string }): Promise<SentimentResponse> => {
52-
return await this.client.fetchJSS("/ai/sentiment", "POST", params);
55+
return await this.client.fetchJSS("/v1/ai/sentiment", "POST", params);
5356
};
5457

5558
image_generation = async (params: ImageGenerationParams) => {
56-
const resp = await this.client.fetchJSS("/ai/image_generation", "POST", params);
59+
const resp = await this.client.fetchJSS("/v1/ai/image_generation", "POST", params);
5760
return respToFileChoice(resp);
5861
};
5962

6063
text_to_sql = async (params: TextToSQLParams): Promise<TextToSQLResponse> => {
61-
return await this.client.fetchJSS("/ai/sql", "POST", params);
64+
return await this.client.fetchJSS("/v1/ai/sql", "POST", params);
6265
};
6366

6467
summary(params: SummaryParams & { type: "points" }): Promise<BaseResponse & { summary: string[] }>;
6568
summary(params: SummaryParams & { type: "text" }): Promise<BaseResponse & { summary: string }>;
6669
async summary(params: SummaryParams): Promise<(BaseResponse & { summary: string[] }) | (BaseResponse & { summary: string })> {
6770
if (params.type === "points") {
68-
const resp = await this.client.fetchJSS("/ai/summary", "POST", params);
71+
const resp = await this.client.fetchJSS("/v1/ai/summary", "POST", params);
6972
return resp as BaseResponse & { summary: string[] };
7073
}
71-
return await this.client.fetchJSS("/ai/summary", "POST", params);
74+
return await this.client.fetchJSS("/v1/ai/summary", "POST", params);
7275
}
7376

7477
prediction = async (params: PredictionParams): Promise<PredictionResponse> => {
75-
return await this.client.fetchJSS("/ai/prediction", "POST", params);
78+
return await this.client.fetchJSS("/v1/ai/prediction", "POST", params);
7679
};
7780

7881
embedding(params: EmbeddingParams): Promise<EmbeddingResponse>;
7982
embedding(file: Blob | Buffer, params: Omit<EmbeddingParams, "url" | "file_store_key" | "file_content">): Promise<EmbeddingResponse>;
8083
async embedding(params: EmbeddingParams | Blob | Buffer, options?: EmbeddingParams): Promise<EmbeddingResponse> {
8184
if (params instanceof Blob || params instanceof Buffer) {
8285
const formData = createFileUploadFormData(params, options);
83-
return await this.client.fetchJSS("/embedding", "POST", formData);
86+
return await this.client.fetchJSS("/v1/embedding", "POST", formData);
8487
}
85-
return await this.client.fetchJSS("/embedding", "POST", params);
88+
return await this.client.fetchJSS("/v1/embedding", "POST", params);
89+
}
90+
91+
embeddingV2(params: EmbeddingV2Params): Promise<EmbeddingV2Response>;
92+
embeddingV2(file: Blob | Buffer, params: Omit<EmbeddingV2Params, "url" | "file_store_key" | "file_content">): Promise<EmbeddingV2Response>;
93+
async embeddingV2(params: EmbeddingV2Params | Blob | Buffer, options?: EmbeddingV2Params): Promise<EmbeddingV2Response> {
94+
if (params instanceof Blob || params instanceof Buffer) {
95+
const formData = createFileUploadFormData(params, options);
96+
return await this.client.fetchJSS("/v2/embedding", "POST", formData);
97+
}
98+
return await this.client.fetchJSS("/v2/embedding", "POST", params);
8699
}
87100
}
88101

src/general/interfaces.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ export interface EmbeddingParams {
116116
token_overflow_mode?: "truncate" | "error";
117117
}
118118

119+
export interface EmbeddingV2Params {
120+
text?: string;
121+
url?: string;
122+
file_store_key?: string;
123+
file_content?: any;
124+
type: "text" | "text-other" | "image" | "audio" | "pdf";
125+
token_overflow_mode?: "truncate" | "error";
126+
speaker_fingerprint?: boolean;
127+
}
128+
129+
export interface EmbeddingV2Response extends BaseResponse {
130+
embeddings: number[][];
131+
chunks?:
132+
| string[]
133+
| Array<{
134+
text: string;
135+
timestamp: number[];
136+
}>;
137+
speaker_embeddings?: number[][];
138+
}
139+
119140
export interface EmbeddingResponse extends BaseResponse {
120141
embeddings: number[][];
121142
chunks?: Array<{ text: string; timestamp: number[] }>; // only available for text and audio

src/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseConfig } from "../types";
22
import { removeUndefinedProperties } from "./helpers";
33

4-
const baseURL = "https://api.jigsawstack.com/v1";
4+
const baseURL = "https://api.jigsawstack.com";
55
// const baseURL = "http://localhost:3000";
66

77
export class RequestClient {

src/store/file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class File {
77

88
upload = async (file: Blob | Buffer, params?: FileUploadParams): Promise<FileUploadResponse> => {
99
return await this.client.fetchJSS(
10-
`/store/file`,
10+
`/v1/store/file`,
1111
"POST",
1212
file,
1313
{
@@ -22,12 +22,12 @@ export class File {
2222
};
2323

2424
retrieve = async (key: string) => {
25-
const resp = await this.client.fetchJSS(`/store/file/read/${key}`, "GET");
25+
const resp = await this.client.fetchJSS(`/v1/store/file/read/${key}`, "GET");
2626

2727
return respToFileChoice(resp);
2828
};
2929

3030
delete = async (key: string): Promise<BaseResponse> => {
31-
return await this.client.fetchJSS(`/store/file/read/${key}`, "DELETE");
31+
return await this.client.fetchJSS(`/v1/store/file/read/${key}`, "DELETE");
3232
};
3333
}

src/validate/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ class Validate {
1919
async nsfw(params: NSFWParams | Blob | Buffer, options?: NSFWParams): Promise<NSFWValidationResponse> {
2020
if (params instanceof Blob || params instanceof Buffer) {
2121
const formData = createFileUploadFormData(params, options);
22-
return await this.client.fetchJSS("/validate/nsfw", "POST", formData);
22+
return await this.client.fetchJSS("/v1/validate/nsfw", "POST", formData);
2323
}
24-
return await this.client.fetchJSS("/validate/nsfw", "POST", params);
24+
return await this.client.fetchJSS("/v1/validate/nsfw", "POST", params);
2525
}
2626

2727
profanity = async ({ text, censor_replacement = "*" }: ProfanityParams): Promise<ProfanityValidationResponse> => {
28-
return await this.client.fetchJSS("/validate/profanity", "POST", { text, censor_replacement });
28+
return await this.client.fetchJSS("/v1/validate/profanity", "POST", { text, censor_replacement });
2929
};
3030

3131
spellcheck = async ({ text, language_code = "en" }: SpellCheckParams): Promise<SpellCheckValidationResponse> => {
32-
return await this.client.fetchJSS("/validate/spell_check", "POST", { text, language_code });
32+
return await this.client.fetchJSS("/v1/validate/spell_check", "POST", { text, language_code });
3333
};
3434

3535
spamcheck({ text }: { text: string }): Promise<SpamCheckValidationResponse>;
3636
spamcheck({ text }: { text: string[] }): Promise<SpamCheckValidationArrayResponse>;
3737
async spamcheck({ text }: { text: string | string[] }): Promise<SpamCheckValidationResponse | SpamCheckValidationArrayResponse> {
38-
return await this.client.fetchJSS("/validate/spam_check", "POST", { text });
38+
return await this.client.fetchJSS("/v1/validate/spam_check", "POST", { text });
3939
}
4040
}
4141

src/vision/vision.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ class Vision {
99
async vocr(params: VOCRParams | Blob | Buffer, options?: VOCRParams): Promise<VOCRResponse> {
1010
if (params instanceof Blob || params instanceof Buffer) {
1111
const formData = createFileUploadFormData(params, options);
12-
return await this.client.fetchJSS("/vocr", "POST", formData);
12+
return await this.client.fetchJSS("/v1/vocr", "POST", formData);
1313
}
14-
return await this.client.fetchJSS("/vocr", "POST", params);
14+
return await this.client.fetchJSS("/v1/vocr", "POST", params);
1515
}
1616

1717
object_detection(params: ObjectDetectionParams): Promise<ObjectDetectionResponse>;
1818
object_detection(file: Blob | Buffer, params?: Omit<ObjectDetectionParams, "url" | "file_store_key">): Promise<ObjectDetectionResponse>;
1919
async object_detection(params: ObjectDetectionParams | Blob | Buffer, options?: ObjectDetectionParams): Promise<ObjectDetectionResponse> {
2020
if (params instanceof Blob || params instanceof Buffer) {
2121
const formData = createFileUploadFormData(params, options);
22-
return await this.client.fetchJSS("/object_detection", "POST", formData);
22+
return await this.client.fetchJSS("/v1/object_detection", "POST", formData);
2323
}
24-
return await this.client.fetchJSS("/object_detection", "POST", params);
24+
return await this.client.fetchJSS("/v1/object_detection", "POST", params);
2525
}
2626
}
2727

0 commit comments

Comments
 (0)