Skip to content

Commit

Permalink
chore: throttle requests in example to prepare for more requests
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou committed Jan 26, 2025
1 parent 894cee7 commit c56b592
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
Binary file modified bun.lockb
Binary file not shown.
11 changes: 8 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ These examples use OpenAI and FireCrawl APIs. You need to have the following env
- `OPENAI_API_KEY` - Your OpenAI API key
- `FIRECRAWL_API_KEY` - Your FireCrawl API key for GitHub and NPM data access

In order to run Slack example, you need to have `SLACK_API_TOKEN` and `SLACK_CHANNEL_ID` environment variables set.

> [!NOTE]
> FireCrawl requests are throttled to 10 requests per minute, as per the Free Plan, to avoid rate limiting.
## Structure

- `flows.ts` - All flows are defined here
- `agents.ts` - All agents are defined here

> [!NOTE]
> We're using [`Agentic`](https://github.com/agentic/agentic) to create agents.
## Running the examples

- `bun run-organization-analysis.ts callstackincubator` - Analyzing an entire GitHub organization
- `bun run-project-analysis.ts facebook/react-native` - Analyzing a single GitHub project
- `bun run-organization-analysis-with-slack-message.ts callstackincubator` - Analyzing an entire GitHub organization and sending the report to Slack

> [!NOTE]
> In order to run Slack example, you need to have `SLACK_API_TOKEN` environment variable set.
> You will also need to have `SLACK_CHANNEL_ID` environment variable set.
19 changes: 18 additions & 1 deletion example/agents.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { createAISDKTools } from '@agentic/ai-sdk'
import { throttleKy } from '@agentic/core'
import { FirecrawlClient } from '@agentic/firecrawl'
import { SlackClient } from '@agentic/slack'
import { openai } from '@ai-sdk/openai'
import { agent } from 'flows-ai'
import ky from 'ky'
import pThrottle from 'p-throttle'

/**
* Let's throttle the Firecrawl client to 10 requests per minute,
* as per the Firecrawl Free Plan.
*/
const firecrawl = new FirecrawlClient({
ky: throttleKy(
ky,
pThrottle({
limit: 1,
interval: 6000,
strict: true,
})
),
})

const firecrawl = new FirecrawlClient()
const slack = new SlackClient()

export const githubAgent = agent({
Expand Down
5 changes: 4 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
},
"dependencies": {
"@agentic/ai-sdk": "^7.2.0",
"@agentic/core": "^7.2.0",
"@agentic/firecrawl": "^7.2.0",
"@agentic/slack": "^7.2.0"
"@agentic/slack": "^7.2.0",
"ky": "^1.7.4",
"p-throttle": "^6.2.0"
}
}
3 changes: 0 additions & 3 deletions example/run-organization-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const response = await execute(organizationAnalysisFlow, {
onFlowStart: (flow) => {
console.log('Executing', flow.agent.name)
},
onFlowFinish: (flow, response) => {
console.log('Flow finished', flow.agent.name, response)
},
})

console.log(response)

0 comments on commit c56b592

Please # to comment.