From 998a1f82e6c034708566086b43e3657dd9f582eb Mon Sep 17 00:00:00 2001 From: Mark McDonald Date: Fri, 21 Jun 2024 12:17:23 +0800 Subject: [PATCH] Add generateContent text samples for Python and rest --- examples/gemini/python/api/generatecontent_text.py | 9 +++++++++ examples/gemini/rest/api/generatecontent_text.sh | 8 ++++++++ 2 files changed, 17 insertions(+) create mode 100644 examples/gemini/python/api/generatecontent_text.py create mode 100644 examples/gemini/rest/api/generatecontent_text.sh diff --git a/examples/gemini/python/api/generatecontent_text.py b/examples/gemini/python/api/generatecontent_text.py new file mode 100644 index 000000000..4ec9520d0 --- /dev/null +++ b/examples/gemini/python/api/generatecontent_text.py @@ -0,0 +1,9 @@ +import os +import google.generativeai as genai + +genai.configure(api_key=os.environ["GOOGLE_API_KEY"]) + +model = genai.GenerativeModel("gemini-1.5-flash") + +response = model.generate_content("Give me python code to sort a list") +print(response.text) diff --git a/examples/gemini/rest/api/generatecontent_text.sh b/examples/gemini/rest/api/generatecontent_text.sh new file mode 100644 index 000000000..ab4c300bd --- /dev/null +++ b/examples/gemini/rest/api/generatecontent_text.sh @@ -0,0 +1,8 @@ +curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${GOOGLE_API_KEY}" \ + -H 'Content-Type: application/json' \ + -X POST \ + -d '{ + "contents": [{ + "parts":[{"text": "Give me python code to sort a list."}] + }] + }'