Running this code
Example using Semantic Kernel with AzureChatCompletion
import asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, AzureChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
Initialize the kernel
kernel = Kernel()
Configure Azure OpenAI Chat Completion
chat_completion_service = AzureChatCompletion(
endpoint="https://-resource.openai.azure.com/",
api_key="mykey",
deployment_name="gpt-4.1-mini"
)
kernel.add_service(chat_completion_service)
Define a system message and chat history
system_message = """
You are a chat bot. Your name is Mosscap and
you have one goal: figure out what people need.
Your full name, should you need to know it, is
Splendid Speckled Mosscap. You communicate
effectively, but you tend to answer with long
flowery prose.
"""
chat_history = []
chat_history = ChatHistory(system_message=system_message)
async def chat() -> bool:
try:
user_input = input("User:> ")
except (KeyboardInterrupt, EOFError):
print("\n\nExiting chat...")
return False
if user_input.lower().strip() == "exit":
print("\n\nExiting chat...")
return False
chat_history.add_user_message(user_input)
settings = AzureChatPromptExecutionSettings(
max_tokens=2000,
temperature=0.7,
top_p=0.8
)
response = await chat_completion_service.get_chat_message_content(
chat_history=chat_history,
settings=settings
)
print(f"Mosscap:> {response}")
chat_history.add_assistant_message(response)
return True
async def main() -> None:
chatting = True
while chatting:
chatting = await chat()
if name == "main":
asyncio.run(main())
on this line: chat_history.add_assistant_message(response)
chat_history.py", line 140, in add_assistant_message
raise NotImplementedError
NotImplementedError
Name: semantic-kernel
Version: 1.32.1
Summary: Semantic Kernel Python SDK
Home-page: https://learn.microsoft.com/en-us/semantic-kernel/overview/
Author:
Author-email: Microsoft SK-Support@microsoft.com
License:
Location: C:\Python312\Lib\site-packages
Requires: aiohttp, aiortc, azure-ai-agents, azure-ai-projects, azure-identity, cloudevents, defusedxml, jinja2, nest-asyncio, numpy, openai, openapi_core, opentelemetry-api, opentelemetry-sdk, prance, protobuf, pybars4, pydantic, pydantic-settings, scipy, typing-extensions, websockets
Running this code
Example using Semantic Kernel with AzureChatCompletion
import asyncio
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion, AzureChatPromptExecutionSettings
from semantic_kernel.contents import ChatHistory
Initialize the kernel
kernel = Kernel()
Configure Azure OpenAI Chat Completion
chat_completion_service = AzureChatCompletion(
endpoint="https://-resource.openai.azure.com/",
api_key="mykey",
deployment_name="gpt-4.1-mini"
)
kernel.add_service(chat_completion_service)
Define a system message and chat history
system_message = """
You are a chat bot. Your name is Mosscap and
you have one goal: figure out what people need.
Your full name, should you need to know it, is
Splendid Speckled Mosscap. You communicate
effectively, but you tend to answer with long
flowery prose.
"""
chat_history = []
chat_history = ChatHistory(system_message=system_message)
async def chat() -> bool:
try:
user_input = input("User:> ")
except (KeyboardInterrupt, EOFError):
print("\n\nExiting chat...")
return False
async def main() -> None:
chatting = True
while chatting:
chatting = await chat()
if name == "main":
asyncio.run(main())
on this line: chat_history.add_assistant_message(response)
chat_history.py", line 140, in add_assistant_message
raise NotImplementedError
NotImplementedError
Name: semantic-kernel
Version: 1.32.1
Summary: Semantic Kernel Python SDK
Home-page: https://learn.microsoft.com/en-us/semantic-kernel/overview/
Author:
Author-email: Microsoft SK-Support@microsoft.com
License:
Location: C:\Python312\Lib\site-packages
Requires: aiohttp, aiortc, azure-ai-agents, azure-ai-projects, azure-identity, cloudevents, defusedxml, jinja2, nest-asyncio, numpy, openai, openapi_core, opentelemetry-api, opentelemetry-sdk, prance, protobuf, pybars4, pydantic, pydantic-settings, scipy, typing-extensions, websockets