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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ dist
.yarn/install-state.gz
.pnp.*


test.js
test.ts

.DS_Store
Expand Down
15 changes: 9 additions & 6 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "isomorphic-fetch";
import { BaseConfig } from "../types";
import AudioApis from "./audio/audio";
import Classification from "./classification/index";
import General from "./general";
import { RequestClient } from "./request";
import { File } from "./store/file";
Expand All @@ -27,6 +28,7 @@ export const JigsawStack = (config?: BaseConfig) => {
retrieve: file.retrieve,
delete: file.delete,
};
const classification = new Classification(client);

return {
sentiment: general.sentiment,
Expand All @@ -38,16 +40,17 @@ export const JigsawStack = (config?: BaseConfig) => {
embedding: general.embedding,
audio,
vision: {
vocr: vision.vocr,
object_detection: vision.object_detection,
vocr: vision.vocr.bind(vision),
object_detection: vision.object_detection.bind(vision),
},
web: {
ai_scrape: web.ai_scrape,
html_to_any: web.html_to_any,
search: web.search,
search_suggestions: web.search_suggestions,
ai_scrape: web.ai_scrape.bind(web),
html_to_any: web.html_to_any.bind(web),
search: web.search.bind(web),
search_suggestions: web.search_suggestions.bind(web),
},
store,
validate,
classification,
};
};
3 changes: 1 addition & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class RequestClient {
[key: string]: string;
}
) => {
const disableRequestLogging = this.config?.disableRequestLogging;
const isFileUpload = body instanceof Blob || body instanceof Buffer;
const isFormData = body instanceof FormData;

Expand All @@ -27,8 +26,8 @@ export class RequestClient {
const _headers = {
"x-api-key": this.config?.apiKey,
...(!isFormData && { "Content-Type": isFileUpload ? "application/octet-stream" : "application/json" }),
...this.config?.headers,
...headers,
["x-jigsaw-no-request-log"]: disableRequestLogging && "true",
};

let _body;
Expand Down
39 changes: 2 additions & 37 deletions tests/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// tests/test-helpers.ts - Fix the client structure
import Audio from "../src/audio/audio";
import Classification from "../src/classification/index";
import General from "../src/general/index";
import { RequestClient } from "../src/request";
import Validate from "../src/validate/index";
import Vision from "../src/vision/vision";
import Web from "../src/web/web";
import { JigsawStack } from "jigsawstack";

export function createJigsawStackClient() {
const apiKey = process.env.JIGSAWSTACK_API_KEY;
Expand All @@ -14,36 +8,7 @@ export function createJigsawStackClient() {
throw new Error("JIGSAWSTACK_API_KEY environment variable is required for testing");
}

const client = new RequestClient({ apiKey });

return {
// General APIs
sentiment: (params: any) => new General(client).sentiment(params),
translate: {
text: (params: any) => new General(client).translate.text(params),
image: (params: any) => new General(client).translate.image(params),
},
summary: (params: any) => new General(client).summary(params),
embedding: (params: any) => new General(client).embedding(params),
text_to_sql: (params: any) => new General(client).text_to_sql(params),
prediction: (params: any) => new General(client).prediction(params),
image_generation: (params: any) => new General(client).image_generation(params),

// Audio APIs
audio: new Audio(client),

// Vision APIs
vision: new Vision(client),

// Web APIs - Include both web scraping AND search
web: new Web(client),

// Classification APIs
classification: new Classification(client),

// Validation APIs
validate: new Validate(client),
};
return JigsawStack({ apiKey });
}

export function expectSuccess(result: any): void {
Expand Down
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export interface BaseResponse {
export interface BaseConfig {
apiKey?: string;
baseURL?: string;
disableRequestLogging?: boolean; // Controls how requests are logged. Default is false.
headers?: Record<string, string>; // Additional headers to be sent with the request.
}