Skip to content

Add Gemini text-generation sample using official SDK#2

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/update-gemini-api-documentation
Closed

Add Gemini text-generation sample using official SDK#2
Copilot wants to merge 3 commits intomainfrom
copilot/update-gemini-api-documentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 27, 2025

The task requires demonstrating Gemini text generation per the official docs (zh-CN), configuring the API key and invoking a model to produce text.

  • Gemini SDK integration
    • Add google-generativeai dependency.
    • Configure client with GEMINI_API_KEY, fail fast with a clear error if unset.
  • Sample text generation
    • Instantiate gemini-1.5-flash and print generated text for a simple prompt.

Example:

import google.generativeai as genai
import os

api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
    raise EnvironmentError("Set the GEMINI_API_KEY environment variable to call Gemini API.")

genai.configure(api_key=api_key)
model = genai.GenerativeModel("gemini-1.5-flash")
print(model.generate_content("Write a story about a magic backpack.").text)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • ai.google.dev
    • Triggering command: /usr/bin/python python - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

https://ai.google.dev/gemini-api/docs/text-generation?hl=zh-cn


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 27, 2025 13:14
Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com>
Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com>
Copilot AI changed the title [WIP] Update documentation for Gemini API text generation Add Gemini text-generation sample using official SDK Dec 27, 2025
Copilot AI requested a review from hiyouga December 27, 2025 13:16
@hiyouga hiyouga closed this Dec 27, 2025
@hiyouga hiyouga deleted the copilot/update-gemini-api-documentation branch December 28, 2025 11:41
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

Successfully merging this pull request may close these issues.

2 participants