-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add Python Equivalents for Bing & Google Search Plugins in Semantic Kernel #229
base: main
Are you sure you want to change the base?
Add Python Equivalents for Bing & Google Search Plugins in Semantic Kernel #229
Conversation
Learn Build status updates of commit 6738f71: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Co-authored-by: Evan Mattson <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>
Co-authored-by: Evan Mattson <[email protected]>
Learn Build status updates of commit 8d39f17: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Co-authored-by: Evan Mattson <[email protected]>
Learn Build status updates of commit 19cf1f2: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Learn Build status updates of commit de14297: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this, much appreciated! But some cleanup to do!
Learn Build status updates of commit 898718d: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Hi @eavanvalkenburg / @moonbox3, Thank you for the reviews. I have tried to resolve all comments. Here are both codes. Please let me know if they are correct. Bing web search# Create a kernel with OpenAI chat completion
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
from semantic_kernel.connectors.search.bing import BingSearch
from semantic_kernel.functions import KernelArguments, KernelPlugin
# Initialize the Kernel
kernel = Kernel()
# Add OpenAI/Azure OpenAI chat completion service
kernel.add_service(AzureChatCompletion(service_id="chat"))
# Create a Bing Search instance (API key will be picked up from the environment)
bing_search = BingSearch()
# Build a Bing Search plugin and add it to the kernel
search_plugin = KernelPlugin.from_text_search_with_search(
bing_search,
description="Get search results using Bing."
)
# Add plugin to the kernel with a specific plugin name
kernel.add_plugin(search_plugin, plugin_name="bing")
# Define query and prompt
query = "What is Semantic Kernel?"
prompt = "{{bing.search $query}}. {{$query}}"
# Execute search query using the plugin
arguments = KernelArguments(query=query)
result = kernel.invoke_prompt(prompt, arguments)
# Display result
print(result) Google web searchfrom semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
from semantic_kernel.connectors.search.google import GoogleSearch
from semantic_kernel.functions import KernelArguments, KernelPlugin
# Initialize the Kernel
kernel = Kernel()
# Add OpenAI/Azure OpenAI chat completion service
kernel.add_service(AzureChatCompletion(service_id="chat"))
# Create a Google Search instance (API key and Search Engine ID picked from environment)
google_search = GoogleSearch()
# Build a Google Search plugin and add it to the kernel
search_plugin = KernelPlugin.from_text_search_with_search(
google_search,
description="Get details about Semantic Kernel concepts."
)
# Add plugin to the kernel with a specific plugin name
kernel.add_plugin(search_plugin, plugin_name="google")
# Define query and prompt
query = "What is Semantic Kernel?"
prompt = "{{google.search $query}}. {{$query}}"
# Execute search query using the plugin
arguments = KernelArguments(query=query)
result = kernel.invoke_prompt(prompt, arguments)
# Display result
print(result) |
PR Description:
This PR adds Python equivalents for the Bing and Google search integration within the Semantic Kernel. The implementation mirrors the existing C# functionality, enabling Python developers to leverage web search for grounded AI responses using:
Key Changes:
BingTextSearch
andGoogleTextSearch
plugins in Pythongpt-4o
for context-aware responsesKernelArguments
for dynamic query handlingThis enhancement broadens Semantic Kernel’s usability, allowing Python developers to build AI-powered applications with real-time web search capabilities.