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

TypeError: _missingExportShim is not a function at ZodSchema.getJsonSchema #2991

Closed
7flash opened this issue Nov 25, 2023 · 1 comment
Closed

Comments

@7flash
Copy link

7flash commented Nov 25, 2023

Following code taken from example and adopted to Deno https://github.com/lgrammel/modelfusion/blob/main/examples/middle-school-math-agent/src/MiddleSchoolMathOpenAITools.ts

const apiKey = Deno.env.get('OPENAI_API_KEY')

const input = { text: 'solve this' }

MathAgent();

async function MathAgent() {
  const { text: problem } = input;

  const { OpenAIApiConfiguration, OpenAIChatMessage, openai, useToolsOrGenerateText, Tool, ZodSchema } = await import("https://dev.jspm.io/modelfusion");
  const { z } = await import("https://dev.jspm.io/zod");

  const calculator = new Tool({
    name: "calculator",
    description: "Execute a calculation",

    parameters: new ZodSchema(
      z.object({
        a: z.number().describe("The first number."),
        b: z.number().describe("The second number."),
        operator: z.enum(["+", "-", "*", "/"]).describe("The operator."),
      })
    ),

    execute: async ({ a, b, operator }) => {
      switch (operator) {
        case "+":
          return a + b;
        case "-":
          return a - b;
        case "*":
          return a * b;
        case "/":
          return a / b;
        default:
          throw new Error(`Unknown operator: ${operator}`);
      }
    },
  });

  const messages = [
    OpenAIChatMessage.system(
      "You are solving math problems. " +
      "Reason step by step. " +
      "Use the calculator when necessary. " +
      "The calculator can only do simple additions, subtractions, multiplications, and divisions. " +
      "When you give the final answer, provide an explanation for how you got it."
    ),
    OpenAIChatMessage.user(problem),
  ];

  console.log(`PROBLEM: ${problem}\n`);

  const { text, toolResults } = await useToolsOrGenerateText(
    openai.ChatTextGenerator({
      api: new OpenAIApiConfiguration({ apiKey }),
      model: "gpt-4-1106-preview",
      temperature: 0,
      maxCompletionTokens: 500,
    }),
    [calculator],
    messages
  );

}

And probably the error is triggered when running around here https://github.com/lgrammel/modelfusion/blob/61562b19863b8ad7c990a0af920a93dc94594941/src/tool/generate-tool-calls-or-text/generateToolCallsOrText.ts#L139C45-L139C53

OPENAI_API_KEY=$(cat .openai-key) deno run --allow-all nov25-third.ts
PROBLEM: solve this

error: Uncaught (in promise) TypeError: _missingExportShim is not a function
        return _missingExportShim(this.zodSchema);
               ^
    at ZodSchema.getJsonSchema (https://dev.jspm.io/npm:modelfusion@0.80.0/_/EQpO4pnp.js:79:16)
    at https://dev.jspm.io/npm:modelfusion@0.80.0:7555:49
    at Array.map (<anonymous>)
    at OpenAIChatModel.doGenerateToolCallsOrText (https://dev.jspm.io/npm:modelfusion@0.80.0:7550:26)
@lgrammel
Copy link

This is not a Zod error, it's related to ModelFusion.

@7flash 7flash closed this as completed Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants