From dd7fe8da007f5d0caf4e1724ef7af116c5a2513f Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Mon, 3 Jun 2024 02:19:25 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- legacy/bin/scratch.ts | 20 +++++++++++++++----- legacy/src/services/exa-client.ts | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/legacy/bin/scratch.ts b/legacy/bin/scratch.ts index 7cf5df38..4ed458ac 100644 --- a/legacy/bin/scratch.ts +++ b/legacy/bin/scratch.ts @@ -8,7 +8,8 @@ import restoreCursor from 'restore-cursor' // import { ProxycurlClient } from '../src/services/proxycurl-client.js' // import { WikipediaClient } from '../src/index.js' // import { PerigonClient } from '../src/index.js' -import { FirecrawlClient } from '../src/index.js' +// import { FirecrawlClient } from '../src/index.js' +import { ExaClient } from '../src/index.js' /** * Scratch pad for testing. @@ -49,10 +50,19 @@ async function main() { // }) // console.log(JSON.stringify(res, null, 2)) - const firecrawl = new FirecrawlClient() - const res = await firecrawl.scrapeUrl({ - // url: 'https://www.bbc.com/news/articles/cp4475gwny1o' - url: 'https://www.firecrawl.dev' + // const firecrawl = new FirecrawlClient() + // const res = await firecrawl.scrapeUrl({ + // // url: 'https://www.bbc.com/news/articles/cp4475gwny1o' + // url: 'https://www.firecrawl.dev' + // }) + // console.log(JSON.stringify(res, null, 2)) + + const exa = new ExaClient() + const res = await exa.search({ + query: 'OpenAI', + contents: { + text: true + } }) console.log(JSON.stringify(res, null, 2)) } diff --git a/legacy/src/services/exa-client.ts b/legacy/src/services/exa-client.ts index b61a251d..dac09150 100644 --- a/legacy/src/services/exa-client.ts +++ b/legacy/src/services/exa-client.ts @@ -2,7 +2,7 @@ import defaultKy, { type KyInstance } from 'ky' import { z } from 'zod' import { aiFunction, AIFunctionsProvider } from '../fns.js' -import { assert, getEnv } from '../utils.js' +import { assert, getEnv, pruneUndefined } from '../utils.js' export namespace exa { export const TextContentsOptionsSchema = z.object({ @@ -151,6 +151,9 @@ export namespace exa { /** The autoprompt string, if applicable. */ autopromptString?: string + + /** Internal ID of this request. */ + requestId?: string } } @@ -209,8 +212,18 @@ export class ExaClient extends AIFunctionsProvider { inputSchema: exa.FindSimilarOptionsSchema }) async findSimilar(opts: exa.FindSimilarOptions) { + const { excludeSourceDomain, ...rest } = opts + const excludeDomains = (opts.excludeDomains ?? []).concat( + excludeSourceDomain ? [new URL(opts.url).hostname] : [] + ) + return this.ky - .post('findSimilar', { json: opts }) + .post('findSimilar', { + json: pruneUndefined({ + ...rest, + excludeDomains: excludeDomains.length ? excludeDomains : undefined + }) + }) .json() }