Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/audio/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class Audio {
): Promise<SpeechToTextResponse | SpeechToTextWebhookResponse> {
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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/classification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Classification {
}

classify = async (params: ClassificationParams): Promise<ClassificationResponse> => {
return await this.client.fetchJSS("/classification", "POST", params);
return await this.client.fetchJSS("/v1/classification", "POST", params);
};
}

Expand Down
1 change: 1 addition & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
37 changes: 25 additions & 12 deletions src/general/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { createFileUploadFormData } from "../utils";
import {
EmbeddingParams,
EmbeddingResponse,
EmbeddingV2Params,
EmbeddingV2Response,
ImageGenerationParams,
PredictionParams,
PredictionResponse,
Expand All @@ -24,65 +26,76 @@ 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<TranslateResponse | (BaseResponse & { translated_text: string[] })> => {
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,
options?: Omit<TranslateImageParams, "file_store_key" | "url">
): Promise<ReturnType<typeof respToFileChoice>> => {
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<SentimentResponse> => {
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<TextToSQLResponse> => {
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<BaseResponse & { summary: string[] }>;
summary(params: SummaryParams & { type: "text" }): Promise<BaseResponse & { summary: string }>;
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<PredictionResponse> => {
return await this.client.fetchJSS("/ai/prediction", "POST", params);
return await this.client.fetchJSS("/v1/ai/prediction", "POST", params);
};

embedding(params: EmbeddingParams): Promise<EmbeddingResponse>;
embedding(file: Blob | Buffer, params: Omit<EmbeddingParams, "url" | "file_store_key" | "file_content">): Promise<EmbeddingResponse>;
async embedding(params: EmbeddingParams | Blob | Buffer, options?: EmbeddingParams): Promise<EmbeddingResponse> {
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<EmbeddingV2Response>;
embeddingV2(file: Blob | Buffer, params: Omit<EmbeddingV2Params, "url" | "file_store_key" | "file_content">): Promise<EmbeddingV2Response>;
async embeddingV2(params: EmbeddingV2Params | Blob | Buffer, options?: EmbeddingV2Params): Promise<EmbeddingV2Response> {
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);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/general/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/store/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class File {

upload = async (file: Blob | Buffer, params?: FileUploadParams): Promise<FileUploadResponse> => {
return await this.client.fetchJSS(
`/store/file`,
`/v1/store/file`,
"POST",
file,
{
Expand All @@ -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<BaseResponse> => {
return await this.client.fetchJSS(`/store/file/read/${key}`, "DELETE");
return await this.client.fetchJSS(`/v1/store/file/read/${key}`, "DELETE");
};
}
10 changes: 5 additions & 5 deletions src/validate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ class Validate {
async nsfw(params: NSFWParams | Blob | Buffer, options?: NSFWParams): Promise<NSFWValidationResponse> {
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<ProfanityValidationResponse> => {
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<SpellCheckValidationResponse> => {
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<SpamCheckValidationResponse>;
spamcheck({ text }: { text: string[] }): Promise<SpamCheckValidationArrayResponse>;
async spamcheck({ text }: { text: string | string[] }): Promise<SpamCheckValidationResponse | SpamCheckValidationArrayResponse> {
return await this.client.fetchJSS("/validate/spam_check", "POST", { text });
return await this.client.fetchJSS("/v1/validate/spam_check", "POST", { text });
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/vision/vision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class Vision {
async vocr(params: VOCRParams | Blob | Buffer, options?: VOCRParams): Promise<VOCRResponse> {
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<ObjectDetectionResponse>;
object_detection(file: Blob | Buffer, params?: Omit<ObjectDetectionParams, "url" | "file_store_key">): Promise<ObjectDetectionResponse>;
async object_detection(params: ObjectDetectionParams | Blob | Buffer, options?: ObjectDetectionParams): Promise<ObjectDetectionResponse> {
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);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/web/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Web {
constructor(private readonly client: RequestClient) {}

ai_scrape = async (params: AIScrapeParams): Promise<AIScrapeResponse> => {
return await this.client.fetchJSS("/ai/scrape", "POST", params);
return await this.client.fetchJSS("/v1/ai/scrape", "POST", params);
};

// Simplified function overloads
Expand All @@ -16,21 +16,21 @@ class Web {
html_to_any(params: HTMLAnyParams): Promise<HTMLAnyURLResponse | HTMLAnyBinaryResponse>;
async html_to_any(params: HTMLAnyParams): Promise<HTMLAnyURLResponse | HTMLAnyBinaryResponse> {
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<DeepResearchResponse> => {
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<SearchResponse> => {
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<SuggestionResponse> => {
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);
};
}

Expand Down