Skip to content
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

make flows optional on ai.startFlowServer #1346

Open
zerolethanh opened this issue Nov 20, 2024 · 2 comments
Open

make flows optional on ai.startFlowServer #1346

zerolethanh opened this issue Nov 20, 2024 · 2 comments

Comments

@zerolethanh
Copy link

Is your feature request related to a problem? Please describe.
I have to import many flows when run ai.startFlowServer

Describe the solution you'd like
public this registeredFlows prop? or something like optional flows prop on ai.startFlowServer, e.g: ai.startFlowServer({flows?:[...ai.registeredFlows]})

Describe alternatives you've considered
We have designed flows system by read flows.ts|.js in sub-folders like:

/src | /lib
  '- /flows/
       '- /users/
          '- flows.ts|.js <-- at this point `export {userListFlow} from './list/userListFlow'`
          '- /list/
              '- userListFlow.ts|.js
/// read flows code
const allFlowsDir = path.resolve(devEnv ? "src" : "lib", "flows");
fs.readdirSync(allFlowsDir).forEach((name) => {
    const flowDir = path.join(allFlowsDir, name);
    logInfo("loading flow:", flowDir);
    try {
        require(path.join(flowDir, "flows")); // require flows.ts|.js
        logSuccess(`loaded flow: ${flowDir}`);
    } catch (e:any) {
        console.log((e as Error).stack)
    }
});

Additional context
image

@zerolethanh
Copy link
Author

zerolethanh commented Nov 20, 2024

currently, we resolved this issue by this solution:

// read all flows in /flows dir
const allFlowsDir = path.resolve(devEnv ? "src" : "lib", "flows");
type IFlows = FlowServerOptions['flows']
const allFlows: IFlows = []

fs.readdirSync(allFlowsDir).forEach((name) => {
    const flowDir = path.join(allFlowsDir, name);
    // logInfo("loading flow:", flowDir);
    try {
        const flowList = require(path.join(flowDir, "flows")); // require flows.ts|.js
        if (flowList) {
            const flows = Object.values(flowList) as IFlows
            allFlows.push(...flows)
        }
        // logSuccess(`loaded flow: ${flowDir}`);
    } catch (e: any) {
        logError(e);
    }
});

ai.startFlowServer(
  {
    flows: allFlows
  }
);

@apascal07
Copy link
Collaborator

apascal07 commented Nov 21, 2024

@pavelgj Exposing Genkit.registeredFlows seems reasonable even if we were to deprecate/not recommend Genkit.startFlowServer anymore since users may still want to iterate through all of them to add to their own server.

Thanks for the suggestion, @zerolethanh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants