|
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 | | -from vertexai.preview.prompts import Prompt |
17 | | - |
18 | | -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
19 | | - |
20 | | - |
21 | | -def restore_prompt_version() -> Prompt: |
22 | | - """Restores specified version for specified prompt.""" |
23 | | - |
24 | | - # [START generativeaionvertexai_prompt_restore_version] |
25 | | - import vertexai |
26 | | - from vertexai.preview import prompts |
27 | | - |
28 | | - # Initialize vertexai |
29 | | - vertexai.init(project=PROJECT_ID, location="us-central1") |
30 | | - |
31 | | - # Create local Prompt |
32 | | - prompt = Prompt( |
33 | | - prompt_name="zoologist", |
34 | | - prompt_data="Which animal is the fastest on earth?", |
35 | | - model_name="gemini-2.0-flash-001", |
36 | | - system_instruction="You are a zoologist. Answer in a short sentence.", |
37 | | - ) |
38 | | - # Save Prompt to online resource. |
39 | | - prompt1 = prompts.create_version(prompt=prompt) |
40 | | - prompt_id = prompt1.prompt_id |
41 | | - |
42 | | - # Restore to prompt version id 1 (original) |
43 | | - prompt_version_metadata = prompts.restore_version(prompt_id=prompt_id, version_id="1") |
44 | | - |
45 | | - # Fetch the newly restored latest version of the prompt |
46 | | - prompt1 = prompts.get(prompt_id=prompt_version_metadata.prompt_id) |
47 | | - |
48 | | - # Example response: |
49 | | - # Restored prompt version 1 under prompt id 12345678910 as version number 2 |
50 | | - # [END generativeaionvertexai_prompt_restore_version] |
51 | | - return prompt1 |
52 | | - |
53 | | - |
54 | | -if __name__ == "__main__": |
55 | | - restore_prompt_version() |
| 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 | +# from vertexai.preview.prompts import Prompt |
| 17 | +# |
| 18 | +# PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") |
| 19 | +# |
| 20 | +# |
| 21 | +# def restore_prompt_version() -> Prompt: |
| 22 | +# """Restores specified version for specified prompt.""" |
| 23 | +# |
| 24 | +# # [START generativeaionvertexai_prompt_restore_version] |
| 25 | +# import vertexai |
| 26 | +# from vertexai.preview import prompts |
| 27 | +# |
| 28 | +# # Initialize vertexai |
| 29 | +# vertexai.init(project=PROJECT_ID, location="us-central1") |
| 30 | +# |
| 31 | +# # Create local Prompt |
| 32 | +# prompt = Prompt( |
| 33 | +# prompt_name="zoologist", |
| 34 | +# prompt_data="Which animal is the fastest on earth?", |
| 35 | +# model_name="gemini-2.0-flash-001", |
| 36 | +# system_instruction="You are a zoologist. Answer in a short sentence.", |
| 37 | +# ) |
| 38 | +# # Save Prompt to online resource. |
| 39 | +# prompt1 = prompts.create_version(prompt=prompt) |
| 40 | +# prompt_id = prompt1.prompt_id |
| 41 | +# |
| 42 | +# # Restore to prompt version id 1 (original) |
| 43 | +# prompt_version_metadata = prompts.restore_version(prompt_id=prompt_id, version_id="1") |
| 44 | +# |
| 45 | +# # Fetch the newly restored latest version of the prompt |
| 46 | +# prompt1 = prompts.get(prompt_id=prompt_version_metadata.prompt_id) |
| 47 | +# |
| 48 | +# # Example response: |
| 49 | +# # Restored prompt version 1 under prompt id 12345678910 as version number 2 |
| 50 | +# # [END generativeaionvertexai_prompt_restore_version] |
| 51 | +# return prompt1 |
| 52 | +# |
| 53 | +# |
| 54 | +# if __name__ == "__main__": |
| 55 | +# restore_prompt_version() |
0 commit comments