Comparing version 1.0.12 to 1.0.13
@@ -55,2 +55,3 @@ /** | ||
* @property {HighlightsContentsOptions | boolean} [highlights] - Options for retrieving highlights. | ||
* @property {SummaryContentsOptions | boolean} [summary] - Options for retrieving summary. | ||
*/ | ||
@@ -60,2 +61,3 @@ type ContentsOptions = { | ||
highlights?: HighlightsContentsOptions | true; | ||
summary?: SummaryContentsOptions | true; | ||
}; | ||
@@ -85,2 +87,10 @@ /** | ||
/** | ||
* Options for retrieving summary from page. | ||
* @typedef {Object} SummaryContentsOptions | ||
* @property {string} [query] - The query string to use for summary generation. | ||
*/ | ||
type SummaryContentsOptions = { | ||
query?: string; | ||
}; | ||
/** | ||
* @typedef {Object} TextResponse | ||
@@ -101,10 +111,17 @@ * @property {string} text - Text from page | ||
}; | ||
/** | ||
* @typedef {Object} SummaryResponse | ||
* @property {string} summary - The generated summary of the page content. | ||
*/ | ||
type SummaryResponse = { | ||
summary: string; | ||
}; | ||
type Default<T extends {}, U> = [keyof T] extends [never] ? U : T; | ||
/** | ||
* @typedef {Object} ContentsResultComponent | ||
* Depending on 'ContentsOptions', this yields either a 'TextResponse', a 'HighlightsResponse', both, or an empty object. | ||
* Depending on 'ContentsOptions', this yields a combination of 'TextResponse', 'HighlightsResponse', 'SummaryResponse', or an empty object. | ||
* | ||
* @template T - A type extending from 'ContentsOptions'. | ||
*/ | ||
type ContentsResultComponent<T extends ContentsOptions> = Default<(T['text'] extends (object | true) ? TextResponse : {}) & (T['highlights'] extends (object | true) ? HighlightsResponse : {}), TextResponse>; | ||
type ContentsResultComponent<T extends ContentsOptions> = Default<(T['text'] extends (object | true) ? TextResponse : {}) & (T['highlights'] extends (object | true) ? HighlightsResponse : {}) & (T['summary'] extends (object | true) ? SummaryResponse : {}), TextResponse>; | ||
/** | ||
@@ -151,8 +168,8 @@ * Represents a search result object. | ||
/** | ||
* Makes a request to the Exa API. | ||
* @param {string} endpoint - The API endpoint to call. | ||
* @param {string} method - The HTTP method to use. | ||
* @param {any} [body] - The request body for POST requests. | ||
* @returns {Promise<any>} The response from the API. | ||
*/ | ||
* Makes a request to the Exa API. | ||
* @param {string} endpoint - The API endpoint to call. | ||
* @param {string} method - The HTTP method to use. | ||
* @param {any} [body] - The request body for POST requests. | ||
* @returns {Promise<any>} The response from the API. | ||
*/ | ||
private request; | ||
@@ -196,2 +213,2 @@ /** | ||
export { BaseSearchOptions, ContentsOptions, ContentsResultComponent, Default, FindSimilarOptions, HighlightsContentsOptions, HighlightsResponse, RegularSearchOptions, SearchResponse, SearchResult, TextContentsOptions, TextResponse, Exa as default }; | ||
export { BaseSearchOptions, ContentsOptions, ContentsResultComponent, Default, FindSimilarOptions, HighlightsContentsOptions, HighlightsResponse, RegularSearchOptions, SearchResponse, SearchResult, SummaryContentsOptions, SummaryResponse, TextContentsOptions, TextResponse, Exa as default }; |
@@ -58,8 +58,8 @@ "use strict"; | ||
/** | ||
* Makes a request to the Exa API. | ||
* @param {string} endpoint - The API endpoint to call. | ||
* @param {string} method - The HTTP method to use. | ||
* @param {any} [body] - The request body for POST requests. | ||
* @returns {Promise<any>} The response from the API. | ||
*/ | ||
* Makes a request to the Exa API. | ||
* @param {string} endpoint - The API endpoint to call. | ||
* @param {string} method - The HTTP method to use. | ||
* @param {any} [body] - The request body for POST requests. | ||
* @returns {Promise<any>} The response from the API. | ||
*/ | ||
async request(endpoint, method, body) { | ||
@@ -95,8 +95,9 @@ const response = await (0, import_cross_fetch.default)(this.baseURL + endpoint, { | ||
async searchAndContents(query, options) { | ||
const { text, highlights, ...rest } = options || {}; | ||
const { text, highlights, summary, ...rest } = options || {}; | ||
return await this.request("/search", "POST", { | ||
query, | ||
contents: !text && !highlights ? { text: true } : { | ||
contents: !text && !highlights && !summary ? { text: true } : { | ||
...text ? { text } : {}, | ||
...highlights ? { highlights } : {} | ||
...highlights ? { highlights } : {}, | ||
...summary ? { summary } : {} | ||
}, | ||
@@ -122,8 +123,9 @@ ...rest | ||
async findSimilarAndContents(url, options) { | ||
const { text, highlights, ...rest } = options || {}; | ||
const { text, highlights, summary, ...rest } = options || {}; | ||
return await this.request("/findSimilar", "POST", { | ||
url, | ||
contents: !text && !highlights ? { text: true } : { | ||
contents: !text && !highlights && !summary ? { text: true } : { | ||
...text ? { text } : {}, | ||
...highlights ? { highlights } : {} | ||
...highlights ? { highlights } : {}, | ||
...summary ? { summary } : {} | ||
}, | ||
@@ -130,0 +132,0 @@ ...rest |
{ | ||
"name": "exa-js", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Exa SDK for Node.js and the browser", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -17,3 +17,3 @@ # exa-js | ||
```js | ||
import Exa from "exa-node" | ||
import Exa from "exa-js" | ||
@@ -23,2 +23,57 @@ const exa = new Exa(process.env.EXA_API_KEY) | ||
### Common commands | ||
```js | ||
// Basic search | ||
const basicResults = await exa.search("This is a Exa query:"); | ||
// Autoprompted search | ||
const autoPromptedResults = await exa.search("autopromptable query", { useAutoprompt: true }); | ||
// Search with date filters | ||
const dateFilteredResults = await exa.search("This is a Exa query:", { | ||
startPublishedDate: "2019-01-01", | ||
endPublishedDate: "2019-01-31" | ||
}); | ||
// Search with domain filters | ||
const domainFilteredResults = await exa.search("This is a Exa query:", { | ||
includeDomains: ["www.cnn.com", "www.nytimes.com"] | ||
}); | ||
// Search and get text contents | ||
const searchAndTextResults = await exa.searchAndContents("This is a Exa query:", { text: true }); | ||
// Search and get highlights | ||
const searchAndHighlightsResults = await exa.searchAndContents("This is a Exa query:", { highlights: true }); | ||
// Search and get contents with contents options | ||
const searchAndCustomContentsResults = await exa.searchAndContents("This is a Exa query:", { | ||
text: { includeHtmlTags: true, maxCharacters: 1000 }, | ||
highlights: { highlightsPerUrl: 2, numSentences: 1, query: "This is the highlight query:" } | ||
}); | ||
// Find similar documents | ||
const similarResults = await exa.findSimilar("https://example.com"); | ||
// Find similar excluding source domain | ||
const similarExcludingSourceResults = await exa.findSimilar("https://example.com", { excludeSourceDomain: true }); | ||
// Find similar with contents | ||
const similarWithContentsResults = await exa.findSimilarAndContents("https://example.com", { text: true, highlights: true }); | ||
// Get text contents | ||
const textContentsResults = await exa.getContents(["ids"], { text: true }); | ||
// Get highlights | ||
const highlightsContentsResults = await exa.getContents(["ids"], { highlights: true }); | ||
// Get contents with contents options | ||
const customContentsResults = await exa.getContents(["ids"], { | ||
text: { includeHtmlTags: true, maxCharacters: 1000 }, | ||
highlights: { highlightsPerUrl: 2, numSentences: 1, query: "This is the highlight query:" } | ||
}); | ||
``` | ||
### `exa.search(query: string, options?: SearchOptions): Promise<SearchResponse>` | ||
@@ -25,0 +80,0 @@ Performs a search on the Exa system with the given parameters. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
54888
482
106