Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/notebook bing search #1729

Merged
merged 20 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5b1f9a8
Updated the SK nuget package to latest version in the notebook sample…
Jun 22, 2023
5c2ac76
Merge branch 'main' of https://github.com/N-E-W-T-O-N/semantic-kernel…
Jun 23, 2023
cf3ac2f
Added bing seach notebook
Jun 26, 2023
99bdf21
Merge branch 'main' of https://github.com/N-E-W-T-O-N/semantic-kernel…
Jun 26, 2023
31170e6
Merge branch 'microsoft:main' into feature/notebook_bing_search
N-E-W-T-O-N Jun 27, 2023
5423e5f
Update sk package to 0.17.230626.1-preview
Jun 29, 2023
a53a81d
Updated SK packages in notebook sample
Jun 29, 2023
0b5e80b
Merge branch 'feature/notebook_bing_search' of https://github.com/N-E…
Jun 29, 2023
f33502b
Minnor tweaks in 09-BingSearch-using-kernel.ipynb
N-E-W-T-O-N Jun 29, 2023
02df6ff
Merge branch 'microsoft:main' into feature/notebook_bing_search
N-E-W-T-O-N Jun 29, 2023
87bc66e
Merge branch 'main' of https://github.com/N-E-W-T-O-N/semantic-kernel…
Jul 3, 2023
d303c8c
Updated BingSearch notebook with minor tweaks
Jul 3, 2023
6109a32
Merge branch 'main' into feature/notebook_bing_search
gitri-ms Jul 3, 2023
6d7cd1f
Merge branch 'main' into feature/notebook_bing_search
gitri-ms Jul 3, 2023
deb3ef4
Merge branch 'microsoft:main' into feature/notebook_bing_search
N-E-W-T-O-N Jul 4, 2023
205e3d5
Updated 10-BingSearch-using-kernel @gitri-ms
N-E-W-T-O-N Jul 4, 2023
e34c957
Minor Fix
N-E-W-T-O-N Jul 4, 2023
f1f4258
Merge branch 'main' into feature/notebook_bing_search
gitri-ms Jul 5, 2023
fee97c4
Fixes in other notebooks from upgrade; cleanup formatting and spelling
gitri-ms Jul 5, 2023
f374332
Merge branch 'main' into feature/notebook_bing_search
gitri-ms Jul 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,5 @@ playwright-report/

