// Access your API key as an environment variable (see "Set up your API key" above) final apiKey = Platform.environment['API_KEY']; if (apiKey == null) { print('No \$API_KEY environment variable'); exit(1); }
// The Gemini 1.5 models are versatile and work with most use cases final model = GenerativeModel(model: 'gemini-1.5-flash', apiKey: apiKey); }
void main() async { // Access your API key as an environment variable (see "Set up your API key" above) final apiKey = Platform.environment['API_KEY']; if (apiKey == null) { print('No \$API_KEY environment variable'); exit(1); } // The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts final model = GenerativeModel(model: 'gemini-1.5-flash', apiKey: apiKey); final content = [Content.text('Write a story about a magic backpack.')]; final response = await model.generateContent(content); print(response.text); }
void main() async { // Access your API key as an environment variable (see "Set up your API key" above) final apiKey = Platform.environment['API_KEY']; if (apiKey == null) { print('No \$API_KEY environment variable'); exit(1); } // The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts final model = GenerativeModel(model: 'gemini-1.5-flash', apiKey: apiKey); final (firstImage, secondImage) = await ( File('image0.jpg').readAsBytes(), File('image1.jpg').readAsBytes() ).wait; final prompt = TextPart("What's different between these pictures?"); final imageParts = [ DataPart('image/jpeg', firstImage), DataPart('image/jpeg', secondImage), ]; final response = await model.generateContent([ Content.multi([prompt, ...imageParts]) ]); print(response.text); }
Future<void> main() async { // Access your API key as an environment variable (see "Set up your API key" above) final apiKey = Platform.environment['API_KEY']; if (apiKey == null) { print('No \$API_KEY environment variable'); exit(1); } // The Gemini 1.5 models are versatile and work with multi-turn conversations (like chat) final model = GenerativeModel( model: 'gemini-1.5-flash', apiKey: apiKey, generationConfig: GenerationConfig(maxOutputTokens: 100)); // Initialize the chat final chat = model.startChat(history: [ Content.text('Hello, I have 2 dogs in my house.'), Content.model([TextPart('Great to meet you. What would you like to know?')]) ]); var content = Content.text('How many paws are in my house?'); var response = await chat.sendMessage(content); print(response.text); }