Skip to content

Commit 8618cd3

Browse files
authored
Python: Bump Python Package version for release. Update notebook refs to use AIRequestSettings. (microsoft#4478)
### Motivation and Context Bump Python Package version for release. Update notebook refs and request settings to use the new AIRequestSettings classes. Fix hugging face bug that requires generator input as text_inputs instead of prompt. Add a hugging face request settings unit test. <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description Bump Python Package version for release. Update notebook refs to point to new package version. <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]>
1 parent 756937f commit 8618cd3

18 files changed

+1319
-1185
lines changed

python/notebooks/00-getting-started.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"metadata": {},
1717
"outputs": [],
1818
"source": [
19-
"!python -m pip install semantic-kernel==0.4.3.dev0"
19+
"!python -m pip install semantic-kernel==0.4.4.dev0"
2020
]
2121
},
2222
{
@@ -57,7 +57,7 @@
5757
"\n",
5858
"api_key, org_id = sk.openai_settings_from_dot_env()\n",
5959
"\n",
60-
"kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id))"
60+
"kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo-1106\", api_key=api_key, org_id=org_id))"
6161
]
6262
},
6363
{

python/notebooks/01-basic-loading-the-kernel.ipynb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
28-
"!python -m pip install semantic-kernel==0.4.3.dev0"
28+
"!python -m pip install semantic-kernel==0.4.4.dev0"
2929
]
3030
},
3131
{
3232
"cell_type": "code",
33-
"execution_count": null,
33+
"execution_count": 1,
3434
"metadata": {},
3535
"outputs": [],
3636
"source": [
3737
"import semantic_kernel as sk\n",
38-
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion"
38+
"from semantic_kernel.connectors.ai.open_ai import (\n",
39+
" AzureChatCompletion,\n",
40+
" OpenAIChatCompletion,\n",
41+
")"
3942
]
4043
},
4144
{
@@ -48,7 +51,7 @@
4851
},
4952
{
5053
"cell_type": "code",
51-
"execution_count": null,
54+
"execution_count": 2,
5255
"metadata": {},
5356
"outputs": [],
5457
"source": [
@@ -85,13 +88,13 @@
8588
" )\n",
8689
")\n",
8790
"\n",
88-
"kernel.add_chat_service( # We are adding a text service\n",
89-
" \"OpenAI_chat_gpt\", # The alias we can use in prompt templates' config.json\n",
91+
"kernel.add_chat_service( # We are adding a text service\n",
92+
" \"OpenAI_chat_gpt\", # The alias we can use in prompt templates' config.json\n",
9093
" OpenAIChatCompletion(\n",
91-
" ai_model_id=\"gpt-3.5-turbo\", # OpenAI Model Name\n",
92-
" api_key=\"...your OpenAI API Key...\", # OpenAI API key\n",
93-
" org_id=\"...your OpenAI Org ID...\" # *optional* OpenAI Organization ID\n",
94-
" )\n",
94+
" ai_model_id=\"gpt-3.5-turbo\", # OpenAI Model Name\n",
95+
" api_key=\"...your OpenAI API Key...\", # OpenAI API key\n",
96+
" org_id=\"...your OpenAI Org ID...\", # *optional* OpenAI Organization ID\n",
97+
" ),\n",
9598
")"
9699
]
97100
},
@@ -143,7 +146,7 @@
143146
"name": "python",
144147
"nbconvert_exporter": "python",
145148
"pygments_lexer": "ipython3",
146-
"version": "3.11.6"
149+
"version": "3.10.12"
147150
},
148151
"polyglot_notebook": {
149152
"kernelInfo": {

python/notebooks/02-running-prompts-from-file.ipynb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"metadata": {},
9090
"outputs": [],
9191
"source": [
92-
"!python -m pip install semantic-kernel==0.4.3.dev0"
92+
"!python -m pip install semantic-kernel==0.4.4.dev0"
9393
]
9494
},
9595
{
@@ -100,7 +100,10 @@
100100
"outputs": [],
101101
"source": [
102102
"import semantic_kernel as sk\n",
103-
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
103+
"from semantic_kernel.connectors.ai.open_ai import (\n",
104+
" AzureChatCompletion,\n",
105+
" OpenAIChatCompletion,\n",
106+
")\n",
104107
"\n",
105108
"kernel = sk.Kernel()\n",
106109
"\n",
@@ -109,7 +112,9 @@
109112
"# Configure AI service used by the kernel\n",
110113
"if useAzureOpenAI:\n",
111114
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
112-
" azure_chat_service = AzureChatCompletion(deployment_name=\"turbo\", endpoint=endpoint, api_key=api_key) # set the deployment name to the value of your chat model\n",
115+
" azure_chat_service = AzureChatCompletion(\n",
116+
" deployment_name=\"turbo\", endpoint=endpoint, api_key=api_key\n",
117+
" ) # set the deployment name to the value of your chat model\n",
113118
" kernel.add_chat_service(\"chat_completion\", azure_chat_service)\n",
114119
"else:\n",
115120
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
@@ -192,7 +197,7 @@
192197
"name": "python",
193198
"nbconvert_exporter": "python",
194199
"pygments_lexer": "ipython3",
195-
"version": "3.11.6"
200+
"version": "3.10.12"
196201
}
197202
},
198203
"nbformat": 4,

python/notebooks/03-semantic-function-inline.ipynb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"metadata": {},
5656
"outputs": [],
5757
"source": [
58-
"!python -m pip install semantic-kernel==0.4.3.dev0"
58+
"!python -m pip install semantic-kernel==0.4.4.dev0"
5959
]
6060
},
6161
{
@@ -66,7 +66,10 @@
6666
"outputs": [],
6767
"source": [
6868
"import semantic_kernel as sk\n",
69-
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
69+
"from semantic_kernel.connectors.ai.open_ai import (\n",
70+
" AzureTextCompletion,\n",
71+
" OpenAITextCompletion,\n",
72+
")\n",
7073
"\n",
7174
"kernel = sk.Kernel()\n",
7275
"\n",
@@ -75,7 +78,9 @@
7578
"# Configure AI service used by the kernel\n",
7679
"if useAzureOpenAI:\n",
7780
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
78-
" azure_text_service = AzureTextCompletion(deployment_name=\"text\", endpoint=endpoint, api_key=api_key) # set the deployment name to the value of your text model\n",
81+
" azure_text_service = AzureTextCompletion(\n",
82+
" deployment_name=\"text\", endpoint=endpoint, api_key=api_key\n",
83+
" ) # set the deployment name to the value of your text model\n",
7984
" kernel.add_text_completion_service(\"dv\", azure_text_service)\n",
8085
"else:\n",
8186
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
@@ -196,7 +201,10 @@
196201
"outputs": [],
197202
"source": [
198203
"import semantic_kernel as sk\n",
199-
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
204+
"from semantic_kernel.connectors.ai.open_ai import (\n",
205+
" AzureChatCompletion,\n",
206+
" OpenAIChatCompletion,\n",
207+
")\n",
200208
"\n",
201209
"kernel = sk.Kernel()\n",
202210
"\n",
@@ -205,7 +213,9 @@
205213
"# Configure AI service used by the kernel\n",
206214
"if useAzureOpenAI:\n",
207215
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
208-
" azure_chat_service = AzureChatCompletion(deployment_name=\"turbo\", endpoint=endpoint, api_key=api_key) # set the deployment name to the value of your chat model\n",
216+
" azure_chat_service = AzureChatCompletion(\n",
217+
" deployment_name=\"turbo\", endpoint=endpoint, api_key=api_key\n",
218+
" ) # set the deployment name to the value of your chat model\n",
209219
" kernel.add_chat_service(\"chat_completion\", azure_chat_service)\n",
210220
"else:\n",
211221
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
@@ -241,7 +251,7 @@
241251
"\n",
242252
"summary = tldr_function(text)\n",
243253
"\n",
244-
"print(f\"Output: {summary}\") # Output: Robots must not harm humans."
254+
"print(f\"Output: {summary}\") # Output: Robots must not harm humans."
245255
]
246256
}
247257
],