# Static Web App deployment config
swa-cli.config.json
**/copilot-chat-app/webapp/build
**/copilot-chat-app/webapp/build
**/copilot-chat-app/webapp/node_modules
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/00-getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"outputs": [],
"source": [
"// Import Semantic Kernel\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\""
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/01-basic-loading-the-kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\""
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\""
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand Down
11 changes: 10 additions & 1 deletion samples/notebooks/dotnet/03-semantic-function-inline.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -30,6 +31,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -49,7 +51,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand All @@ -69,6 +71,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -96,6 +99,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -127,6 +131,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -155,6 +160,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -180,6 +186,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -213,6 +220,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -273,6 +281,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down
3 changes: 1 addition & 2 deletions samples/notebooks/dotnet/04-context-variables-chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#!import config/Settings.cs\n",
"\n",
"using Microsoft.SemanticKernel;\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/05-using-the-planner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"#!import config/Utils.cs\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/06-memory-and-embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/07-DALL-E-2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"source": [
"// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n",
"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: SkiaSharp, 2.88.3\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down
3 changes: 2 additions & 1 deletion samples/notebooks/dotnet/08-chatGPT-with-DALL-E-2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -55,7 +56,7 @@
"source": [
"// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n",
"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.15.230531.5-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: SkiaSharp, 2.88.3\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down
224 changes: 224 additions & 0 deletions samples/notebooks/dotnet/09-BingSearch-using-kernel.ipynb
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# BingSearch using Kernel \n",
"\n",
"This notebook explains how to integrate Bing Search with the Semantic Kernel to get the latest information from the internet.\n",
"\n",
"To use Bing Search you simply need a Bing Search API key. You can get the API key by creating a [Bing Search resource](https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/create-bing-search-service-resource) in Azure. \n",
"\n",
"To learn more read the following [documenation](https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/overview)\n"
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Prepare a semantic kernel instance first, loading also the AI backend settings defined in the [Setup notebook](0-AI-settings.ipynb):"
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Skills.Web, 0.17.230626.1-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"#!import config/Utils.cs\n",
"\n",
"using Microsoft.SemanticKernel;\n",
"using Microsoft.SemanticKernel.Skills.Core;\n",
"using Microsoft.SemanticKernel.SkillDefinition;\n",
"using Microsoft.SemanticKernel.Orchestration;\n",
"using Microsoft.SemanticKernel.Planning;\n",
"using Microsoft.SemanticKernel.Planning.Sequential;\n",
"using Microsoft.SemanticKernel.TemplateEngine;\n",
"var builder = new KernelBuilder();\n",
"\n",
"// Configure AI backend used by the kernel\n",
"var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();\n",
"\n",
"if (useAzureOpenAI)\n",
" builder.WithAzureTextCompletionService(model, azureEndpoint, apiKey);\n",
"else\n",
" builder.WithOpenAITextCompletionService(model, apiKey, orgId);\n",
"\n",
"var kernel = builder.Build();"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Add the following namespaces to use the Bing Search connector."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"using Microsoft.SemanticKernel.Skills.Web;\n",
"using Microsoft.SemanticKernel.Skills.Web.Bing;"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Below are some examples on how `WebSearchEngineSkill` can be use in SK . Just uncomment the example to use the ."
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Example 1\n",
"What is quantum tunnelling\n",
"----\n",
"In physics, quantum tunnelling, barrier penetration, or simply tunnelling is a quantum mechanical phenomenon in which an object such as an electron or atom passes through a potential energy barrier that, according to classical mechanics, the object does not have sufficient energy to enter or surmount.\n",
"\n",
"Example 2\n",
"[1] Elon Musk (@elonmusk) is the owner of Twitter and is the most-followed person on Twitter, with over 144 million followers. Former U.S. President Barack Obama (@BarackObama) is the second most-followed person on Twitter, with over 132 million followers.\n"
]
}
],
"source": [
"// Load Bing skill\n",
"//Uncomment the Example \n",
"using (var bingConnector = new BingConnector(\"BING_KEY\")\n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
"{\n",
"kernel.ImportSkill(new WebSearchEngineSkill(bingConnector), \"bing\");\n",
"//First run the example sample given below and uncomment the await the following statements \n",
"//await Example1Async(kernel);\n",
"//await Example2Async(kernel);\n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
"}"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"private static async Task Example1Async(IKernel kernel)\n",
"{\n",
" Console.WriteLine(\"Example 1\");\n",
"\n",
" // Run \n",
" var question = \"What is quantum tunnelling\";\n",
" var bingResult = await kernel.Func(\"bing\", \"search\").InvokeAsync(question);\n",
"\n",
" Console.WriteLine(question);\n",
" Console.WriteLine(\"----\");\n",
" Console.WriteLine(bingResult);\n",
" Console.WriteLine();\n",
"\n",
" /* OUTPUT:\n",
"\n",
" What is quantum tunnerling\n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
" ----\n",
" In physics, quantum tunnelling, barrier penetration, or simply tunnelling is a quantum mechanical\n",
" phenomenon in which an object such as an electron or atom passes through a potential energy \n",
" barrier that, according to classical mechanics, the object does not have sufficient energy to\n",
" enter or surmount.\n",
" \n",
" */\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"outputs": [],
"source": [
"private static async Task Example2Async(IKernel kernel)\n",
"{\n",
" Console.WriteLine(\"Example 2\");\n",
" //Use the following function in VS only\n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
" string question = await InteractiveKernel.GetInputAsync(\"Please aSk your question\"); \n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
" //Console.ReadLine();\n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
" var bingResult = await kernel.Func(\"bing\", \"search\").InvokeAsync(question);\n",
"\n",
" Console.WriteLine(bingResult);\n",
N-E-W-T-O-N marked this conversation as resolved.
Show resolved Hide resolved
"}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "polyglot-notebook"
},
"orig_nbformat": 4,
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading