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

Structured output example doesn't work #315

Open
uriva opened this issue Dec 28, 2024 · 1 comment
Open

Structured output example doesn't work #315

uriva opened this issue Dec 28, 2024 · 1 comment

Comments

@uriva
Copy link

uriva commented Dec 28, 2024

Description of the bug:

import { GoogleGenerativeAI, SchemaType } from "npm:@google/generative-ai";
const genAI = new GoogleGenerativeAI("<MY_KEY>");

const schema = {
  description: "List of recipes",
  type: SchemaType.ARRAY,
  items: {
    type: SchemaType.OBJECT,
    properties: {
      recipeName: {
        type: SchemaType.STRING,
        description: "Name of the recipe",
        nullable: false,
      },
    },
    required: ["recipeName"],
  },
};

const model = genAI.getGenerativeModel({
  model: "gemini-1.5-pro",
  generationConfig: {
    responseMimeType: "application/json",
    responseSchema: schema,
  },
});

const result = await model.generateContent(
  "List a few popular cookie recipes.",
);
console.log(result.response.text());

yields

error: Uncaught SyntaxError: The requested module 'npm:@google/generative-ai' does not provide an export named 'SchemaType'
import { GoogleGenerativeAI, SchemaType } from "npm:@google/generative-ai";

also it seems that GeneratorConfig doesn't have these fields:

generationConfig: {
    responseMimeType: "application/json",
    responseSchema: schema,
  }

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

@uriva
Copy link
Author

uriva commented Dec 28, 2024

I think this is a version issue, it does work with @21.0.0
but this is strange - the latest version is 22.0.0? I guess it should work ootb with deno, so leaving this open.

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

1 participant