https://www.boundaryml.com logo
I may be going a bit crazy here (or be an idiot), ...
# help
w
complianceWorkerQueue.subscribe({ handler: "packages/functions/src/complianceWorker/index.handler", link: [bucket, complianceWorkerQueue, ...allSecrets, complianceDecisionTopic], nodejs: { install: ["@boundaryml/baml", "@boundaryml/baml-linux-x64-gnu"], esbuild: { loader: { ".node": "file", }, }, }, }); I have this set up with esbuild I don't have any IDE warnings, and I can fully see Image in my packages boundary/baml but I get The requested module '@boundaryml/baml' does not provide an export named 'Image', no matter what I try
@aaronv (BAML) @Vaibhav (BAML πŸ‘) sorry for ping but have you guys tried anything with lambda recently? Trying to get something deployed tonight for a client. May potentially switch to a container function/fargate task if needed but would rather not...
v
Hi @wllvns no worries. stuck in a few meetings. Let me tag @seawatts who make have more context about Lamba functions here
Where are you using image?
I wonder if you can click on the node modules thing. And then see if image is included
s
Thanks for reaching out @wllvns sorry you’re running into this. Are you using SST? Or AWS cdk?
w
SST
SST v3, I've done it previously may dust off my old example and try to upgrade to 0.205.0
somewhat annoyingly my previous test repo still works with old BAML code, doesn't support image there
Going to try and implement the image aspect, if it works there I may continue debugging, otherwise I'll probably just move to a container deployment on fargate as I've got some code in place to do that already as well
Copy code
{
  "errorType": "Runtime.UserCodeSyntaxError",
  "errorMessage": "SyntaxError: Named export 'Image' not found. The requested module '@boundaryml/baml' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from '@boundaryml/baml';\nconst { ClientRegistry, Image } = pkg;\n",
  "stack": [
    "Runtime.UserCodeSyntaxError: SyntaxError: Named export 'Image' not found. The requested module '@boundaryml/baml' is a CommonJS module, which may not support all module.exports as named exports.",
    "CommonJS modules can always be imported via the default export, for example using:",
    "",
    "import pkg from '@boundaryml/baml';",
    "const { ClientRegistry, Image } = pkg;",
    "",
    "    at _loadUserApp (file:///var/runtime/index.mjs:1106:17)",
    "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1148:21)",
    "    at async start (file:///var/runtime/index.mjs:1335:23)",
    "    at async file:///var/runtime/index.mjs:1342:1"
  ]
}
my test repo at least gave a more helpful/complete error
Image import solution: import pkg from @boundaryml/baml, then reference pkg.Image I was also getting another weird error, but my guess at this point is that is self-inflicted
Copy code
import { Resource } from "sst";
import { Handler } from "aws-lambda";
import { Example } from "@baml-test/core/example";
import pkg from '@boundaryml/baml'

import { b } from "../baml_client"

export const handler: Handler = async (_event) => {
  const cr = new pkg.ClientRegistry()
  // Creates a new client
  console.log(Resource.OPENAI_API_KEY.value)
  cr.addLlmClient('MyAmazingClient', 'openai', {
    model: "gpt-4o-2024-11-20",
    temperature: 0.7,
    api_key: Resource.OPENAI_API_KEY.value
  })
  // Sets MyAmazingClient as the primary client
  cr.setPrimary('MyAmazingClient')
  const resume = await b.ExtractResume("hithere", { clientRegistry: cr })
  const image =  await b.ExtractImageContent(pkg.Image.fromUrl("..."), { env: {
    OPENAI_API_KEY: Resource.OPENAI_API_KEY.value
    }})
  return {
    statusCode: 200,
    body: `${Example.hello()}. yes it works.... ${JSON.stringify(image)}`,
  };
};
there's a complete-ish solution that worked for me doing image processing in lambda using BAML, as well as a more SST way of providing the envs to the model via SST Secrets
@seawatts @Vaibhav (BAML πŸ‘) thank you both for jumping in, apologies for the false emergency
api infra def was defined in the examples:
Copy code
import { bucket } from "./storage";
import { secrets } from "./secrets";

export const api = new sst.aws.ApiGatewayV2("Api");

// for when sstv3 supports lambda layers
// const installPackages = stack.stage === "prod" ? [] : ["@boundaryml/baml"];
// const bamlLayer =
// stack.stage === "prod"
//   ? [
//       new sst.aws.lambda.LayerVersion(stack, "BAMLLayer", {
//         code: lambda.Code.fromAsset("layers/baml-layer"),
//       }),
//     ]
//   : [];

api.route("GET /", {
  link: [bucket, secrets.OpenAiApiKey],
  runtime: "nodejs20.x",
  environment: {
    // OPENAI_API_KEY: process.env.OPENAI_API_KEY
  },
  nodejs: {
    install: ["@boundaryml/baml", "@boundaryml/baml-linux-x64-gnu"],
    // TBD which loader config we need (this one or the esbuild one)
    loader: {
      ".node": "file",
    },

    esbuild: {
      loader: {
        ".node": "file",
      },
      // TODO: add the lambda layer when sstv3 supports it (or upload it manually)
      // since this will be in the lambda layer, don't include it in the final bundle
      // external: ["@boundaryml/baml"],
    },
  },
  handler: "packages/functions/src/api.handler",
});
looks like I got some personal debugging to do....