vercel / modelfusion

The TypeScript library for building AI applications.
https://modelfusion.dev
MIT License
1.01k stars 76 forks source link

File caching with example #279

Closed jakedetels closed 4 months ago

jakedetels commented 4 months ago

Introduced a new FileCache class to enable file-based caching. Given FileCache is a node.js specific module (and cannot be run in the browser), I expose access to it via:

import { FileCache } from "modelfusion/server";

modelfusion/server re-exports everything from modelfusion/index.ts, and additionally includes any node.js specific tools. Without bundling the code this way, we encounter a build error when attempting to import modelfusion into browser contexts (as in the nextjs example app).

lgrammel commented 4 months ago

Thanks for the pull request! I'm still wondering how to best integrate node.js specific things into the library, there are e.g. async_hooks and the ws library already. Can you for now rename "server" to "node"?

jakedetels commented 4 months ago

I spent considerable time trying to find an alternate way to incorporate node.js specific code, including examining the example with getRun.ts and its use of conditional imports with async_hooks. Conditional imports wouldn't work in this case. All the research I found indicated the best strategy is splitting the build into browser vs. node specific files. Glad to try other options if any can be identified.

lgrammel commented 4 months ago

I spent considerable time trying to find an alternate way to incorporate node.js specific code, including examining the example with getRun.ts and its use of conditional imports with async_hooks. Conditional imports wouldn't work in this case. All the research I found indicated the best strategy is splitting the build into browser vs. node specific files. Glad to try other options if any can be identified.

Makes sense, this is a good starting point and might be the best solution. Is the re-export of ../index needed?

jakedetels commented 4 months ago

I was on the fence about the re-export of ../index. I've removed it.

lgrammel commented 4 months ago

Awesome, merged. Thank you!