Edits history of script submission #15833 for ' Search (exa)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Exa = {
      apiKey: string;
    };
    /**
     * Search
     * Perform a search with a Exa prompt-engineered query and retrieve a list of relevant results. Optionally get contents.
     */
    export async function main(
      auth: Exa,
      body: {
        query: string;
        useAutoprompt?: false | true;
        type?: "keyword" | "neural" | "auto";
        category?:
          | "company"
          | "research paper"
          | "news"
          | "pdf"
          | "github"
          | "tweet"
          | "personal site"
          | "linkedin profile"
          | "financial report";
      } & {
        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?: "auto" | "never" | "fallback" | "always";
          livecrawlTimeout?: number;
          subpages?: number;
          subpageTarget?: string | string[];
          extras?: { links?: number; imageLinks?: number };
        };
      },
    ) {
      const url = new URL(`https://api.exa.ai/search`);
    
      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