The WetroCloud SDK provides an easy way to interact with the WetroCloud API, allowing developers to create collections, insert resources, and query data effortlessly.
npm install wetrocloud-sdk
import Wetrocloud from "wetrocloud-sdk";
const sdk = new Wetrocloud({ apiSecret: "your-api-secret" });
Creates a new collection.
collection_id: string
- (Optional) The unique ID of the collection.
Promise<ICreateCollection | IErrorMessage>;
const collection = await sdk.createCollection({collection_id:'unique_id'});
Retrieves a list of available collections.
Promise<IListCollection[] | IErrorMessage>;
const collections = await sdk.listCollections();
Inserts a resource into a collection.
-
collection_id: string
- The ID of the collection. -
resource: string
- The resource to insert. -
type: string
- The type of resource.
Promise<IInsertResourceCollection | IErrorMessage>;
const response = await sdk.insertResource({
collection_id: "12345",
resource: "Sample text",
type: "text",
});
Queries resources from a collection.
-
collection_id: string
- The ID of the collection. -
request_query: string
- The query string. -
json_schema?: T | T[]
- Optional JSON schema. -
json_schema_rules?: string
- Optional JSON schema rules. -
model?: string
- Optional model parameter. -
stream?: boolean
- Optional. Determines whether the response should be streamed. Defaults totrue
.
Promise<IErrorMessage | IQueryResourceCollectionDynamic<T>>;
const response = await sdk.queryResources({
collection_id: "12345",
request_query: "search query",
json_schema: { topic: "", description: "" },
model: "gpt-4",
});
Chat with a collection using message history.
-
collection_id: string
- The ID of the collection. -
message: string
- The message to send. -
chat_history: { "role": "user" | "system", "content": string }[]
- Chat history.
Promise<IErrorMessage | IQueryResourceCollectionDynamic<T>>;
const response = await sdk.chat({
collection_id: "12345",
message: "Hello, how does this work?",
chat_history: [{ "role": "user", "content": "Hello" }],
});
Deletes a resource from a collection.
-
collection_id: string
- The ID of the collection. -
resource_id: string
- The ID of the resource to delete.
Promise<IGenericResponse | IErrorMessage>;
const response = await sdk.deleteResource({
collection_id: "12345",
resource_id: "67890",
});
Deletes an entire collection.
collection_id: string
- The ID of the collection.
Promise<IGenericResponse | IErrorMessage>;
const response = await sdk.deleteCollection({
collection_id: "12345",
});
Categorizes a resource using predefined categories.
-
resource: string
- The resource to categorize. -
type: string
- The type of resource. -
json_schema: T | T[]
- JSON schema of the resource. -
categories: string[]
- List of categories. -
prompt: string
- An overall command of your request.
Promise<ICatergorizeResource<T> | IErrorMessage>;
const response = await sdk.categorize({
resource: "match review: John Cena vs. The Rock are fighting",
type: "text",
json_schema: { title: "", content: "" },
categories: [
"football",
"coding",
"entertainment",
"basketball",
"wrestling",
"information",
],
prompt: "Where does this fall under?",
});
Generates text without retrieval-augmented generation (RAG).
-
model: string
- The model to use. -
messages: { role: "user" | "system" | "assistant", content: string }[]
- Message history.
Promise<IGenericResponse | IErrorMessage>;
const response = await sdk.textGeneration({
model: "gpt-4",
messages: [{ "role": "user", "content": "Tell me a joke." }],
});
Extracts text from an image.
-
image_url: string
- The URL of the image. -
request_query: string
- The query to process the image.
Promise<IGenericResponse | IErrorMessage>;
const response = await sdk.imageToText({
image_url: "https://example.com/image.jpg",
request_query: "Extract text from this image.",
});
Extracts structured data from a website.
-
website_url: string
- The URL of the website. -
json_schema: T | T[]
- The JSON schema defining the expected structure.
Promise<IDataExtraction<T> | IErrorMessage>;
const response = await sdk.extract({
website_url: "https://example.com",
json_schema: { title: "", body: "" },
});
For more details, check out the official API documentation: WetroCloud Docs