old-agentic
Travis Fischer 2024-06-02 21:49:15 -05:00
rodzic 5411938104
commit 5ecfdc6f7c
7 zmienionych plików z 25 dodań i 9 usunięć

Wyświetl plik

@ -5,11 +5,10 @@ import type { DeepNullable, KyInstance } from '../types.js'
import { assert, delay, getEnv, throttleKy } from '../utils.js' import { assert, delay, getEnv, throttleKy } from '../utils.js'
export namespace clearbit { export namespace clearbit {
// Only allow 20 clearbit API requests per 60s // Allow up to 20 requests per minute by default.
export const throttle = pThrottle({ export const throttle = pThrottle({
limit: 20, limit: 20,
interval: 60 * 1000, interval: 60 * 1000
strict: true
}) })
export interface CompanyEnrichmentOptions { export interface CompanyEnrichmentOptions {
@ -524,7 +523,10 @@ export class ClearbitClient {
throttle?: boolean throttle?: boolean
ky?: KyInstance ky?: KyInstance
} = {}) { } = {}) {
assert(apiKey, 'Error clearbit client missing required "apiKey"') assert(
apiKey,
'ClearbitClient missing required "apiKey" (defaults to "CLEARBIT_API_KEY")'
)
this.apiKey = apiKey this.apiKey = apiKey

Wyświetl plik

@ -7,6 +7,7 @@ export namespace diffbot {
export const API_BASE_URL = 'https://api.diffbot.com' export const API_BASE_URL = 'https://api.diffbot.com'
export const KNOWLEDGE_GRAPH_API_BASE_URL = 'https://kg.diffbot.com' export const KNOWLEDGE_GRAPH_API_BASE_URL = 'https://kg.diffbot.com'
// Allow up to 5 requests per second by default.
export const throttle = pThrottle({ export const throttle = pThrottle({
limit: 5, limit: 5,
interval: 1000, interval: 1000,

Wyświetl plik

@ -6,6 +6,7 @@ import { assert, getEnv, throttleKy } from '../utils.js'
export namespace peopledatalabs { export namespace peopledatalabs {
export const BASE_URL = 'https://api.peopledatalabs.com/v5/' export const BASE_URL = 'https://api.peopledatalabs.com/v5/'
// Allow up to 20 requests per minute by default.
export const throttle = pThrottle({ export const throttle = pThrottle({
limit: 20, limit: 20,
interval: 60 * 1000, interval: 60 * 1000,

Wyświetl plik

@ -4,6 +4,7 @@ import pThrottle from 'p-throttle'
import { assert, getEnv, throttleKy } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
export namespace perigon { export namespace perigon {
// Allow up to 20 requests per minute by default.
export const throttle = pThrottle({ export const throttle = pThrottle({
limit: 20, limit: 20,
interval: 60 * 1000, interval: 60 * 1000,

Wyświetl plik

@ -7,10 +7,10 @@ import { aiFunction, AIFunctionsProvider } from '../fns.js'
import { assert, getEnv, pruneUndefined, throttleKy } from '../utils.js' import { assert, getEnv, pruneUndefined, throttleKy } from '../utils.js'
export namespace predictleads { export namespace predictleads {
// Allow up to 20 requests per minute by default.
export const throttle = pThrottle({ export const throttle = pThrottle({
limit: 20, limit: 20,
interval: 60 * 1000, interval: 60 * 1000
strict: true
}) })
export const DEFAULT_PAGE_SIZE = 100 export const DEFAULT_PAGE_SIZE = 100

Wyświetl plik

@ -1,11 +1,18 @@
import defaultKy, { type KyInstance } from 'ky' import defaultKy, { type KyInstance } from 'ky'
import pThrottle from 'p-throttle'
import { z } from 'zod' import { z } from 'zod'
import { aiFunction, AIFunctionsProvider } from '../fns.js' import { aiFunction, AIFunctionsProvider } from '../fns.js'
import { assert, getEnv } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
// All proxycurl types are auto-generated from their openapi spec // All proxycurl types are auto-generated from their openapi spec
export namespace proxycurl { export namespace proxycurl {
// Allow up to 1500 requests per minute by default.
export const throttle = pThrottle({
limit: 1500,
interval: 5 * 60 * 1000
})
export const CompanyTypeSchema = z.enum([ export const CompanyTypeSchema = z.enum([
'EDUCATIONAL', 'EDUCATIONAL',
'GOVERNMENT_AGENCY', 'GOVERNMENT_AGENCY',
@ -2012,10 +2019,12 @@ export class ProxycurlClient extends AIFunctionsProvider {
apiKey = getEnv('PROXYCURL_API_KEY'), apiKey = getEnv('PROXYCURL_API_KEY'),
apiBaseUrl = getEnv('PROXYCURL_API_BASE_URL') ?? apiBaseUrl = getEnv('PROXYCURL_API_BASE_URL') ??
'https://nubela.co/proxycurl', 'https://nubela.co/proxycurl',
throttle = true,
ky = defaultKy ky = defaultKy
}: { }: {
apiKey?: string apiKey?: string
apiBaseUrl?: string apiBaseUrl?: string
throttle?: boolean
ky?: KyInstance ky?: KyInstance
} = {}) { } = {}) {
assert( assert(
@ -2031,7 +2040,9 @@ export class ProxycurlClient extends AIFunctionsProvider {
this.apiKey = apiKey this.apiKey = apiKey
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
this.ky = ky.extend({ const throttledKy = throttle ? throttleKy(ky, proxycurl.throttle) : ky
this.ky = throttledKy.extend({
prefixUrl: apiBaseUrl, prefixUrl: apiBaseUrl,
headers: { headers: {
Authorization: `Bearer ${apiKey}` Authorization: `Bearer ${apiKey}`

Wyświetl plik

@ -6,7 +6,7 @@ import { aiFunction, AIFunctionsProvider } from '../fns.js'
import { assert, getEnv, throttleKy } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
export namespace wikipedia { export namespace wikipedia {
// Only allow 200 requests per second by default. // Allow up to 200 requests per second by default.
export const throttle = pThrottle({ export const throttle = pThrottle({
limit: 200, limit: 200,
interval: 1000 interval: 1000