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
11 changes: 7 additions & 4 deletions src/audio/audio.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { RequestClient } from "../request";
import { createFileUploadFormData } from "../utils";
import { SpeechToTextParams, SpeechToTextResponse } from "./interfaces";
import { SpeechToTextParams, SpeechToTextSyncResponse, SpeechToTextWebhookResponse } from "./interfaces";
class Audio {
constructor(private readonly client: RequestClient) {}
speech_to_text(params: SpeechToTextParams): Promise<SpeechToTextResponse>;
speech_to_text(file: Blob | Buffer, params?: Omit<SpeechToTextParams, "url" | "file_store_key">): Promise<SpeechToTextResponse>;
async speech_to_text(params: SpeechToTextParams | Blob | Buffer, options?: SpeechToTextParams): Promise<SpeechToTextResponse> {
speech_to_text(params: SpeechToTextParams): Promise<SpeechToTextSyncResponse>;
speech_to_text(file: Blob | Buffer, params?: Omit<SpeechToTextParams, "url" | "file_store_key">): Promise<SpeechToTextSyncResponse>;
async speech_to_text(
params: SpeechToTextParams | Blob | Buffer,
options?: SpeechToTextParams
): Promise<SpeechToTextSyncResponse | SpeechToTextWebhookResponse> {
if (params instanceof Blob || params instanceof Buffer) {
const formData = createFileUploadFormData(params, options);
return await this.client.fetchJSS("/ai/transcribe", "POST", formData);
Expand Down
5 changes: 1 addition & 4 deletions src/audio/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ export interface SpeechToTextParams {
chunk_duration?: number;
}

export interface SpeechToTextResponse extends BaseResponse {
export interface SpeechToTextSyncResponse extends BaseResponse {
text: string;
chunks: Array<{
timestamp: number[];
text: string;
}>;
status?: "processing" | "error";
id?: string;
speakers?: {
// available when by_speaker is true
speaker: string;
timestamp: number[];
text: string;
Expand Down
1 change: 0 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const JigsawStack = (config?: BaseConfig) => {
};

return {
fetch: client.fetchJSS,
sentiment: general.sentiment,
translate: general.translate,
image_generation: general.image_generation,
Expand Down
27 changes: 4 additions & 23 deletions src/general/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { createFileUploadFormData } from "../utils";
import {
EmbeddingParams,
EmbeddingResponse,
ImageGenerationParams,
PredictionParams,
PredictionResponse,
SentimentResponse,
SummaryParams,
SummaryResponse,
TextToSQLParams,
TextToSQLResponse,
TranslateImageParams,
TranslateParams,
Expand Down Expand Up @@ -50,33 +52,12 @@ class General {
return await this.client.fetchJSS("/ai/sentiment", "POST", params);
};

image_generation = async (params: {
prompt: string;
aspect_ratio?: "1:1" | "16:9" | "21:9" | "3:2" | "2:3" | "4:5" | "5:4" | "3:4" | "4:3" | "9:16" | "9:21";
width?: number;
height?: number;
steps?: number;
output_format?: "png" | "svg";
return_type?: "url" | "binary" | "base64";
advance_config?: {
negative_prompt?: string;
guidance?: number;
seed?: number;
};
url?: string;
file_store_key?: string;
}) => {
image_generation = async (params: ImageGenerationParams) => {
const resp = await this.client.fetchJSS("/ai/image_generation", "POST", params);

return respToFileChoice(resp);
};

text_to_sql = async (params: {
prompt: string;
sql_schema?: string;
file_store_key?: string;
database?: "postgresql" | "mysql" | "sqlite";
}): Promise<TextToSQLResponse> => {
text_to_sql = async (params: TextToSQLParams): Promise<TextToSQLResponse> => {
return await this.client.fetchJSS("/ai/sql", "POST", params);
};

Expand Down
35 changes: 31 additions & 4 deletions src/general/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
import { BaseResponse } from "../../types";

export type TextToSQLParams = {
prompt: string;
database?: "postgresql" | "mysql" | "sqlite";
sql_schema?: string;
file_store_key?: string;
};

export interface ImageGenerationParams {
prompt: string;
aspect_ratio?: "1:1" | "16:9" | "21:9" | "3:2" | "2:3" | "4:5" | "5:4" | "3:4" | "4:3" | "9:16" | "9:21";
width?: number;
height?: number;
steps?: number;
output_format?: "png" | "svg";
return_type?: "url" | "binary" | "base64";
advance_config?: {
negative_prompt?: string;
guidance?: number;
seed?: number;
};
url?: string;
file_store_key?: string;
}

export interface ImageGenerationResponse extends BaseResponse {
url: string;
}

export interface SentimentResponse extends BaseResponse {
sentiment: {
emotion: string;
Expand All @@ -24,12 +52,11 @@ export interface TranslateParams {
text: string | string[];
}

export interface TranslateImageParams {
target_language: string;
export type TranslateImageParams = {
url?: string;
Comment thread
VineeTagarwaL-code marked this conversation as resolved.
file_store_key?: string;
target_language: string;
return_type?: "url" | "binary" | "base64";
}
};

export interface SpeechToTextResponse extends BaseResponse {
text: string;
Expand Down
8 changes: 7 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export const respToFileChoice = (resp) => {
export const respToFileChoice = (
resp: Response
): {
blob: () => Promise<Blob>;
buffer: () => Promise<Buffer>;
file: (filename: string, options?: FilePropertyBag) => Promise<File>;
} => {
if (!(resp instanceof Response)) {
return resp;
}
Expand Down
15 changes: 4 additions & 11 deletions src/vercel-ai-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,11 @@ export class JigsawStackToolSet {
target_language: z.string().describe('Target language code (e.g., "en", "es", "fr")'),
}),
execute: async ({ url, file_store_key, target_language }) => {
await this.jigsawStack.translate.image({
Comment thread
VineeTagarwaL-code marked this conversation as resolved.
return await this.jigsawStack.translate.image({
url,
file_store_key,
target_language,
return_type: "url",
});

return {
success: true,
message: `Successfully translated image to ${target_language}`,
target_language,
note: "Image has been translated. Use jigsawStack.translate.image() directly to get the binary data.",
};
},
}),

Expand Down Expand Up @@ -250,8 +243,8 @@ export class JigsawStackToolSet {
return await this.jigsawStack.vision.vocr({
Comment thread
VineeTagarwaL-code marked this conversation as resolved.
prompt,
url,
file_store_key,
page_range,
file_store_key,
});
},
}),
Expand All @@ -264,8 +257,8 @@ export class JigsawStackToolSet {
}),
execute: async ({ url, file_store_key }) => {
return await this.jigsawStack.vision.object_detection({
Comment thread
VineeTagarwaL-code marked this conversation as resolved.
url,
file_store_key,
return_type: "url",
});
},
}),
Expand Down
9 changes: 5 additions & 4 deletions src/vision/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface VOCRParams {
export type VOCRParams = {
prompt?: string | string[];
url?: string;
file_store_key?: string;
page_range?: Array<number>;
Comment thread
VineeTagarwaL-code marked this conversation as resolved.
}
};

interface Bounds {
top_left: {
Expand Down Expand Up @@ -46,14 +46,14 @@ export interface VOCRResponse {
page_range?: Array<number>; // only available when page_range is specified
}

export interface ObjectDetectionParams {
export type ObjectDetectionParams = {
url?: string;
file_store_key?: string;
prompts?: string[];
features?: ("object_detection" | "gui")[];
annotated_image?: boolean;
return_type?: "url" | "base64";
}
};

export interface ObjectDetectionResponse {
// Optional annotated image - included only if annotated_image=true and objects/gui_elements exist
Expand All @@ -73,6 +73,7 @@ interface GuiElement {

interface DetectedObject {
bounds: BoundingBox;
label: string;
mask?: string; // URL or base64 string depending on return_type - only present for some objects
}

Expand Down