1.0.10 • Published 1 year ago
web-oracle v1.0.10
WebOracle TypeScript SDK
The official TypeScript SDK for interacting with the WebOracle API. This SDK provides a simple and intuitive interface for making requests to various WebOracle endpoints.
Installation
Install the SDK using npm:
npm install web-oracleOr using yarn:
yarn add web-oracleUsage
First, import and initialize the WebOracle client:
import { WebOracle } from "weboracle-sdk";
const webOracle = new WebOracle("your_api_key");Now you can use the various API methods:
Answer API
// Get an answer
const answerResponse = await webOracle.answer.get({
query: "What is the capital of France?",
});
// Perform an advanced search
const advancedSearchResponse = await webOracle.answer.searchAdvanced({
query: "Latest developments in AI",
additionalInstructions: "Focus on the last 6 months",
});Browse API
const browseResult = await webOracle.browse.explore({
url: "https://example.com",
singlePage: true,
});Crawl API
const crawlResult = await webOracle.crawl.start({
url: "https://example.com",
crawlOptions: {
maxDepth: 3,
limit: 100,
},
});Search API
// Perform a Serper search
const searchResults = await webOracle.search.serperSearch({
q: "best restaurants in New York",
num: 10,
});
// Perform a LinkedIn search
const linkedInResults = await webOracle.search.linkedInSearch({
query: "software engineers",
page: 1,
resultsPerPage: 20,
});
// Rerank search results
const rerankedResults = await webOracle.search.rerank({
query: "machine learning applications",
});
// Generate search queries
const generatedQueries = await webOracle.search.generateQueries({
query: "Electric vehicles market trends",
});Scrape API
const scrapedContent = await webOracle.scrape.extract({
url: "https://example.com",
scrapeOptions: {
formats: ["markdown", "html"],
onlyMainContent: true,
},
});Error Handling
The SDK uses custom WebOracleError for error handling. You can catch and handle these errors in your code:
try {
const result = await webOracle.answer.getAnswer({ query: "Some query" });
// Handle successful response
} catch (error) {
if (error instanceof WebOracleError) {
console.error(`API Error: ${error.message}, Status: ${error.status}`);
} else {
console.error("Unexpected error:", error);
}
}Documentation
For detailed information about each API endpoint and its parameters, please refer to the API documentation.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.