Attempted to execute a function that is not recorded in the Function Spec

I ran into this error again, which is generated by the tree-shaking algorithm the functions team has implemented. For some reason, the '@foundry/models-api/language-models' package is pruned if it’s not a top-level import relative to where your FoO is declared. This leads to this annoying error: " Attempted to execute a function that is not recorded in the Function Spec.". It would be good to include the function name in the error message along with a stack trace that includes my source files. That aside the workaround is to actually call const response = GPT_4o.createChatCompletion in my FoO so that the dependency is included. Below is a complete example:

import { OntologyEditFunction, Edits } from "@foundry/functions-api";
import { Objects, MachineExecutions } from "@foundry/ontology-api";
import { Uuid } from "@foundry/functions-utils";
import { GPT_4o } from '@foundry/models-api/language-models';

import { Context, EvaluatorResult, Solutions, StateConfig, Workflow } from "./reasoning";
import { SupportedEngines } from "./reasoning/factory";
import { getMachineExecution, getState } from "./reasoning";

export class Text2Action {
    @Edits(MachineExecutions)
    @OntologyEditFunction()
    public async getNextState(
        plan?: string,
        forward: boolean = true,
        executionId?: string,
        inputs: string = '{}',
        xreason: string = SupportedEngines.COMS): Promise<void> {
        
        // I have to include this call or I will get an error that I am attempting to call a function not in the function registry
        // This is due to the GPT_4o being tree shaken by their algorithm
        const response = GPT_4o.createChatCompletion(
            {
                messages: [
                    {role: "SYSTEM", contents: [{ text: 'You are a helpful AI assistant' }]},
                    {role: "USER", contents: [{ text: 'what is your name?' }]},
                ]
            }
        );

        const solution = {
            input: '', //not relevant for this
            id: executionId || '',
            plan: plan || '',
        };
        // The actual call to GPT_4o is deeply nested in the deps of this function call
        const result = await getState(solution, forward, JSON.parse(inputs), xreason as SupportedEngines);

        let machine = getMachineExecution(solution);
        if (!machine) {
            const id = Uuid.random();
            machine = Objects.create().machineExecutions(id);
        }
        machine.machine = JSON.stringify(result.stateMachine);
        machine.state = result.jsonState;
        machine.logs = result.logs;
    }
}

Please consider updating your tree shaking to include model dependencies.

1 Like

This cal also occur if you are dynamically generating queries. The object set functions (Objects.search().someObject) are pruned if the bundler does not detect their use.

1 Like