-
Notifications
You must be signed in to change notification settings - Fork 3
Make genai prices auto-update in the worker #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements automatic price data updates for the AI gateway by introducing a new price auto-update mechanism that fetches and caches provider pricing data from the @pydantic/genai-prices package.
- Adds a new
setupPriceAutoUpdatemodule with TTL-based caching (30-minute refresh interval) - Integrates the price update setup into the main request handler
- Implements concurrent fetch prevention and stale data handling logic
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| gateway/src/setupPriceAutoUpdate.ts | New module implementing price data auto-update with caching, TTL management, and integration with the genai-prices package |
| gateway/src/index.ts | Integrates price auto-update by calling setupPriceAutoUpdate at the start of each gateway request |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I think it should be running in the background and the calculation should be using whatever latest data is already present. That data should be replaced independently. |
4c3f4ac to
dab2252
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9a958f1 to
eb84677
Compare
| ctx: ExecutionContext, | ||
| options: GatewayOptions, | ||
| ): Promise<Response> { | ||
| ctx.waitUntil(refreshGenaiPrices()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused how this is non-blocking. refreshGenaiPrices() returns waitForUpdate() which returns providerDataPromise which should be freshDataPromise.
We keep the prices in memory, I believe this should be good enough for a worker? Auto-updating every 30 minutes, as Samuel suggested. The update is non-blocking.