Function works on local test bench but wont deploy

Joseff Evans 0 Reputation points
2024-09-21T13:44:30.91+00:00

I have a classifier.mjs file that runs fine locally but wont deploy

It will deploy if I remove the @xenova/transformer import but I cant work out why - any ideas?

import { app } from '@azure/functions';
import path from 'path';

import { pipeline, env } from '@xenova/transformers';

env.allowLocalModels = true;
env.allowRemoteModels = false;
env.localModelPath = path.join(process.cwd(),"/src/functions/models");

app.http('classifyTicket', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    handler: async (request, context) => {
        context.log(`Http function processed request for url "${request.url}"`);

        const classifier = await pipeline("text-classification", "/ICTBertClassifier");
        
        const name = request.query.get('name') || await request.text() || 'world';

        context.log(name)

        const classifiedText = await classifier(name);

        return { body: JSON.stringify(classifiedText) };

    }
});
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,953 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Luis Arias 6,786 Reputation points
    2024-09-21T19:43:11.8166667+00:00

    Hi Joseff,

    You need to add that dependencies to package.json in order to include that library.

    {
      "type": "module",
      "main": "index.mjs",
      "dependencies": {
        "@xenova/transformers": "^1.0.0"  // Ensure you have the correct version
      }
    }
    

    References:

    If the information helped address your question, please Accept the answer.

    Luis


  2. Daniel FANG 545 Reputation points
    2024-09-26T02:13:38.78+00:00

    To install npm package, you can use below command in the root of your function project. -d option will save the package to the package.json file.

    You can also go to the function app's deployment tab to view more details of the error during the deployment. the function app actually does the build on the server side.

    npm install @xenova/transformers -d
    

  3. Joseff Evans 0 Reputation points
    2024-09-26T09:33:35.6066667+00:00

    Thanks for the info - the issue ended up being related to the function being a linux function and me developing it in windows.

    Set up WSL so I could build it in linux and all seems ok now

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.