Edits history of script submission #15830 for ' Find similar links (exa)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Exa = {
      apiKey: string;
    };
    /**
     * Find similar links
     * Find similar links to the link provided. Optionally get contents.
     */
    export async function main(
      auth: Exa,
      body: { url: string } & {
        numResults?: number;
        includeDomains?: string[];
        excludeDomains?: string[];
        startCrawlDate?: string;
        endCrawlDate?: string;
        startPublishedDate?: string;
        endPublishedDate?: string;
        includeText?: string[];
        excludeText?: string[];
        contents?: {
          text?:
            | false
            | true
            | { maxCharacters?: number; includeHtmlTags?: false | true };
          highlights?: {
            numSentences?: number;
            highlightsPerUrl?: number;
            query?: string;
          };
          summary?: { query?: string };
          livecrawl?: "never" | "fallback" | "always" | "auto";
          livecrawlTimeout?: number;
          subpages?: number;
          subpageTarget?: string | string[];
          extras?: { links?: number; imageLinks?: number };
        };
      },
    ) {
      const url = new URL(`https://api.exa.ai/findSimilar`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-API-Key": auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago