From b5ce6a8bdea056ecc623bdebe0c15ae874952a64 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:11:56 +0000 Subject: [PATCH 1/3] Initial plan From 035db69ea2e5833050726f126a24aefa464379f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:14:35 +0000 Subject: [PATCH 2/3] feat: add gemini text generation sample Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com> --- 01_basic_response.py | 13 ++++++++++++- pyproject.toml | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/01_basic_response.py b/01_basic_response.py index 665b397..bef8fb3 100644 --- a/01_basic_response.py +++ b/01_basic_response.py @@ -1,5 +1,16 @@ +import os + +import google.generativeai as genai + + def main(): - print("Hello from mini-ema!") + api_key = os.environ["GEMINI_API_KEY"] + genai.configure(api_key=api_key) + + model = genai.GenerativeModel("gemini-1.5-flash") + prompt = "Write a story about a magic backpack." + response = model.generate_content(prompt) + print(response.text) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 2ddb7e8..7a7491a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,4 +4,6 @@ version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.10" -dependencies = [] +dependencies = [ + "google-generativeai==0.8.3", +] From c75c86e157737573081bf1fb3e2a1b4f72928a1b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:15:10 +0000 Subject: [PATCH 3/3] chore: handle missing api key gracefully Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com> --- 01_basic_response.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/01_basic_response.py b/01_basic_response.py index bef8fb3..68e4577 100644 --- a/01_basic_response.py +++ b/01_basic_response.py @@ -4,7 +4,9 @@ def main(): - api_key = os.environ["GEMINI_API_KEY"] + 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")