|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import os |
| 15 | + |
| 16 | +PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 17 | + |
| 18 | + |
| 19 | +def generate_from_text_input() -> str: |
| 20 | + # [START generativeaionvertexai_gemini_generate_from_text_input] |
| 21 | + import vertexai |
| 22 | + from vertexai.generative_models import GenerativeModel |
| 23 | + |
| 24 | + # TODO(developer): Update and un-comment below line |
| 25 | + # PROJECT_ID = "your-project-id" |
| 26 | + vertexai.init(project=PROJECT_ID, location="us-central1") |
| 27 | + |
| 28 | + model = GenerativeModel("gemini-2.0-flash-001") |
| 29 | + |
| 30 | + response = model.generate_content( |
| 31 | + "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?" |
| 32 | + ) |
| 33 | + |
| 34 | + print(response.text) |
| 35 | + # Example response: |
| 36 | + # **Emphasizing the Dried Aspect:** |
| 37 | + # * Everlasting Blooms |
| 38 | + # * Dried & Delightful |
| 39 | + # * The Petal Preserve |
| 40 | + # ... |
| 41 | + |
| 42 | + # [END generativeaionvertexai_gemini_generate_from_text_input] |
| 43 | + return response.text |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + generate_from_text_input() |
0 commit comments