using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
deploymentName: "gpt-4o",
endpoint: "https://my-openai.openai.azure.com/",
apiKey: Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY")!
);
var kernel = builder.Build();
var chatService = kernel.GetRequiredService<IChatCompletionService>();
var history = new ChatHistory("You are a helpful assistant.");
history.AddUserMessage("What are the benefits of Azure AI Foundry?");
var response = await chatService.GetChatMessageContentAsync(history);
Console.WriteLine(response.Content);
import semantic_kernel as sk
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
kernel = sk.Kernel()
kernel.add_service(AzureChatCompletion(
deployment_name="gpt-4o",
endpoint="https://my-openai.openai.azure.com/",
api_key=os.environ["AZURE_OPENAI_KEY"],
))
summarize = kernel.add_function(
plugin_name="TextPlugin",
function_name="summarize",
prompt="Summarize in 3 bullet points:\n\n",
)
result = await kernel.invoke(summarize, input="Azure AI Foundry is...")
from langchain_openai import AzureChatOpenAI, AzureOpenAIEmbeddings
from langchain.chains import RetrievalQA
from langchain_community.vectorstores import AzureSearch
llm = AzureChatOpenAI(
azure_deployment="gpt-4o",
azure_endpoint="https://my-openai.openai.azure.com/",
api_version="2024-08-01-preview",
temperature=0.7,
)
embeddings = AzureOpenAIEmbeddings(
azure_deployment="text-embedding-ada-002",
azure_endpoint="https://my-openai.openai.azure.com/",
)
vector_store = AzureSearch(
azure_search_endpoint="https://my-search.search.windows.net",
azure_search_key=os.environ["SEARCH_KEY"],
index_name="documents",
embedding_function=embeddings.embed_query,
)
qa_chain = RetrievalQA.from_chain_type(
llm=llm, retriever=vector_store.as_retriever(search_kwargs={"k": 5}),
)
answer = qa_chain.invoke("What is our refund policy?")
import autogen
config_list = [{"model": "gpt-4o", "api_type": "azure",
"base_url": "https://my-openai.openai.azure.com/",
"api_version": "2024-08-01-preview",
"api_key": os.environ["AZURE_OPENAI_KEY"]}]
researcher = autogen.AssistantAgent("Researcher",
system_message="You research topics thoroughly.",
llm_config={"config_list": config_list})
writer = autogen.AssistantAgent("Writer",
system_message="You write clear summaries from research.",
llm_config={"config_list": config_list})
user_proxy = autogen.UserProxyAgent("User",
human_input_mode="NEVER", max_consecutive_auto_reply=3)
user_proxy.initiate_chat(researcher, message="Research enterprise AI trends.")
from llama_index.llms.azure_openai import AzureOpenAI
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
llm = AzureOpenAI(deployment_name="gpt-4o",
azure_endpoint="https://my-openai.openai.azure.com/",
api_key=os.environ["AZURE_OPENAI_KEY"])
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents, llm=llm)
response = index.as_query_engine().query("What are the key findings?")
| Feature | Semantic Kernel | LangChain | AutoGen | LlamaIndex |
|---|---|---|---|---|
| Best for | Enterprise apps | Rapid prototyping | Multi-agent | RAG-focused |
| Languages | C#, Python, Java | Python, JS | Python | Python, TS |
| MS support | First-party | Community | First-party | Community |
| Production | High | Medium-High | Medium | Medium-High |
Tip: Use Semantic Kernel for enterprise .NET apps, LangChain for Python prototypes, AutoGen for multi-agent collaboration, LlamaIndex for RAG over diverse data.