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

How to import in Deno? #319

Open
SaavanNanavati opened this issue Jan 3, 2025 · 2 comments
Open

How to import in Deno? #319

SaavanNanavati opened this issue Jan 3, 2025 · 2 comments

Comments

@SaavanNanavati
Copy link

Description of the bug:

I can't import this library in Deno:

import {
    GoogleGenerativeAI,
    HarmBlockThreshold,
    HarmCategory,
} from "npm:@google/[email protected]";

Actual vs expected behavior:

Import should be valid

Any other information you'd like to share?

No response

@Super1Leonardo
Copy link

You need to write "import { GoogleGenerativeAI } from "@google/generative-ai";" in your file and also you need to have
"imports": {
"@google/generative-ai": "npm:@google/generative-ai@^0.21.0",
},
in deno.json file

@sigmaSd
Copy link

sigmaSd commented Jan 20, 2025

deno.json file is optional, you can just run directly a single file ts file,

import { GoogleGenerativeAI } from "npm:@google/generative-ai";
import process from "node:process";

async function searchGrounding() {
  // [USE google_search as a tool in Gemini 2.0]
  // Make sure to include these imports:
  // import {
  //  GoogleGenerativeAI,
  // } from "@google/generative-ai";
  const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY ?? "");
  const model = genAI.getGenerativeModel(
    {
      model: "gemini-2.0-flash-exp",
      tools: [
        {
          googleSearch: {},
        },
      ],
    },
  );

  while (true) {
    const input = prompt(">");
    if (!input) break;
    const result = await model.generateContent(input);
    console.log(result.response.text());
    console.log(result.response.candidates?.at(0)?.groundingMetadata);
  }
  // [END search_grounding]
}

await searchGrounding();

deno -NE a.ts

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

3 participants