Skip to content

Commit 2ade5d2

Browse files
authored
Copy templates/makersuite_*.ipynb to aistudio_*.ipynb (google#368)
* Git cp - rename file to new location * Git cp - introduce a temp file * Git cp - revert temp file to original path * Correct names in nb metadata
1 parent a3346c2 commit 2ade5d2

File tree

2 files changed

+263
-0
lines changed

2 files changed

+263
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "Tce3stUlHN0L"
7+
},
8+
"source": [
9+
"##### Copyright 2023 Google LLC"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {
16+
"cellView": "form",
17+
"id": "tuOe1ymfHZPu"
18+
},
19+
"outputs": [],
20+
"source": [
21+
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
22+
"# you may not use this file except in compliance with the License.\n",
23+
"# You may obtain a copy of the License at\n",
24+
"#\n",
25+
"# https://www.apache.org/licenses/LICENSE-2.0\n",
26+
"#\n",
27+
"# Unless required by applicable law or agreed to in writing, software\n",
28+
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
29+
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
30+
"# See the License for the specific language governing permissions and\n",
31+
"# limitations under the License."
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"metadata": {
38+
"id": "kWIuwKG2_oWE"
39+
},
40+
"outputs": [],
41+
"source": [
42+
"# Install the client library and import necessary modules.\n",
43+
"!pip install google-generativeai\n",
44+
"import google.generativeai as palm\n",
45+
"import base64\n",
46+
"import json\n",
47+
"import pprint"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {
54+
"id": "_SvYoR3WCeKr"
55+
},
56+
"outputs": [],
57+
"source": [
58+
"# Configure the client library by providing your API key.\n",
59+
"palm.configure(api_key=\"YOUR API KEY\")"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {
66+
"id": "Pwab0i0RAHBN"
67+
},
68+
"outputs": [],
69+
"source": [
70+
"# These parameters for the model call can be set by URL parameters.\n",
71+
"model = \"\" # @param {isTemplate: true}\n",
72+
"temperature = 0.25 # @param {isTemplate: true}\n",
73+
"candidate_count = 1 # @param {isTemplate: true}\n",
74+
"top_k = 40 # @param {isTemplate: true}\n",
75+
"top_p = 0.95 # @param {isTemplate: true}\n",
76+
"context_b64 = '' # @param {isTemplate: true}\n",
77+
"examples_b64 = \"\" # @param {isTemplate: true}\n",
78+
"messages_b64 = \"\" # @param {isTemplate: true}\n",
79+
"\n",
80+
"defaults = {\n",
81+
" 'model': model,\n",
82+
" 'temperature': temperature,\n",
83+
" 'candidate_count': candidate_count,\n",
84+
" 'top_k': top_k,\n",
85+
" 'top_p': top_p,\n",
86+
"}\n",
87+
"\n",
88+
"# Convert the model context from a baese64 string to a string.\n",
89+
"context = base64.b64decode(context_b64).decode(\"utf-8\")\n",
90+
"\n",
91+
"# Convert the model inputs from base64 strings to lists.\n",
92+
"examples = json.loads(base64.b64decode(examples_b64).decode(\"utf-8\"))\n",
93+
"messages = json.loads(base64.b64decode(messages_b64).decode(\"utf-8\"))\n",
94+
"\n",
95+
"# Show what will be sent with the API call.\n",
96+
"pprint.pprint(defaults | {\n",
97+
" 'context': context, 'examples': examples, 'messages': messages})"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {
104+
"id": "LB2LxPmAB95V"
105+
},
106+
"outputs": [],
107+
"source": [
108+
"# Call the model and print the response.\n",
109+
"response = palm.chat(\n",
110+
" **defaults,\n",
111+
" context=context,\n",
112+
" examples=examples,\n",
113+
" messages=messages\n",
114+
")\n",
115+
"print(response.candidates[0]['content'])"
116+
]
117+
}
118+
],
119+
"metadata": {
120+
"colab": {
121+
"name": "aistudio_palm_prompt_chat.ipynb",
122+
"toc_visible": true
123+
},
124+
"kernelspec": {
125+
"display_name": "Python 3",
126+
"name": "python3"
127+
}
128+
},
129+
"nbformat": 4,
130+
"nbformat_minor": 0
131+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "Tce3stUlHN0L"
7+
},
8+
"source": [
9+
"##### Copyright 2023 Google LLC"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {
16+
"cellView": "form",
17+
"id": "tuOe1ymfHZPu"
18+
},
19+
"outputs": [],
20+
"source": [
21+
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
22+
"# you may not use this file except in compliance with the License.\n",
23+
"# You may obtain a copy of the License at\n",
24+
"#\n",
25+
"# https://www.apache.org/licenses/LICENSE-2.0\n",
26+
"#\n",
27+
"# Unless required by applicable law or agreed to in writing, software\n",
28+
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
29+
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
30+
"# See the License for the specific language governing permissions and\n",
31+
"# limitations under the License."
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"metadata": {
38+
"id": "kWIuwKG2_oWE"
39+
},
40+
"outputs": [],
41+
"source": [
42+
"# Install the client library and import necessary modules.\n",
43+
"!pip install google-generativeai\n",
44+
"import google.generativeai as palm\n",
45+
"import base64\n",
46+
"import json\n",
47+
"import pprint"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {
54+
"id": "_SvYoR3WCeKr"
55+
},
56+
"outputs": [],
57+
"source": [
58+
"# Configure the client library by providing your API key.\n",
59+
"palm.configure(api_key=\"YOUR API KEY\")"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {
66+
"id": "Pwab0i0RAHBN"
67+
},
68+
"outputs": [],
69+
"source": [
70+
"# These parameters for the model call can be set by URL parameters.\n",
71+
"model = \"\" # @param {isTemplate: true}\n",
72+
"temperature = 0.7 # @param {isTemplate: true}\n",
73+
"candidate_count = 1 # @param {isTemplate: true}\n",
74+
"top_k = 40 # @param {isTemplate: true}\n",
75+
"top_p = 0.95 # @param {isTemplate: true}\n",
76+
"max_output_tokens = 1024 # @param {isTemplate: true}\n",
77+
"text_b64 = \"\" # @param {isTemplate: true}\n",
78+
"stop_sequences_b64 = \"\" # @param {isTemplate: true}\n",
79+
"safety_settings_b64 = \"\" # @param {isTemplate: true}\n",
80+
"\n",
81+
"# Convert the prompt text param from a bae64 string to a string.\n",
82+
"text = base64.b64decode(text_b64).decode(\"utf-8\")\n",
83+
"\n",
84+
"# Convert the stop_sequences and safety_settings params from base64 strings to lists.\n",
85+
"stop_sequences = json.loads(base64.b64decode(stop_sequences_b64).decode(\"utf-8\"))\n",
86+
"safety_settings = json.loads(base64.b64decode(safety_settings_b64).decode(\"utf-8\"))\n",
87+
"\n",
88+
"defaults = {\n",
89+
" 'model': model,\n",
90+
" 'temperature': temperature,\n",
91+
" 'candidate_count': candidate_count,\n",
92+
" 'top_k': top_k,\n",
93+
" 'top_p': top_p,\n",
94+
" 'max_output_tokens': max_output_tokens,\n",
95+
" 'stop_sequences': stop_sequences,\n",
96+
" 'safety_settings': safety_settings,\n",
97+
"}\n",
98+
"\n",
99+
"# Show what will be sent with the API call.\n",
100+
"pprint.pprint(defaults | {'prompt': text})"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"metadata": {
107+
"id": "LB2LxPmAB95V"
108+
},
109+
"outputs": [],
110+
"source": [
111+
"# Call the model and print the response.\n",
112+
"response = palm.generate_text(\n",
113+
" **defaults,\n",
114+
" prompt=text\n",
115+
")\n",
116+
"print(response.candidates[0]['output'])"
117+
]
118+
}
119+
],
120+
"metadata": {
121+
"colab": {
122+
"name": "aistudio_palm_prompt_text.ipynb",
123+
"toc_visible": true
124+
},
125+
"kernelspec": {
126+
"display_name": "Python 3",
127+
"name": "python3"
128+
}
129+
},
130+
"nbformat": 4,
131+
"nbformat_minor": 0
132+
}

0 commit comments

Comments
 (0)