diff --git a/package.json b/package.json index d26395b..9f7a2cf 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,11 @@ "scripts": { "build": "pkgroll --src=./", "format": "biome check --write .", - "test": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/*.ts" + "test": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/*.ts", + "test:audio": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/audio.test.ts", + "test:vision": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/vision.test.ts", + "test:web": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/web.test.ts", + "test:validate": "yarn build && node --test --no-warnings --import tsx --test-reporter=spec tests/validate.test.ts" }, "dependencies": { "isomorphic-fetch": "^3.0.0", diff --git a/src/audio/audio.ts b/src/audio/audio.ts index 571a514..a87c0c3 100644 --- a/src/audio/audio.ts +++ b/src/audio/audio.ts @@ -30,9 +30,9 @@ class Audio { ): Promise { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); - return await this.client.fetchJSS("/ai/transcribe", "POST", formData); + return await this.client.fetchJSS("/v1/ai/transcribe", "POST", formData); } - return await this.client.fetchJSS("/ai/transcribe", "POST", params); + return await this.client.fetchJSS("/v1/ai/transcribe", "POST", params); } } diff --git a/src/classification/index.ts b/src/classification/index.ts index f528a7c..d6f2517 100644 --- a/src/classification/index.ts +++ b/src/classification/index.ts @@ -8,7 +8,7 @@ class Classification { } classify = async (params: ClassificationParams): Promise => { - return await this.client.fetchJSS("/classification", "POST", params); + return await this.client.fetchJSS("/v1/classification", "POST", params); }; } diff --git a/src/core.ts b/src/core.ts index f456478..6e6b634 100644 --- a/src/core.ts +++ b/src/core.ts @@ -44,6 +44,7 @@ export const JigsawStack = (config?: BaseConfig) => { prediction: general.prediction, text_to_sql: general.text_to_sql, embedding: general.embedding, + embeddingV2: general.embeddingV2, audio, vision: { vocr: createBoundMethod(vision, vision.vocr), diff --git a/src/general/index.ts b/src/general/index.ts index 7183e52..878146a 100644 --- a/src/general/index.ts +++ b/src/general/index.ts @@ -5,6 +5,8 @@ import { createFileUploadFormData } from "../utils"; import { EmbeddingParams, EmbeddingResponse, + EmbeddingV2Params, + EmbeddingV2Response, ImageGenerationParams, PredictionParams, PredictionResponse, @@ -24,15 +26,16 @@ class General { this.client = client; this.summary = this.summary.bind(this); this.embedding = this.embedding.bind(this); + this.embeddingV2 = this.embeddingV2.bind(this); } translate = { text: async (params: TranslateParams): Promise => { if (Array.isArray(params.text)) { - const resp = await this.client.fetchJSS("/ai/translate", "POST", params); + const resp = await this.client.fetchJSS("/v1/ai/translate", "POST", params); return resp as BaseResponse & { translated_text: string[] }; } - return await this.client.fetchJSS("/ai/translate", "POST", params); + return await this.client.fetchJSS("/v1/ai/translate", "POST", params); }, image: async ( params: Blob | Buffer | TranslateImageParams, @@ -40,39 +43,39 @@ class General { ): Promise> => { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); - const resp = await this.client.fetchJSS("/ai/translate/image", "POST", formData); + const resp = await this.client.fetchJSS("/v1/ai/translate/image", "POST", formData); return respToFileChoice(resp); } - const resp = await this.client.fetchJSS("/ai/translate/image", "POST", params); + const resp = await this.client.fetchJSS("/v1/ai/translate/image", "POST", params); return respToFileChoice(resp); }, }; sentiment = async (params: { text: string }): Promise => { - return await this.client.fetchJSS("/ai/sentiment", "POST", params); + return await this.client.fetchJSS("/v1/ai/sentiment", "POST", params); }; image_generation = async (params: ImageGenerationParams) => { - const resp = await this.client.fetchJSS("/ai/image_generation", "POST", params); + const resp = await this.client.fetchJSS("/v1/ai/image_generation", "POST", params); return respToFileChoice(resp); }; text_to_sql = async (params: TextToSQLParams): Promise => { - return await this.client.fetchJSS("/ai/sql", "POST", params); + return await this.client.fetchJSS("/v1/ai/sql", "POST", params); }; summary(params: SummaryParams & { type: "points" }): Promise; summary(params: SummaryParams & { type: "text" }): Promise; async summary(params: SummaryParams): Promise<(BaseResponse & { summary: string[] }) | (BaseResponse & { summary: string })> { if (params.type === "points") { - const resp = await this.client.fetchJSS("/ai/summary", "POST", params); + const resp = await this.client.fetchJSS("/v1/ai/summary", "POST", params); return resp as BaseResponse & { summary: string[] }; } - return await this.client.fetchJSS("/ai/summary", "POST", params); + return await this.client.fetchJSS("/v1/ai/summary", "POST", params); } prediction = async (params: PredictionParams): Promise => { - return await this.client.fetchJSS("/ai/prediction", "POST", params); + return await this.client.fetchJSS("/v1/ai/prediction", "POST", params); }; embedding(params: EmbeddingParams): Promise; @@ -80,9 +83,19 @@ class General { async embedding(params: EmbeddingParams | Blob | Buffer, options?: EmbeddingParams): Promise { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); - return await this.client.fetchJSS("/embedding", "POST", formData); + return await this.client.fetchJSS("/v1/embedding", "POST", formData); } - return await this.client.fetchJSS("/embedding", "POST", params); + return await this.client.fetchJSS("/v1/embedding", "POST", params); + } + + embeddingV2(params: EmbeddingV2Params): Promise; + embeddingV2(file: Blob | Buffer, params: Omit): Promise; + async embeddingV2(params: EmbeddingV2Params | Blob | Buffer, options?: EmbeddingV2Params): Promise { + if (params instanceof Blob || params instanceof Buffer) { + const formData = createFileUploadFormData(params, options); + return await this.client.fetchJSS("/v2/embedding", "POST", formData); + } + return await this.client.fetchJSS("/v2/embedding", "POST", params); } } diff --git a/src/general/interfaces.ts b/src/general/interfaces.ts index 1d6e80d..384207b 100644 --- a/src/general/interfaces.ts +++ b/src/general/interfaces.ts @@ -116,6 +116,27 @@ export interface EmbeddingParams { token_overflow_mode?: "truncate" | "error"; } +export interface EmbeddingV2Params { + text?: string; + url?: string; + file_store_key?: string; + file_content?: any; + type: "text" | "text-other" | "image" | "audio" | "pdf"; + token_overflow_mode?: "truncate" | "error"; + speaker_fingerprint?: boolean; +} + +export interface EmbeddingV2Response extends BaseResponse { + embeddings: number[][]; + chunks?: + | string[] + | Array<{ + text: string; + timestamp: number[]; + }>; + speaker_embeddings?: number[][]; +} + export interface EmbeddingResponse extends BaseResponse { embeddings: number[][]; chunks?: Array<{ text: string; timestamp: number[] }>; // only available for text and audio diff --git a/src/request.ts b/src/request.ts index 8839085..ce8f16f 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,7 +1,7 @@ import { BaseConfig } from "../types"; import { removeUndefinedProperties } from "./helpers"; -const baseURL = "https://api.jigsawstack.com/v1"; +const baseURL = "https://api.jigsawstack.com"; // const baseURL = "http://localhost:3000"; export class RequestClient { diff --git a/src/store/file.ts b/src/store/file.ts index 6379bc1..b9c1de3 100644 --- a/src/store/file.ts +++ b/src/store/file.ts @@ -7,7 +7,7 @@ export class File { upload = async (file: Blob | Buffer, params?: FileUploadParams): Promise => { return await this.client.fetchJSS( - `/store/file`, + `/v1/store/file`, "POST", file, { @@ -22,12 +22,12 @@ export class File { }; retrieve = async (key: string) => { - const resp = await this.client.fetchJSS(`/store/file/read/${key}`, "GET"); + const resp = await this.client.fetchJSS(`/v1/store/file/read/${key}`, "GET"); return respToFileChoice(resp); }; delete = async (key: string): Promise => { - return await this.client.fetchJSS(`/store/file/read/${key}`, "DELETE"); + return await this.client.fetchJSS(`/v1/store/file/read/${key}`, "DELETE"); }; } diff --git a/src/validate/index.ts b/src/validate/index.ts index d69e57a..922a2e0 100644 --- a/src/validate/index.ts +++ b/src/validate/index.ts @@ -19,23 +19,23 @@ class Validate { async nsfw(params: NSFWParams | Blob | Buffer, options?: NSFWParams): Promise { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); - return await this.client.fetchJSS("/validate/nsfw", "POST", formData); + return await this.client.fetchJSS("/v1/validate/nsfw", "POST", formData); } - return await this.client.fetchJSS("/validate/nsfw", "POST", params); + return await this.client.fetchJSS("/v1/validate/nsfw", "POST", params); } profanity = async ({ text, censor_replacement = "*" }: ProfanityParams): Promise => { - return await this.client.fetchJSS("/validate/profanity", "POST", { text, censor_replacement }); + return await this.client.fetchJSS("/v1/validate/profanity", "POST", { text, censor_replacement }); }; spellcheck = async ({ text, language_code = "en" }: SpellCheckParams): Promise => { - return await this.client.fetchJSS("/validate/spell_check", "POST", { text, language_code }); + return await this.client.fetchJSS("/v1/validate/spell_check", "POST", { text, language_code }); }; spamcheck({ text }: { text: string }): Promise; spamcheck({ text }: { text: string[] }): Promise; async spamcheck({ text }: { text: string | string[] }): Promise { - return await this.client.fetchJSS("/validate/spam_check", "POST", { text }); + return await this.client.fetchJSS("/v1/validate/spam_check", "POST", { text }); } } diff --git a/src/vision/vision.ts b/src/vision/vision.ts index a5599e1..c0344b3 100644 --- a/src/vision/vision.ts +++ b/src/vision/vision.ts @@ -9,9 +9,9 @@ class Vision { async vocr(params: VOCRParams | Blob | Buffer, options?: VOCRParams): Promise { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); - return await this.client.fetchJSS("/vocr", "POST", formData); + return await this.client.fetchJSS("/v1/vocr", "POST", formData); } - return await this.client.fetchJSS("/vocr", "POST", params); + return await this.client.fetchJSS("/v1/vocr", "POST", params); } object_detection(params: ObjectDetectionParams): Promise; @@ -19,9 +19,9 @@ class Vision { async object_detection(params: ObjectDetectionParams | Blob | Buffer, options?: ObjectDetectionParams): Promise { if (params instanceof Blob || params instanceof Buffer) { const formData = createFileUploadFormData(params, options); - return await this.client.fetchJSS("/object_detection", "POST", formData); + return await this.client.fetchJSS("/v1/object_detection", "POST", formData); } - return await this.client.fetchJSS("/object_detection", "POST", params); + return await this.client.fetchJSS("/v1/object_detection", "POST", params); } } diff --git a/src/web/web.ts b/src/web/web.ts index 9e90173..73fa2aa 100644 --- a/src/web/web.ts +++ b/src/web/web.ts @@ -7,7 +7,7 @@ class Web { constructor(private readonly client: RequestClient) {} ai_scrape = async (params: AIScrapeParams): Promise => { - return await this.client.fetchJSS("/ai/scrape", "POST", params); + return await this.client.fetchJSS("/v1/ai/scrape", "POST", params); }; // Simplified function overloads @@ -16,21 +16,21 @@ class Web { html_to_any(params: HTMLAnyParams): Promise; async html_to_any(params: HTMLAnyParams): Promise { if (params.return_type === "binary") { - return (await this.client.fetchJSS("/web/html_to_any", "POST", params)) as HTMLAnyBinaryResponse; + return (await this.client.fetchJSS("/v1/web/html_to_any", "POST", params)) as HTMLAnyBinaryResponse; } // For both "url" and "base64", return the same structure with url property - return (await this.client.fetchJSS("/web/html_to_any", "POST", params)) as HTMLAnyURLResponse; + return (await this.client.fetchJSS("/v1/web/html_to_any", "POST", params)) as HTMLAnyURLResponse; } deep_research = async (params: DeepResearchParams): Promise => { - return await this.client.fetchJSS("/web/deep_research", "POST", params); + return await this.client.fetchJSS("/v1/web/deep_research", "POST", params); }; search = async (params: SearchParams): Promise => { - return await this.client.fetchJSS("/web/search", "POST", params); + return await this.client.fetchJSS("/v1/web/search", "POST", params); }; search_suggestions = async ({ query }: { query: string }): Promise => { - return await this.client.fetchJSS(`/web/search/suggest?query=${query}`, "GET", undefined); + return await this.client.fetchJSS(`/v1/web/search/suggest?query=${query}`, "GET", undefined); }; }