python/notebooks/04-context-variables-chat.ipynb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"metadata": {},
2727
"outputs": [],
2828
"source": [
29-
"!python -m pip install semantic-kernel==0.4.3.dev0"
29+
"!python -m pip install semantic-kernel==0.4.4.dev0"
3030
]
3131
},
3232
{
@@ -37,7 +37,10 @@
3737
"outputs": [],
3838
"source": [
3939
"import semantic_kernel as sk\n",
40-
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
40+
"from semantic_kernel.connectors.ai.open_ai import (\n",
41+
" AzureChatCompletion,\n",
42+
" OpenAIChatCompletion,\n",
43+
")\n",
4144
"\n",
4245
"kernel = sk.Kernel()\n",
4346
"\n",
@@ -46,10 +49,16 @@
4649
"# Configure AI service used by the kernel\n",
4750
"if useAzureOpenAI:\n",
4851
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
49-
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))\n",
52+
" kernel.add_chat_service(\n",
53+
" \"chat_completion\",\n",
54+
" AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key),\n",
55+
" )\n",
5056
"else:\n",
5157
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
52-
" kernel.add_chat_service(\"gpt-3.5\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id))\n"
58+
" kernel.add_chat_service(\n",
59+
" \"gpt-3.5\",\n",
60+
" OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id),\n",
61+
" )"
5362
]
5463
},
5564
{
@@ -98,7 +107,8 @@
98107
" function_name=\"ChatBot\",\n",
99108
" max_tokens=2000,\n",
100109
" temperature=0.7,\n",
101-
" top_p=0.5)"
110+
" top_p=0.5,\n",
111+
")"
102112
]
103113
},
104114
{

python/notebooks/05-using-the-planner.ipynb

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"metadata": {},
2424
"outputs": [],
2525
"source": [
26-
"!python -m pip install semantic-kernel==0.4.3.dev0"
26+
"!python -m pip install semantic-kernel==0.4.4.dev0"
2727
]
2828
},
2929
{
@@ -34,7 +34,10 @@
3434
"outputs": [],
3535
"source": [
3636
"import semantic_kernel as sk\n",
37-
"from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion\n",
37+
"from semantic_kernel.connectors.ai.open_ai import (\n",
38+
" OpenAIChatCompletion,\n",
39+
" AzureChatCompletion,\n",
40+
")\n",
3841
"\n",
3942
"kernel = sk.Kernel()\n",
4043
"\n",
@@ -43,10 +46,16 @@
4346
"# Configure AI backend used by the kernel\n",
4447
"if useAzureOpenAI:\n",
4548
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
46-
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))\n",
49+
" kernel.add_chat_service(\n",
50+
" \"chat_completion\",\n",
51+
" AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key),\n",
52+
" )\n",
4753
"else:\n",
4854
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
49-
" kernel.add_chat_service(\"gpt-3.5\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id))"
55+
" kernel.add_chat_service(\n",
56+
" \"gpt-3.5\",\n",
57+
" OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id),\n",
58+
" )"
5059
]
5160
},
5261
{
@@ -127,6 +136,7 @@
127136
"outputs": [],
128137
"source": [
129138
"from semantic_kernel.planning.basic_planner import BasicPlanner\n",
139+
"\n",
130140
"planner = BasicPlanner()"
131141
]
132142
},
@@ -185,7 +195,8 @@
185195
" function_name=\"shakespeare\",\n",
186196
" skill_name=\"ShakespeareSkill\",\n",
187197
" max_tokens=2000,\n",
188-
" temperature=0.8)"
198+
" temperature=0.8,\n",
199+
")"
189200
]
190201
},
191202
{
@@ -299,6 +310,7 @@
299310
"outputs": [],
300311
"source": [
301312
"from semantic_kernel.planning import SequentialPlanner\n",
313+
"\n",
302314
"planner = SequentialPlanner(kernel)"
303315
]
304316
},
@@ -383,6 +395,7 @@
383395
"outputs": [],
384396
"source": [
385397
"from semantic_kernel.planning import ActionPlanner\n",
398+
"\n",
386399
"planner = ActionPlanner(kernel)"
387400
]
388401
},
@@ -402,6 +415,7 @@
402415
"outputs": [],
403416
"source": [
404417
"from semantic_kernel.core_skills import FileIOSkill, MathSkill, TextSkill, TimeSkill\n",
418+
"\n",
405419
"kernel.import_skill(MathSkill(), \"math\")\n",
406420
"kernel.import_skill(FileIOSkill(), \"fileIO\")\n",
407421
"kernel.import_skill(TimeSkill(), \"time\")\n",
@@ -502,15 +516,17 @@
502516
" \"\"\"\n",
503517
" A search engine skill.\n",
504518
" \"\"\"\n",
519+
"\n",
505520
" from semantic_kernel.orchestration.sk_context import SKContext\n",
506-
" from semantic_kernel.skill_definition import sk_function, sk_function_context_parameter\n",
521+
" from semantic_kernel.skill_definition import (\n",
522+
" sk_function,\n",
523+
" sk_function_context_parameter,\n",
524+
" )\n",
507525
"\n",
508526
" def __init__(self, connector) -> None:\n",
509527
" self._connector = connector\n",
510528
"\n",
511-
" @sk_function(\n",
512-
" description=\"Performs a web search for a given query\", name=\"searchAsync\"\n",
513-
" )\n",
529+
" @sk_function(description=\"Performs a web search for a given query\", name=\"searchAsync\")\n",
514530
" @sk_function_context_parameter(\n",
515531
" name=\"query\",\n",
516532
" description=\"The search query\",\n",
@@ -564,9 +580,7 @@
564580
"metadata": {},
565581
"outputs": [],
566582
"source": [
567-
"planner = StepwisePlanner(\n",
568-
" kernel, StepwisePlannerConfig(max_iterations=10, min_iteration_time_ms=1000)\n",
569-
")"
583+
"planner = StepwisePlanner(kernel, StepwisePlannerConfig(max_iterations=10, min_iteration_time_ms=1000))"
570584
]
571585
},
572586
{
@@ -626,10 +640,10 @@
626640
"source": [
627641
"for index, step in enumerate(plan._steps):\n",
628642
" print(\"Step:\", index)\n",
629-
" print(\"Description:\",step.description)\n",
643+
" print(\"Description:\", step.description)\n",
630644
" print(\"Function:\", step.skill_name + \".\" + step._function.name)\n",
631645
" if len(step._outputs) > 0:\n",
632-
" print( \" Output:\\n\", str.replace(result[step._outputs[0]],\"\\n\", \"\\n \"))"
646+
" print(\" Output:\\n\", str.replace(result[step._outputs[0]], \"\\n\", \"\\n \"))"
633647
]
634648
}
635649
],
@@ -649,7 +663,7 @@
649663
"name": "python",
650664
"nbconvert_exporter": "python",
651665
"pygments_lexer": "ipython3",
652-
"version": "3.11.6"
666+
"version": "3.10.12"
653667
}
654668
},
655669
"nbformat": 4,

0 commit comments

Comments
 (0)