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

Add Python Equivalents for Bing & Google Search Plugins in Semantic Kernel #229

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

shethaadit
Copy link

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:

  • BingTextSearch Plugin with Bing Search API
  • GoogleTextSearch Plugin with Google Custom Search Engine

Key Changes:

  • Implemented BingTextSearch and GoogleTextSearch plugins in Python
  • Integrated with OpenAI’s gpt-4o for context-aware responses
  • Ensured parity with the C# implementation
  • Used KernelArguments for dynamic query handling

This enhancement broadens Semantic Kernel’s usability, allowing Python developers to build AI-powered applications with real-time web search capabilities.

Copy link
Contributor

Learn Build status updates of commit 6738f71:

✅ Validation status: passed

File Status Preview URL Details
semantic-kernel/concepts/text-search/index.md ✅Succeeded

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit 8d39f17:

✅ Validation status: passed

File Status Preview URL Details
semantic-kernel/concepts/text-search/index.md ✅Succeeded

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit 19cf1f2:

✅ Validation status: passed

File Status Preview URL Details
semantic-kernel/concepts/text-search/index.md ✅Succeeded

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit de14297:

✅ Validation status: passed

File Status Preview URL Details
semantic-kernel/concepts/text-search/index.md ✅Succeeded

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

@eavanvalkenburg eavanvalkenburg left a 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!

Copy link
Contributor

Learn Build status updates of commit 898718d:

✅ Validation status: passed

File Status Preview URL Details
semantic-kernel/concepts/text-search/index.md ✅Succeeded

For more details, please refer to the build report.

For any questions, please:

@shethaadit
Copy link
Author

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 search

from 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants