Skip to content

feat: adding support for Azure OpenAI for Semantic Kernel - commands are commented #505

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions samples/python/agents/semantickernel/.envexample
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## OpenAI configurations - uncomment if using OpenAI
# OPENAI_API_KEY="<example>"
# OPENAI_CHAT_MODEL_ID="gpt-4.1"
#
#
## Azure OpenAI configuration - uncomment if using Azure OpenAI
# AZURE_OPENAI_ENDPOINT=""
# AZURE_OPENAI_API_KEY=""
# AZURE_OPENAI_API_VERSION=""
20 changes: 20 additions & 0 deletions samples/python/agents/semantickernel/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread
from semantic_kernel.connectors.ai.open_ai import (
OpenAIChatCompletion,
# AzureChatCompletion, # Comment the line above and uncomment this one for Azure OpenAI Support
OpenAIChatPromptExecutionSettings,
)

from semantic_kernel.contents import (
FunctionCallContent,
FunctionResultContent,
Expand Down Expand Up @@ -97,13 +99,27 @@ def __init__(self):
if not api_key:
raise ValueError('OPENAI_API_KEY environment variable not set.')

## Azure OpenAI credentials - comment all 3 lines above and uncomment these lines for Azure OpenAI support
# api_key = os.getenv('AZURE_OPENAI_API_KEY', None)
# if not api_key:
# raise ValueError('AZURE_OPENAI_API_KEY environment variable not set.')

# endpoint = os.getenv('AZURE_OPENAI_ENDPOINT', None)
# if not endpoint:
# raise ValueError('AZURE_OPENAI_ENDPOINT environment variable not set.')

# deployment_name = os.getenv('AZURE_OPENAI_DEPLOYMENT_NAME', None)
# if not deployment_name:
# raise ValueError('AZURE_OPENAI_DEPLOYMENT_NAME environment variable not set.')

model_id = os.getenv('OPENAI_CHAT_MODEL_ID', 'gpt-4.1')

# Define a CurrencyExchangeAgent to handle currency-related tasks
currency_exchange_agent = ChatCompletionAgent(
service=OpenAIChatCompletion(
api_key=api_key,
ai_model_id=model_id,
# endpoint=endpoint, # comment the line above and uncomment this lines for Azure OpenAI support
),
name='CurrencyExchangeAgent',
instructions=(
Expand All @@ -118,8 +134,10 @@ def __init__(self):
# Define an ActivityPlannerAgent to handle activity-related tasks
activity_planner_agent = ChatCompletionAgent(
service=OpenAIChatCompletion(
# service=AzureChatCompletion( # comment the line above and uncomment this lines for Azure OpenAI support
api_key=api_key,
ai_model_id=model_id,
# endpoint=endpoint, # comment the line above and uncomment this lines for Azure OpenAI support
),
name='ActivityPlannerAgent',
instructions=(
Expand All @@ -134,8 +152,10 @@ def __init__(self):
# Define the main TravelManagerAgent to delegate tasks to the appropriate agents
self.agent = ChatCompletionAgent(
service=OpenAIChatCompletion(
# service=AzureChatCompletion( # comment the line above and uncomment this lines for Azure OpenAI support
api_key=api_key,
ai_model_id=model_id,
# endpoint=endpoint, # comment the line above and uncomment this lines for Azure OpenAI support
),
name='TravelManagerAgent',
instructions=(
Expand Down