Skip to content

Commit

Permalink
Python: Bump Python Package version for release. Update notebook refs…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
moonbox3 and moonbox3 authored Jan 5, 2024
1 parent 756937f commit 8618cd3
Show file tree
Hide file tree
Showing 18 changed files with 1,319 additions and 1,185 deletions.
4 changes: 2 additions & 2 deletions python/notebooks/00-getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install semantic-kernel==0.4.3.dev0"
"!python -m pip install semantic-kernel==0.4.4.dev0"
]
},
{
Expand Down Expand Up @@ -57,7 +57,7 @@
"\n",
"api_key, org_id = sk.openai_settings_from_dot_env()\n",
"\n",
"kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id))"
"kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo-1106\", api_key=api_key, org_id=org_id))"
]
},
{
Expand Down
25 changes: 14 additions & 11 deletions python/notebooks/01-basic-loading-the-kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install semantic-kernel==0.4.3.dev0"
"!python -m pip install semantic-kernel==0.4.4.dev0"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion"
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" OpenAIChatCompletion,\n",
")"
]
},
{
Expand All @@ -48,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -85,13 +88,13 @@
" )\n",
")\n",
"\n",
"kernel.add_chat_service( # We are adding a text service\n",
" \"OpenAI_chat_gpt\", # The alias we can use in prompt templates' config.json\n",
"kernel.add_chat_service( # We are adding a text service\n",
" \"OpenAI_chat_gpt\", # The alias we can use in prompt templates' config.json\n",
" OpenAIChatCompletion(\n",
" ai_model_id=\"gpt-3.5-turbo\", # OpenAI Model Name\n",
" api_key=\"...your OpenAI API Key...\", # OpenAI API key\n",
" org_id=\"...your OpenAI Org ID...\" # *optional* OpenAI Organization ID\n",
" )\n",
" ai_model_id=\"gpt-3.5-turbo\", # OpenAI Model Name\n",
" api_key=\"...your OpenAI API Key...\", # OpenAI API key\n",
" org_id=\"...your OpenAI Org ID...\", # *optional* OpenAI Organization ID\n",
" ),\n",
")"
]
},
Expand Down Expand Up @@ -143,7 +146,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.12"
},
"polyglot_notebook": {
"kernelInfo": {
Expand Down
13 changes: 9 additions & 4 deletions python/notebooks/02-running-prompts-from-file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install semantic-kernel==0.4.3.dev0"
"!python -m pip install semantic-kernel==0.4.4.dev0"
]
},
{
Expand All @@ -100,7 +100,10 @@
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" OpenAIChatCompletion,\n",
")\n",
"\n",
"kernel = sk.Kernel()\n",
"\n",
Expand All @@ -109,7 +112,9 @@
"# Configure AI service used by the kernel\n",
"if useAzureOpenAI:\n",
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
" 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",
" azure_chat_service = AzureChatCompletion(\n",
" deployment_name=\"turbo\", endpoint=endpoint, api_key=api_key\n",
" ) # set the deployment name to the value of your chat model\n",
" kernel.add_chat_service(\"chat_completion\", azure_chat_service)\n",
"else:\n",
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
Expand Down Expand Up @@ -192,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
22 changes: 16 additions & 6 deletions python/notebooks/03-semantic-function-inline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install semantic-kernel==0.4.3.dev0"
"!python -m pip install semantic-kernel==0.4.4.dev0"
]
},
{
Expand All @@ -66,7 +66,10 @@
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureTextCompletion,\n",
" OpenAITextCompletion,\n",
")\n",
"\n",
"kernel = sk.Kernel()\n",
"\n",
Expand All @@ -75,7 +78,9 @@
"# Configure AI service used by the kernel\n",
"if useAzureOpenAI:\n",
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
" 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",
" azure_text_service = AzureTextCompletion(\n",
" deployment_name=\"text\", endpoint=endpoint, api_key=api_key\n",
" ) # set the deployment name to the value of your text model\n",
" kernel.add_text_completion_service(\"dv\", azure_text_service)\n",
"else:\n",
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
Expand Down Expand Up @@ -196,7 +201,10 @@
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" OpenAIChatCompletion,\n",
")\n",
"\n",
"kernel = sk.Kernel()\n",
"\n",
Expand All @@ -205,7 +213,9 @@
"# Configure AI service used by the kernel\n",
"if useAzureOpenAI:\n",
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
" 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",
" azure_chat_service = AzureChatCompletion(\n",
" deployment_name=\"turbo\", endpoint=endpoint, api_key=api_key\n",
" ) # set the deployment name to the value of your chat model\n",
" kernel.add_chat_service(\"chat_completion\", azure_chat_service)\n",
"else:\n",
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
Expand Down Expand Up @@ -241,7 +251,7 @@
"\n",
"summary = tldr_function(text)\n",
"\n",
"print(f\"Output: {summary}\") # Output: Robots must not harm humans."
"print(f\"Output: {summary}\") # Output: Robots must not harm humans."
]
}
],
Expand Down
20 changes: 15 additions & 5 deletions python/notebooks/04-context-variables-chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install semantic-kernel==0.4.3.dev0"
"!python -m pip install semantic-kernel==0.4.4.dev0"
]
},
{
Expand All @@ -37,7 +37,10 @@
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, OpenAIChatCompletion\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" AzureChatCompletion,\n",
" OpenAIChatCompletion,\n",
")\n",
"\n",
"kernel = sk.Kernel()\n",
"\n",
Expand All @@ -46,10 +49,16 @@
"# Configure AI service used by the kernel\n",
"if useAzureOpenAI:\n",
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))\n",
" kernel.add_chat_service(\n",
" \"chat_completion\",\n",
" AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key),\n",
" )\n",
"else:\n",
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
" kernel.add_chat_service(\"gpt-3.5\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id))\n"
" kernel.add_chat_service(\n",
" \"gpt-3.5\",\n",
" OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id),\n",
" )"
]
},
{
Expand Down Expand Up @@ -98,7 +107,8 @@
" function_name=\"ChatBot\",\n",
" max_tokens=2000,\n",
" temperature=0.7,\n",
" top_p=0.5)"
" top_p=0.5,\n",
")"
]
},
{
Expand Down
44 changes: 29 additions & 15 deletions python/notebooks/05-using-the-planner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python -m pip install semantic-kernel==0.4.3.dev0"
"!python -m pip install semantic-kernel==0.4.4.dev0"
]
},
{
Expand All @@ -34,7 +34,10 @@
"outputs": [],
"source": [
"import semantic_kernel as sk\n",
"from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion, AzureChatCompletion\n",
"from semantic_kernel.connectors.ai.open_ai import (\n",
" OpenAIChatCompletion,\n",
" AzureChatCompletion,\n",
")\n",
"\n",
"kernel = sk.Kernel()\n",
"\n",
Expand All @@ -43,10 +46,16 @@
"# Configure AI backend used by the kernel\n",
"if useAzureOpenAI:\n",
" deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
" kernel.add_chat_service(\"chat_completion\", AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key))\n",
" kernel.add_chat_service(\n",
" \"chat_completion\",\n",
" AzureChatCompletion(deployment_name=deployment, endpoint=endpoint, api_key=api_key),\n",
" )\n",
"else:\n",
" api_key, org_id = sk.openai_settings_from_dot_env()\n",
" kernel.add_chat_service(\"gpt-3.5\", OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id))"
" kernel.add_chat_service(\n",
" \"gpt-3.5\",\n",
" OpenAIChatCompletion(ai_model_id=\"gpt-3.5-turbo\", api_key=api_key, org_id=org_id),\n",
" )"
]
},
{
Expand Down Expand Up @@ -127,6 +136,7 @@
"outputs": [],
"source": [
"from semantic_kernel.planning.basic_planner import BasicPlanner\n",
"\n",
"planner = BasicPlanner()"
]
},
Expand Down Expand Up @@ -185,7 +195,8 @@
" function_name=\"shakespeare\",\n",
" skill_name=\"ShakespeareSkill\",\n",
" max_tokens=2000,\n",
" temperature=0.8)"
" temperature=0.8,\n",
")"
]
},
{
Expand Down Expand Up @@ -299,6 +310,7 @@
"outputs": [],
"source": [
"from semantic_kernel.planning import SequentialPlanner\n",
"\n",
"planner = SequentialPlanner(kernel)"
]
},
Expand Down Expand Up @@ -383,6 +395,7 @@
"outputs": [],
"source": [
"from semantic_kernel.planning import ActionPlanner\n",
"\n",
"planner = ActionPlanner(kernel)"
]
},
Expand All @@ -402,6 +415,7 @@
"outputs": [],
"source": [
"from semantic_kernel.core_skills import FileIOSkill, MathSkill, TextSkill, TimeSkill\n",
"\n",
"kernel.import_skill(MathSkill(), \"math\")\n",
"kernel.import_skill(FileIOSkill(), \"fileIO\")\n",
"kernel.import_skill(TimeSkill(), \"time\")\n",
Expand Down Expand Up @@ -502,15 +516,17 @@
" \"\"\"\n",
" A search engine skill.\n",
" \"\"\"\n",
"\n",
" from semantic_kernel.orchestration.sk_context import SKContext\n",
" from semantic_kernel.skill_definition import sk_function, sk_function_context_parameter\n",
" from semantic_kernel.skill_definition import (\n",
" sk_function,\n",
" sk_function_context_parameter,\n",
" )\n",
"\n",
" def __init__(self, connector) -> None:\n",
" self._connector = connector\n",
"\n",
" @sk_function(\n",
" description=\"Performs a web search for a given query\", name=\"searchAsync\"\n",
" )\n",
" @sk_function(description=\"Performs a web search for a given query\", name=\"searchAsync\")\n",
" @sk_function_context_parameter(\n",
" name=\"query\",\n",
" description=\"The search query\",\n",
Expand Down Expand Up @@ -564,9 +580,7 @@
"metadata": {},
"outputs": [],
"source": [
"planner = StepwisePlanner(\n",
" kernel, StepwisePlannerConfig(max_iterations=10, min_iteration_time_ms=1000)\n",
")"
"planner = StepwisePlanner(kernel, StepwisePlannerConfig(max_iterations=10, min_iteration_time_ms=1000))"
]
},
{
Expand Down Expand Up @@ -626,10 +640,10 @@
"source": [
"for index, step in enumerate(plan._steps):\n",
" print(\"Step:\", index)\n",
" print(\"Description:\",step.description)\n",
" print(\"Description:\", step.description)\n",
" print(\"Function:\", step.skill_name + \".\" + step._function.name)\n",
" if len(step._outputs) > 0:\n",
" print( \" Output:\\n\", str.replace(result[step._outputs[0]],\"\\n\", \"\\n \"))"
" print(\" Output:\\n\", str.replace(result[step._outputs[0]], \"\\n\", \"\\n \"))"
]
}
],
Expand All @@ -649,7 +663,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 8618cd3

Please sign in to comment.