<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Siva Ramaswami on Medium]]></title>
        <description><![CDATA[Stories by Siva Ramaswami on Medium]]></description>
        <link>https://medium.com/@sramaswami11?source=rss-3c1885989691------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f6IPAj8iSAKqvjPAzN4fAA.jpeg</url>
            <title>Stories by Siva Ramaswami on Medium</title>
            <link>https://medium.com/@sramaswami11?source=rss-3c1885989691------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:42:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sramaswami11/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[When MCP met Agentic AI: Building a Stock Sentiment Assistant with Real APIs and Multi-Tool…]]></title>
            <link>https://medium.com/@sramaswami11/when-mcp-met-agentic-ai-building-a-stock-sentiment-assistant-with-real-apis-and-multi-tool-34077fcd382a?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/34077fcd382a</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 22:09:34 GMT</pubDate>
            <atom:updated>2025-06-20T22:09:34.888Z</atom:updated>
            <content:encoded><![CDATA[<h3>When MCP met Agentic AI: Building a Stock Sentiment Assistant with Real APIs and Multi-Tool Reasoning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*8y-pEdesgZG59k4p" /></figure><p>It’s hard to miss the growing momentum behind <strong>MCP architecture</strong> and <strong>Agentic AI</strong> in today’s AI engineering conversations.</p><p>In this article, we’ll briefly introduce both of these AI system design patterns and show how to combine them to build a practical, multi-strategy stock sentiment assistant.</p><p>This application will analyze a stock’s potential performance based on multiple real-time attributes like its current price, recent news headlines, and market trends. It will leverage multiple external APIs to fetch live data — including stock prices, earnings reports, and financial news — and apply proven methodologies such as <strong>CAN SLIM scoring</strong> and <strong>Cup and Handle pattern detection</strong> to deliver actionable insights.</p><p>We’ll build this solution using an <strong>MCP-driven architecture</strong>, with the reasoning agent hosted in an ASP.NET Core environment, and a <strong>Blazor-powered front end</strong> for a clean, interactive user experience.</p><p><strong>What is MCP?<br></strong> <strong>MCP</strong> stands for <strong>Model-Context Protocol</strong> — an open standard and open-source framework introduced by <strong>Anthropic in November 2024</strong> to standardize how artificial intelligence (AI) systems, particularly large language models (LLMs), integrate, exchange, and reason with external tools, data sources, and software systems.</p><p>Often described by technology writers as <strong>“the USB-C of AI apps,”</strong> MCP was designed to serve as a universal connector between AI agents and external digital environments. Its core goal is to create a model-agnostic, portable interface for exchanging context — whether that context comes from files, API calls, databases, or function calls — allowing AI models to reason more effectively about their environment and tools.</p><p>MCP defines a set of standardized message formats and operational conventions for passing structured context, invoking functions, reading and writing data, and maintaining multi-turn, multi-agent workflows. By decoupling AI model logic from external environment details, it enables developers to build flexible, interoperable AI assistants that can work across different platforms and toolchains without model-specific custom integrations.</p><p>Since its official announcement and open-sourcing in November 2024, MCP has gained rapid adoption across the AI ecosystem, with leading AI providers including <strong>OpenAI</strong>, <strong>Google DeepMind</strong>, <strong>Anthropic</strong>, and others supporting the protocol or integrating compatible adapters into their platforms.</p><p>For an in-depth technical overview, visit the official MCP spec:<a href="https://modelcontextprotocol.io/introduction"> https://modelcontextprotocol.io/introduction</a></p><p><strong>What is Agentic AI?<br></strong> <strong>Agentic AI</strong> refers to a class of artificial intelligence systems designed to operate autonomously, making decisions, taking actions, and adjusting their behavior without continuous human oversight. Unlike conventional AI models that execute specific tasks when prompted, Agentic AI systems proactively reason about goals, decide what steps to take, and dynamically orchestrate tools, data, and workflows to achieve outcomes.</p><p>These systems exhibit agency — meaning they can pursue objectives, decompose tasks, invoke external resources, and modify their plans based on real-time conditions or evolving context. This makes them especially valuable for complex, multi-step problems where flexibility, judgment, and tool use are required.</p><p><strong>Agentic AI</strong> is increasingly applied in areas like:</p><ul><li>AI-driven software development (e.g. AI coding copilots)</li><li>Automated incident response in cybersecurity</li><li>Customer service automation</li><li>Market analysis and business intelligence</li><li>Research agents and AI-powered assistants</li></ul><p>It’s closely related to — but conceptually distinct from — <strong>AI agents</strong>. While traditional AI agents typically execute a predefined task when prompted (e.g. answering a query, retrieving a document), <strong>Agentic AI systems are capable of autonomous multi-task reasoning</strong>. They can independently plan, decide which tools to use, sequence actions, and alter their flow of execution as needed, often interacting with multiple APIs, models, and data sources on their own initiative.</p><p><strong>Application Architecture Plan</strong></p><p>We are building a <strong>Blazor Web Application</strong> that implements the <strong>MCP (Model-Context-Protocol) architecture pattern</strong>. Our first step is to lay down the building blocks that support this structure.</p><p>The <strong>Model</strong> defines the user’s intent — in this case, analyzing a specific ticker symbol along with a desired objective.</p><p>The <strong>Context</strong> maintains the evolving state of the system, including details like the ticker symbol, current price, news, sentiment analysis, trend data, and decision history.</p><p>The <strong>Protocol</strong> contains a reasoning loop that inspects the current context, determines which tools or services to invoke next, updates the context, and continues iterating until the goal is achieved.</p><p>(We’ll cover the detailed code implementation for these MCP components in the next section.)</p><p>As for the <strong>Agentic AI traits</strong>, the application will demonstrate:</p><ul><li><strong>Autonomy</strong> — The agent dynamically decides what data to fetch and analyze (price, news, trends, etc.) based on the context state, rather than following a hardcoded sequence.</li><li><strong>Multi-step Reasoning</strong> — It incrementally performs actions such as fetching prices, retrieving news, running sentiment and trend analysis, and checking for alerts, based on current conditions.</li><li><strong>Tool Use</strong> — The system will incorporate services like MarketDataService, FinancialNewsService, NewsAnalysisService, TrendAnalysisService, AlertTriggerService, and others.</li><li><strong>Context Awareness</strong> — The app maintains a rich context containing the ticker, prices, news, sentiment, trend information, decision history, and alert states.</li><li><strong>Outcome-based Control Flow</strong> — Decisions, such as triggering alerts, are driven by the state of the context (e.g., sentiment score combined with price movements).</li><li><strong>Goal-Driven Behavior</strong> — All actions are orchestrated around a user-defined goal object that the system continuously works toward achieving.</li></ul><p>In the next section, we’ll dive into how these components are implemented in code.</p><p><strong>Implementation</strong></p><p>Let’s fire up Visual Studio and create a new Blazor Web App project.</p><p>In .NET 9.0, selecting the Blazor Web App template generates two projects: one for the server and another for the client (with a .Client extension). For this implementation, we’ll focus solely on the server project and set aside the client project for now.</p><p>Next, we need to add the following NuGet packages to our server project:</p><ul><li><strong>Microsoft.SemanticKernel</strong> — This package enables us to communicate with the AI model and retrieve sentiment analysis results.</li><li><strong>RestSharp</strong> — A lightweight HTTP client library for making API requests.</li></ul><p>Once the dependencies are in place, create a new folder named <strong>Models</strong> within the project. Inside this folder, add a file called AnalysisGoal.cs. This class will define the goal object that gets sent to the AI model — it will include both the analysis objective and the stock’s ticker symbol that we want to evaluate.</p><p>Here is a screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DIlEXab1jkkh_Z7Q" /></figure><p>Next, let’s define the SentimentContext class for the stock we’re analyzing. This context object will serve as a container for all relevant information related to the stock. It will include properties such as the ticker symbol, current price, a list of top news headlines, the sentiment analysis result, price trends, CAN SLIM score, Cup and Handle pattern detection results, a history of actions taken, and more.</p><p>Here’s a screenshot of the class structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1n2cm-XaGXXaltkO" /></figure><p>Our next step is to create a <strong>Services</strong> folder and add several service classes within it. The first service we’ll build is called MarketDataService, which will contain a single method named GetStockDataAsync.</p><p>This method will use the <strong>FINNHUB</strong> API to fetch the current price of a stock by passing the ticker symbol and API key via a RestClient. It sends the request, processes the response, and retrieves the latest stock price.</p><p>For the complete implementation (and for the other services we are going to describe as well), you can refer to the GitHub repository linked at the end of this article.</p><p>Another service we need to add to the <strong>Services</strong> folder is FinancialNewsService. This service will include a single method named GetRecentHeadlinesAsync, which uses the <strong>FINNHUB</strong> API to fetch the latest important news headlines related to a given stock.</p><p>The method takes the ticker symbol as input, constructs an API request using RestClient, executes the request, and retrieves the relevant headlines.</p><p>The next service to add is NewsAnalysisService, which leverages <strong>Microsoft Semantic Kernel</strong> and <strong>OpenAI</strong> to analyze market sentiment based on the data we’ve gathered — including the ticker symbol, current price, and recent news headlines from the other services we built earlier.</p><p>This service uses a prompt template, where the ticker, price, and headlines are dynamically inserted. Semantic Kernel is initialized with the appropriate model ID and OpenAI API key, after which it executes the prompt against the model. The resulting sentiment analysis is then returned to the application.</p><p>The next service to add is TrendAnalysisService, which is responsible for detecting the market trend of a given stock. This service uses the <strong>TwelveData API</strong> and RestClient to fetch the stock’s historical closing prices.</p><p>Based on this data, it determines whether the stock’s price trend is upward, downward, or stable, and then returns the result to the caller.</p><p>The next service we’ll add is CupAndHandlePatternService, which builds upon the TrendAnalysisService we created earlier. It uses a method from that service called GetRecentClosingPricesAsync — a slight variation of the method used for detecting trends — to retrieve historical closing prices.</p><p>Using this data, it analyzes whether the stock exhibits a <strong>Cup and Handle breakout pattern</strong>.</p><p>For more details, you can review the implementation in the project’s repository. To get a visual understanding of the Cup and Handle pattern, check out this helpful article on Investopedia:<a href="https://www.investopedia.com/terms/c/cupandhandle.asp"> https://www.investopedia.com/terms/c/cupandhandle.asp</a></p><p>The next service we’ll add is CANSLIMScoringService. This scoring model is based on the <strong>CAN SLIM</strong> strategy developed by William J. O’Neil. (For a detailed overview, refer to this Investopedia article:<a href="https://www.investopedia.com/terms/c/canslim.asp"> https://www.investopedia.com/terms/c/canslim.asp</a>).</p><p>In this service, we use a third-party API called <strong>FinancialModelingPrep</strong> to fetch the quarterly earnings growth data for a given stock. Based on this information, we compute a growth value, which is then returned as a score. This score serves as the foundation for interpreting the stock’s CAN SLIM rating.</p><p>All of the relevant data returned from the services above are stored within our <strong>context object</strong>. The final service we’ll add is AlertTriggerService.</p><p>This service takes the context object as input and evaluates specific properties within it — such as sentiment, price trend, pattern detection, and CAN SLIM score — to determine whether a <strong>Buy Alert</strong> should be triggered for the given stock.</p><p>We also create a folder named <strong>Agent</strong>, which contains the logic for our Agentic AI implementation in a class called StockSentimentAgent. This class holds references to each of the services we described earlier.</p><p>It exposes a single method called RunGoalAsync, which retrieves the context object from a memory store where it was previously saved. The method then examines each property within the context and selectively invokes the necessary services based on what’s required. As results are obtained, it updates the context object accordingly.</p><p>The final part of the application comes together in the <strong>Blazor UI</strong>. Inside the <strong>Components</strong> folder, you’ll find a Home.razor file, where the Blazor template currently displays some placeholder “Hello” messages. We’ll clean that up and replace it with a simple UI layout.</p><p>We’ll add some HTML markup to create a <strong>text box</strong> for the user to enter a stock ticker symbol and a <strong>button</strong> to trigger the analysis. When the button is clicked, it will call a method named AnalyzeStock() in the @code section of the Razor component.</p><p>This method retrieves the ticker value entered by the user and pairs it with a predefined objective:</p><p><em>“Analyze stock price, news, sentiment, Cup and Handle pattern, and CAN SLIM score to decide if actionable.”</em></p><p>Both the ticker and objective are then passed to the RunGoalAsync() method we previously implemented in the StockSentimentAgent class.</p><p>Once all the values are retrieved from the various services, the results are displayed on the Razor page.</p><p>For the complete Razor markup and C# code-behind, please check out the full implementation in our GitHub repository.</p><p>The final rendered page will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Agp9fHKSrWnXwShk" /></figure><p><strong>Summary</strong></p><p>In this blog, we explored how to design and build a practical <strong>AI-powered stock sentiment analysis assistant</strong> using the emerging <strong>MCP (Model-Context-Protocol)</strong> architecture pattern and <strong>Agentic AI principles</strong> — all implemented within a modern <strong>Blazor Web App on .NET 9</strong>.</p><p>We began by introducing <strong>MCP</strong> as a model-agnostic, open protocol for standardizing how AI systems interact with external data sources, APIs, and tools. MCP provides a structured, portable way for AI agents to reason about their environment through shared context and a flexible reasoning protocol. In parallel, we introduced the concept of <strong>Agentic AI</strong> — autonomous systems capable of multi-step reasoning, tool use, and goal-directed behavior without continuous human oversight.</p><p>With those foundations in place, we designed a stock analysis application capable of assessing a stock’s potential based on <strong>live market data, news sentiment, technical chart patterns, and earnings performance metrics</strong>. The app applies well-known financial analysis strategies, such as <strong>CAN SLIM scoring</strong> and <strong>Cup and Handle pattern detection</strong>, to surface actionable insights.</p><p>The system architecture follows a clean MCP structure:</p><ul><li>A <strong>Model</strong> representing the user’s goal (e.g., analyze a stock’s outlook)</li><li>A <strong>Context</strong> object maintaining stateful, evolving data throughout the analysis process</li><li>A <strong>Protocol loop</strong> housed in an AI agent that inspects the context, determines which services to invoke, updates the context, and continues iterating until the objective is achieved</li></ul><p>We implemented a suite of services to fetch real-time stock prices, news headlines, sentiment analysis, trend data, and pattern detection — all orchestrated by an autonomous <strong>reasoning agent</strong>. The agent decides which actions to perform based on the current context, dynamically adjusts its workflow, and ultimately determines whether a buy alert should be triggered.</p><p>Finally, we surfaced these insights through a <strong>Blazor front end</strong>, where users can enter a stock ticker, initiate analysis, and view live, AI-augmented results in an interactive, cleanly designed UI.</p><p>This project demonstrates how <strong>MCP architecture and Agentic AI patterns can be combined to build modular, interoperable, and intelligent financial applications</strong> — and highlights the exciting new possibilities unlocked by integrating reasoning agents with real-time data APIs and AI services in a modern web environment.</p><p>Look forward to hearing from you on what you think about this article. Thanks for your time reading this! The entire source code for this project can be downloaded from the following github repository link:</p><p><a href="https://github.com/sramaswami11/FinAgentAI/tree/master">GitHub - sramaswami11/FinAgentAI at master</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34077fcd382a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seeking Deep: Building with DeepSeek APIs]]></title>
            <link>https://medium.com/@sramaswami11/seeking-deep-building-with-deepseek-apis-4207bdf17b86?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/4207bdf17b86</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 03:36:00 GMT</pubDate>
            <atom:updated>2025-02-05T03:36:00.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*l9W_QtCC83W9FWhH26MFUA.png" /></figure><p><strong>Background</strong></p><p>The year 2025 has been nothing short of eventful, marked by significant developments across the globe. Just one day after his inauguration, President Donald Trump announced on January 21, 2025, that the U.S. government would pledge support for the $500 billion Stargate Project. Meanwhile, nearly halfway around the world, in China, DeepSeek unveiled its R1 large language model (LLM) at a fraction of the cost incurred by other developers. Remarkably, DeepSeek is offering the R1 under an open-source license, allowing for free use. In response to the announcement, Nvidia’s stock plummeted over 17%, wiping out $600 billion in market value the following Monday.</p><p><strong>What is DeepSeek?</strong></p><p>DeepSeek is an emerging AI model gaining widespread recognition for its advanced natural language processing capabilities. Developed by a Chinese startup, it has demonstrated performance levels that rival established platforms like ChatGPT. Founded in 2023 by Liang Wenfeng and headquartered in Hangzhou, Zhejiang, DeepSeek is backed by the hedge fund High-Flyer, which Wenfeng co-founded. The company specializes in developing open-source large language models (LLMs), with its first model released in November 2023. Since then, DeepSeek has iterated multiple times on its core LLM, creating several variations tailored to different use cases. However, it wasn’t until January 2025, with the release of its groundbreaking R1 reasoning model, that the company achieved global fame. DeepSeek offers a range of services for its models, including a web interface, mobile application, and API access, making its technology accessible to a broad audience.</p><p>The table below highlights the key differences between DeepSeek and OpenAI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/0*EJEpzjo454Ej2l4l" /></figure><p><strong>Rest of the Article</strong></p><p>Now that we’ve covered the basics of DeepSeek, this article will delve into integrating with DeepSeek’s API, exploring its models, and demonstrating how to connect to the DeepSeek system using a third-party .NET API to accomplish specific tasks. Let’s dive in!</p><p><strong>A Quick Note About the Models:</strong></p><p>DeepSeek currently supports two primary models: <strong>deepseek-chat</strong> and <strong>deepseek-reasoner</strong>. The <strong>deepseek-chat</strong> model has been upgraded to <strong>DeepSeek-V3</strong>, while <strong>deepseek-reasoner</strong> now points to the advanced <strong>DeepSeek-R1</strong> model.</p><p>The <strong>deepseek-reasoner</strong> is a specialized reasoning model designed by DeepSeek. To ensure higher accuracy, it employs a <strong>Chain of Thought (CoT)</strong> approach, generating intermediate reasoning steps before delivering the final answer.</p><p><strong>Getting a DeepSeek account</strong></p><p>Visit <a href="https://www.deepseek.com/"><strong>DeepSeek.com</strong></a> and click the <strong>“Start Now”</strong> button on the landing page. The website will guide you through the signup process. Once you complete the registration, you’ll be directed to DeepSeek’s chat interface, where you can start interacting with their advanced large language model (LLM).</p><p><strong>Getting an API key and purchasing tokens</strong></p><ol><li>Open your browser and navigate to <a href="https://api-docs.deepseek.com/"><strong>https://api-docs.deepseek.com/</strong></a>.</li><li>Click on <strong>Quick Start</strong> and follow the instructions under <strong>Your First API Call</strong>.</li><li>Click the link titled <strong>“Apply for an API Key”</strong> to sign up for an API key.</li><li>During the signup process, you can also purchase tokens, which will be consumed when making API calls.</li></ol><p>Below is a table showing the pricing for one million tokens when using the API with the two currently available models:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MVFGX0wrgSlVuD9r" /></figure><p>The pricing for deepseek-chat with a superscript of (5) refers to discounted price until 2/8/2025.</p><p><strong>Supported Languages and frameworks</strong></p><p>Under the <strong>API Reference</strong> page, you’ll find sample code for connecting to various endpoints using multiple programming languages, including Python, Node.js, C#, Java, and more. However, in this article, we’ll focus on <strong>C#</strong> and utilize a third-party library called <strong>DeepSeekSDK-NET</strong>.</p><p>We’ll be working with four key endpoints:</p><ol><li><strong>Models</strong>: Lists all available models.</li><li><strong>StreamedChat</strong>: Uses the <strong>deepseek-reasoner</strong> model for chat interactions.</li><li><strong>Completions</strong>: Uses the <strong>deepseek-chat</strong> model to complete a partial prompt.</li><li><strong>GetUserBalance</strong>: Returns the remaining balance in the user account associated with the API key.</li></ol><p>Let’s dive in and get started!</p><p><strong>Packages to Install</strong></p><p>The <strong>DeepSeekSDK-NET</strong> library is available as a NuGet package. To install it, open the <strong>Package Manager Console</strong> in Visual Studio and run the appropriate command. Additionally, we’ll need to install another NuGet package to enable reading configuration values from the <strong>appsettings.json</strong> file.</p><p>Once both packages are installed, your Visual Studio Solution Explorer should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*jBZckC8cfNPnqZWy" /></figure><p><strong>Configuring the DeepSeek API key</strong></p><p>You’ll need to add a configuration file named <strong>appsettings.json</strong> to store the DeepSeek API key.<br>Below is a screenshot of the <strong>appsettings.json</strong> file, where you should replace <strong>&lt;YourKey&gt;</strong> with your own API key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uecWRp3Vg2l-ga93" /></figure><p>Now, let’s proceed with coding to implement a few functionalities using the methods provided by the <strong>DeepSeekSDK-NET</strong> library.</p><p><strong>Retrieving the Configuration Value</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/0*npeqSJykUhNhPRtU" /></figure><p>As shown in the screenshot above, you can retrieve the DeepSeek API key.</p><p><strong>Creating an Instance of DeepSeekClient</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*1NQNQnBVabHEk7pm" /></figure><p>You can create an instance of <strong>DeepSeekClient</strong> by invoking its constructor and passing the API key as a parameter.</p><p><strong>Listing Available Models</strong></p><p>The first step is to check which DeepSeek models are available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gzKeTQ8CEg9jWDVP" /></figure><p>As shown in the screenshot above, we simply call the <strong>ListModelsAsync</strong> method provided by our NuGet package, passing an instance of the <strong>CancellationToken</strong> object. After performing a null check on the response, we iterate through the data collection and print the model information to the console.</p><p><strong>Retrieving User Balance</strong></p><p>Before interacting with the model through other APIs, it’s a good practice to check the user’s remaining credit. To achieve this, we use the GetUserBalanceAsync call. The resulting balance object provides the remaining credit for the account associated with the specified apiKey</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3nINVAONe2o2NdqW" /></figure><p><strong>Streamed Chat</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q_LlTsGDUGL2gh1d" /></figure><p>In the screenshot above, we configure the ChatRequest object with a user message, which serves as the question for the LLM, and a system message, providing system-level guidance to the LLM. We also specify the model as deepseek-reasoner. Next, we invoke the ChatStreamAsync method from the DeepSeekSDK-NET package, passing the request and CancellationToken. We can then iterate through the response collection and print the content.</p><p><strong>Completions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9adyZ4wg17C63XHG" /></figure><p>This is similar to the StreamedChat call, but in this case, we pass the ChatModel as the model to be used. This call allows the LLM to complete the request sent by the user.</p><p>Next, we invoke the methods defined above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/0*paGOlXUIcrV7166n" /></figure><p><strong>The Stage is Set</strong></p><p>With the code built, it’s time to give it a whirl. Here’s the output:</p><ul><li>The first two lines display the models returned by the ListModels method.</li><li>Next, we see the user’s balance, retrieved from the GetUserBalance call.</li><li>Following that, the next two lines are the output from the StreamedChat call, showing the Spanish translation of &#39;Good morning,&#39; as requested.</li><li>The subsequent lines are the output from the Completions method, where we asked the LLM to complete our statement on why DeepSeek is superior to OpenAI. The response begins with the total token count, followed by a detailed answer to our query.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZYnavjrwmgfojdLC" /></figure><p><strong>Conclusion:</strong></p><p>We explored how to build applications using <strong>DeepSeek APIs</strong>, walking through key methods and their outputs. We start by setting up the ChatRequest object, where we configure user and system messages to interact with the deepseek-reasoner model. We then demonstrate how to check a user’s balance using the GetUserBalanceAsync call. Next, we showcase streamed responses with ChatStreamAsync, including an example that translates “Good morning” into Spanish. We also cover the Completions method, where we prompt the LLM to generate detailed responses, such as explaining why DeepSeek outperforms OpenAI. Finally, we review the output results, highlighting how each API call fits into the overall workflow.</p><p><strong>Access the full code</strong><a href="https://github.com/sramaswami11/DeepSeekTest/tree/master"><strong> here</strong></a><strong>.</strong></p><p>Thanks for reading, and happy coding! Until next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4207bdf17b86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Smarter AI Agents: A Comprehensive Step-by-Step Guide Using the Semantic Kernel Framework]]></title>
            <link>https://medium.com/@sramaswami11/building-smarter-ai-agents-a-comprehensive-step-by-step-guide-using-the-semantic-kernel-framework-c526a02232dd?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/c526a02232dd</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 02:24:20 GMT</pubDate>
            <atom:updated>2025-01-22T02:24:20.487Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Background:</strong></p><p>In this guide, we will explain essential terms like Semantic Kernel, AI agent and the framework that supports its creation. Following this, we will provide a detailed, step-by-step tutorial on building an AI agent, including extensive code examples. The focus of this article is on developing an agent that acts as a chat completion assistant, capable of using the GitHub API to query a specific repository and return answers to the questions it receives.</p><p><strong>What is an AI agent:</strong></p><p>An AI agent is a software application designed to perform tasks independently or with minimal human input. It takes in information, processes it, and takes actions to achieve specific goals. AI agents offer several advantages, including the ability to build modular components for specialized tasks, facilitate collaboration between agents, enable human-agent interaction, and simplify process orchestration. They are particularly beneficial in scenarios where autonomy and decision-making are essential (e.g., robotic systems), when multiple independent agents need to work together in complex systems (such as supply chain management), or when the application involves goal-oriented behavior (like virtual assistants or game AI).</p><p><strong>What is Semantic Kernel?</strong></p><p>In some of the previous articles, we’ve explored the Semantic Kernel, Microsoft’s open-source solution for building and designing copilots. In essence, the Semantic Kernel streamlines the creation of plugins, organizes them into plans, and helps new AI developers integrate the latest AI advancements into their apps, services, and innovative features. For an in-depth exploration of the Semantic Kernel’s architecture, please refer to my earlier article, <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-a-step-by-step-guide-for-your-application-e51f2c91bcad">Mastering Semantic Kernel Integration: Part 1 — Core Plugins</a>. Below is a visual representation of the Semantic Kernel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LCM8L-0ueZ-7jAqm" /></figure><p><strong>Semantic Kernel Agent Framework</strong></p><p>In some of my previous articles, we delved into the Semantic Kernel. For a comprehensive overview of what the Semantic Kernel is and its architecture, please refer to my earlier article, <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-a-step-by-step-guide-for-your-application-e51f2c91bcad"><em>Mastering Semantic Kernel Integration: Part 1 — Core Plugins</em></a>. The Semantic Kernel Agent Framework, a key component of the Semantic Kernel ecosystem, streamlines the creation and deployment of AI agents. It offers tools and patterns for integrating these agents into various applications, enabling them to perform tasks, make decisions, and interact with other components using the Semantic Kernel’s principles and features. Essentially, it allows developers to incorporate AI-driven functionality consistently and reusably, leveraging the core capabilities of the Semantic Kernel. Currently in preview, the Semantic Kernel Agent Framework is subject to ongoing updates and changes.</p><p><strong>Implementing the AI agent</strong></p><p>Now that we have a solid understanding of the foundational concepts and the Semantic Kernel Agent Framework, it’s time to move from theory to practice. In the next section, we will dive into the implementation, exploring the code step-by-step to build our AI agent. Let’s begin by setting up the environment and writing the initial lines of code to bring our agent to life.</p><p><strong>Taking care of the configurations</strong></p><p>To set up our environment, we need to install two key NuGet packages: Microsoft.SemanticKernel.Agents.Core (currently in preview) and the main Microsoft.SemanticKernel. Additionally, we’ll need a few other NuGet packages to handle configuration management and securely store user secrets, such as the OpenAI key and the passcode for accessing the GitHub API. Once these packages are added, the Visual Studio solution will display all the necessary dependencies for running the code in this tutorial. Here’s a screenshot showcasing the installed packages in Visual Studio:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/0*3TkMcMp-p06ooI5T" /></figure><p>As mentioned earlier, since the Semantic Kernel Agent Framework is still experimental, we need to suppress certain warnings in the project file to avoid issues during compilation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/0*j804yO1e482F4kxH" /></figure><p>Next, let’s store the necessary secrets, such as the OpenAI API key, model, GitHub Base URL, and token, using the PowerShell prompt. Run the following commands to securely store these secrets:</p><p># Open AI</p><p>dotnet user-secrets set “OpenAISettings:ApiKey” “&lt;api-key&gt;”</p><p>dotnet user-secrets set “OpenAISettings:ChatModel” “gpt-4o”</p><p># GitHub</p><p>dotnet user-secrets set “GitHubSettings:BaseUrl” “https://api.github.com&quot;</p><p>dotnet user-secrets set “GitHubSettings:Token” “&lt;personal access token&gt;”</p><p>See the link <a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens">Managing your personal Access Token</a> for instructions to create a token.</p><p><strong>Let’s Dive into the Code</strong></p><p>Now, let’s start adding some code. Since we’re going to interact with GitHub, we’ll first need to create a model class named GitHubModels.cs. This class will contain five sub-classes: Repo, User, Issue, IssueDetail, and Label. Each of these classes will have their respective members, which can be viewed in the GitHub repository where this will be checked in.</p><p>Next, we will create a class called GithubPlugin.cs. In this class, various public methods will be decorated with the [KernelFunction] attribute (formerly known as SKFunction). This attribute indicates that these are native functions written by the developer, making them available for the Semantic Kernel orchestrator to use. To learn more about native functions, refer to my article <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-part3-native-functions-1a315cc21c94"><em>Mastering Semantic Kernel Integration: Part 3 - Native Functions</em>.</a></p><p>Some of these kernel functions will include:</p><ul><li>GetUserProfileAsync: To retrieve the user profile</li><li>GetRepositoryAsync: To connect to the repository</li><li>GetIssuesAsync: To fetch all issues in the repository</li><li>GetIssueDetailAsync: To get detailed information about a specific issue</li></ul><p>Additionally, we will have a set of helper methods to support the implementation of these kernel functions. The full implementation details are available in the file checked into GitHub.</p><p>Next, let’s add a foundational class called Settings.cs. This class will be responsible for managing the OpenAI settings, including the constructor and a GetSettings method to retrieve these settings when needed.</p><p>Now, let’s move to the main part of the code where we will utilize everything we’ve set up so far to accomplish our goal: building the ChatCompletionAgent. This agent will combine the GitHub plugin, Semantic Kernel functions, and OpenAI integration to provide a powerful, automated assistant capable of interacting with GitHub repositories and handling queries.</p><p>The process can be summarized in three key steps:</p><ol><li><strong>Initializing Settings and the Plugin</strong></li><li><strong>Creating the AI Chat Completion Agent with Templatized Instructions and Plugins</strong></li><li><strong>User/Agent Interaction Loop</strong></li></ol><p>Let’s explore the code for each step:</p><h4>Initialization</h4><p>Add the following lines of code to the main program class Program.cs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LZyvmuQFGomsH7m4" /></figure><p>In line 1 above, we initialize the Settings class that we discussed earlier.</p><p>In lines 15 and 16, we retrieve the GitHubSettings and use them to instantiate the GitHubPlugin class.</p><p>Finally, in lines 19 through 25, we create a Kernel instance, configuring it with the ChatCompletionService and the GitHubPlugin we just instantiated.</p><h4>Let’s now move on to the next task:</h4><p><strong>Creating the agent:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LWXn0mBFu6OPbZOA" /></figure><p>We are essentially instantiating a <strong>Chat Completion Agent</strong> with its prompt. The kernel arguments specified in line #47 indicate that the plugin functions we provide will be automatically executed.</p><p>Next, let’s move on to the <strong>Chat loop</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sIxomEKmQJZ44Z6r" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jGcI5qFDdaf3Olad" /></figure><p>In the screenshot(s) above, there is a <strong>do-while</strong> loop running between lines 59 and 89.</p><ul><li>In <strong>line 63</strong>, we are reading the user input.</li><li>In <strong>lines 64 through 67</strong>, if an empty input is received, we simply ignore it.</li><li>In <strong>lines 68 to 72</strong>, if the input is “EXIT”, we exit the infinite loop.</li><li>Any valid input is added to the <strong>Chat History</strong> collection as a User message.</li><li>In <strong>lines 78 through 88</strong>, we invoke the agent using the arguments to provide the final template parameter that specifies the current date and time. The agent then generates a response to the user’s input, which is rendered on the console.</li></ul><p><strong>Let ‘er Rip</strong></p><p>We can test this by building the app and running it. Once the application is running, try entering a few questions to see how well the agent responds:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6lvZcEI6ObkO2mfG" /></figure><p>Behind the scenes, we are making a call to the KernelFunction called GetUserProfileAsync() and returning my GitHub user ID as the response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lsb8UvF8onFN5Rk8" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-1QtzujJdPONQ3Y4" /></figure><p>We can clearly see that a request is being constructed, querying issues with query string parameters to retrieve the last two open issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8mrbjEcYmfJ70uWy" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7yZ9EXQ0kUN1YIcV" /></figure><h4>Conclusion</h4><p>That’s all, folks! As always, thank you for taking the time to read this article. We truly appreciate your feedback and look forward to seeing you in the next part of this series.</p><p>To access all the code for this tutorial, please visit the following URL:<br><a href="https://github.com/sramaswami11/AgentFramework/tree/master">GitHub Repository</a></p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c526a02232dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Music to My Ears: Harmonizing Development with RAGaaS]]></title>
            <link>https://medium.com/@sramaswami11/music-to-my-ears-harmonizing-development-with-ragaas-53339d282534?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/53339d282534</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 20:31:12 GMT</pubDate>
            <atom:updated>2024-12-30T20:31:12.382Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Background:</strong></p><p>In a previous article titled <strong>“</strong><a href="https://medium.com/@sramaswami11/rag-to-riches-using-rag-with-kernel-memory-1bf23668b470"><strong>RAG to Riches: Supercharge your app with RAG and kernel memory</strong></a><strong>”</strong> we introduced Retrieval Augmented Generation (RAG) and demonstrated its implementation using Kernel Memory in a simple application. While that example was straightforward, professional implementations of RAG often involve significantly greater complexity.</p><p>In the “<a href="https://medium.com/@sramaswami11/rag-to-riches-using-rag-with-kernel-memory-1bf23668b470"><strong>RAG to Riches</strong></a>” article, we relied on a single data source. However, enterprise applications frequently require storing data in vector databases. Managing these databases, along with maintaining an efficient data ingestion pipeline to ensure relevance, introduces additional challenges. Developers must integrate with vector databases, which demands specialized skills, time, and resources. For an overview of vector databases and their importance in RAG workflows, refer to resources like <a href="https://en.wikipedia.org/wiki/Vector_database">this Wikipedia article</a>.</p><p>To further complicate matters, enabling RAG systems to reason over both structured and unstructured data often necessitates incorporating knowledge graphs and structured databases. Handling disparate data sources — each with its own APIs, query languages, and connection protocols — requires additional layers of management, making the process even more intricate.</p><p>This complexity raises the question: is there a way to simplify these challenges and avoid the maintenance burden?</p><p>Fortunately, the answer is <strong>RAGaaS</strong> (RAG as a Service).</p><p><strong>What is RAGaaS?</strong></p><p><strong>RAGaaS</strong> stands for <em>Retrieval Augmented Generation as a Service.</em> RAGaaS providers deliver fully managed solutions that handle every aspect of the RAG architecture. These end-to-end services eliminate the complexities of building and maintaining a RAG system, enabling development teams to focus on core application logic and business objectives.</p><p>The provider’s platform typically manages the entire workflow, both during data intake and at user query time. This includes tasks such as data pre-processing, chunking, embedding, vector and text database management, prompt engineering, and contacting the large language model (LLM) to generate responses. By offloading this heavy lifting, RAGaaS simplifies implementation and ensures a seamless experience for developers.</p><p><strong>Who are some popular RAGaaS providers?</strong></p><p>Now that we have an understanding of what RAGaaS is, let’s explore some leading providers in this space. Popular options include <strong>Graphlit</strong>, <strong>Personal AI</strong>, <strong>Vectara</strong>, <strong>Ragie</strong>, and <strong>Nuclia</strong>, among others.</p><p>For the remainder of this article, we’ll focus on integrating with <strong>Graphlit</strong>, a versatile provider that supports multiple language models, including OpenAI, Anthropic, Cohere, Google AI, and Azure AI. Graphlit offers the capability to ingest data from a variety of sources, such as websites, podcasts, and cloud storage, making it highly adaptable to diverse use cases.</p><p>Integration is straightforward, thanks to native SDKs available for Python, Node.js, and .NET. To learn more about Graphlit and its offerings, visit their official website at <a href="https://www.graphlit.com/">www.graphlit.com</a>.</p><p><strong>Plan for the rest of the article</strong></p><p>For the remainder of this article, we’ll focus on setting up and integrating with <strong>Graphlit</strong>, a powerful RAGaaS provider that supports multiple language models, including OpenAI, Anthropic, Cohere, Google AI, and Azure AI. Graphlit allows data ingestion from diverse sources, such as websites, podcasts, and cloud storage, and offers seamless integration through native SDKs for Python, Node.js, and .NET. You can learn more about Graphlit and its capabilities by visiting their official website at <a href="https://www.graphlit.com/">www.graphlit.com</a>.</p><p>In the following sections, we’ll provide a brief guide on setting up the Graphlit environment and demonstrate how to integrate the <strong>Graphlit API</strong> into a <strong>C# project</strong> using the <strong>Visual Studio</strong> development environment.</p><p><strong>Setting up Graphlit</strong></p><p>This guide focuses on integrating with the RAGaaS service provided by <strong>Graphlit</strong>.</p><p>To begin using the Graphlit service, you’ll need to create a free developer account by visiting their website at <a href="https://www.graphlit.com/">www.Graphlit.com</a>. Once your account is set up, follow these steps:</p><ol><li><strong>Create an Organization</strong>: Set up your organization within Graphlit.</li><li><strong>Create a Project</strong>: After creating an organization, set up a project under it.</li></ol><p>Once your project is created, Graphlit will generate the following credentials for you:</p><ul><li><strong>Organization ID</strong></li><li><strong>Preview Environment ID</strong></li><li><strong>JWT Secret</strong></li></ul><p>Make sure to copy and securely store these credentials, as they will be required for integrating with the API and writing code later in this guide.</p><p><strong>Let’s Dive into the Code</strong></p><p>Initially, I planned to create a <strong>console application</strong>, but I decided it would be cooler to implement this in a <strong>Blazor web app</strong>.</p><p>Blazor provides a modern, interactive framework that enables us to build rich web applications using C# and .NET. This approach not only integrates seamlessly with Graphlit’s APIs but also allows us to create a visually appealing interface for our application.</p><p>We’ll still need to install two key NuGet packages:</p><ol><li><strong>Graphlit</strong>: To interact with Graphlit’s APIs.</li><li><strong>Microsoft.Extensions.Configuration.Json</strong>: For reading configuration data from an appsettings.json file.</li></ol><p>Next, we’ll set up an appsettings.json file within the Blazor project. This file will contain the configuration data for <strong>Organization ID</strong>, <strong>Preview Environment ID</strong>, and <strong>JWT Secret</strong>. Replace the placeholders (xxx) with your actual values as shown in the upcoming example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ECXXJW_DYgG9TwVs" /></figure><p>With these preparations, we’re ready to dive into building our Blazor app!</p><p>For this tutorial, we’ll focus on ingesting a <strong>website URL</strong> as a data source. Keep in mind that this is just one of Graphlit’s many capabilities. Graphlit supports ingesting data from a wide variety of sources, including <strong>cloud storage</strong>, <strong>podcasts</strong>, <strong>YouTube</strong>, and more.</p><p>After ingesting the data, we’ll demonstrate how to take a <strong>prompt</strong> from the user (a question based on the ingested content) and retrieve the desired response using Graphlit’s powerful API.</p><p>This process showcases the flexibility of Graphlit’s platform and its ability to seamlessly handle diverse data sources while enabling natural language queries.</p><p><strong>Ingesting the data</strong></p><p>Below is the code that handles the ingestion of data from the specified source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nu3T59RwdtAMpJxn" /></figure><p>In the code below, we can see that the method responsible for data ingestion takes three parameters:</p><ol><li><strong>client</strong>: This is of type IGraphlitClient, which provides access to the Graphlit API.</li><li><strong>name</strong>: The name you wish to assign to the ingested data.</li><li><strong>url</strong>: The URL of the website you want to ingest.</li></ol><p>Inside the method, we call the <strong>IngestUri</strong> function of the client, passing several parameters. The most crucial parameter is the <strong>uri</strong> of the website we want to ingest. The <strong>name</strong> parameter is optional: if not specified, it will default to the filename inferred from the URI. All other parameters can be passed as null, since they are nullable.</p><p>Now, here’s the code to pass the prompt to the Graphlit API and retrieve the answer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AK51iCblN4j5w9uc" /></figure><p>I’ve placed the code for the two methods into a <strong>ChatService.cs</strong> class within my Blazor project.</p><p>The next step is to create a method called <strong>GetResponse</strong>, which will take a string parameter named prompt—this is the text that the user will input. The method will perform the following tasks:</p><ol><li><strong>Instantiate an </strong><strong>HttpClient object</strong> to handle HTTP requests.</li><li><strong>Create a </strong><strong>Graphlit object</strong>, passing the HttpClient and various configuration parameters (such as the API credentials) retrieved from the appsettings.json file.</li></ol><p>Using the instantiated Graphlit client, we will:</p><ul><li>Call the IngestUriAsync method to process the ingested data (as described earlier).</li><li>Call the PromptConversationAsync method, passing the user’s prompt, which will ultimately return the appropriate response.</li></ul><p>This response object will be passed to the constructor of a <strong>Message</strong> object, which will then be returned by the <strong>GetResponse</strong> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IHX1Zl7dgDHWbvkI" /></figure><p>The url used in the above code block is hardcoded for demo purposes. We are also having the constructor for the ChatService class. Here is a screenshot of the code block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e5DrUjVLY8CFBxbi" /></figure><p>Next, we’ll create a class called <strong>Message.cs</strong>, which will represent a message. This class will contain the following properties:</p><ul><li><strong>Timestamp</strong>: The time the message was created.</li><li><strong>Body</strong>: The body of the message.</li><li><strong>IsRequest</strong>: A boolean indicating whether the message is a request or a response.</li></ul><p>The class will also include a constructor that takes the message body and the isRequest boolean, setting these values along with the current timestamp in the corresponding member variables.</p><p>Here is the screenshot that shows the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/0*CCKqU-p-QjvPc-Yu" /></figure><p>Next, create a Razor file called <strong>Chat.razor</strong> to house the user interface (UI) code. This file will also call the methods from the <strong>ChatService</strong> class.</p><p>If you haven’t worked with Blazor before, it’s important to note that Razor files contain both <strong>HTML markup</strong> and <strong>C# code</strong>. The C# code is placed inside the @code block.</p><p>To begin, we’ll inject the <strong>ChatService</strong> class (which we discussed earlier) into the Razor file, along with <strong>IJSRuntime</strong> for performing JavaScript operations.</p><p>Additionally, we’ll add the necessary @using directives to ensure we can access both the <strong>Message</strong> class and the <strong>ChatService</strong> within the Razor file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/0*gVDP5sZk-mLQL0XX" /></figure><p>All the UI needed for this application is shown in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nIppjw6RPRpLwKD5" /></figure><p>Lines 6 through 22 contain a &lt;div&gt; element with a scrollbar that displays all the messages. The appearance of each message is dynamically styled based on whether it is a request or a response, using distinct CSS classes for each type.</p><p>Line 24 contains the HTML markup for a button that clears the chat history within the scrollable box.</p><p>Lines 27 through 30 include an &lt;EditForm&gt; node, which renders a form element with a text area. This is where the user can type their prompt and send it to the API. Upon validation of the input, the form calls the SubmitChat method.</p><p>The screenshot below shows the implementation of both the SubmitChat method and the ClearChat method, the latter of which clears the list of messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wmgVtp3oBLymsvbu" /></figure><p>Below is a screenshot of the remaining methods inside the code area:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m5L0JrBETByw_-1-" /></figure><p>Lines 58 through 60 contain the logic to update the text area as the user types their prompt. This ensures that the text area is continuously updated with the input.</p><p>Lines 63 through 69 make use of the <strong>OnAfterRenderAsync</strong> lifecycle method (a Blazor lifecycle method) to invoke the addSubmitEnter JavaScript function via JavaScript interop.</p><p>Lines 71 through 78 define a class that contains the text for the chat input, helping structure the user interface for the chat feature.</p><p>With the <strong>Chat.razor</strong> file now complete, let’s move on to calling the <strong>Chat</strong> component from the <strong>Home.razor</strong> file. The code to integrate the component into the <strong>Home.razor</strong> file will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/0*GTc37MoK4MGWtsSL" /></figure><p>We also need the ChatService as a singleton service inside the Program.cs file like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*NwyyHltSTX3yD_Wz" /></figure><p>All the code that runs via JS interop is contained within the JSHelpers.js file, the code is shown in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q9GpDSlrJswyDyLN" /></figure><p>In the <strong>Chat.razor</strong> file, we can see the three methods being called to accomplish a variety of functionalities, such as handling message input, clearing chat, and submitting prompts to the API.</p><p>Additionally, the <strong>app.css</strong> stylesheet has been updated with the necessary CSS classes to ensure the data is rendered in an aesthetically pleasing way.</p><p>All of the code used in this tutorial is available on <a href="https://github.com/sramaswami11/RAGaaSWithGraphlit"><strong>GitHub</strong> <strong>Repository</strong></a> for reference and further exploration.</p><p><strong>Let the Magic Happen</strong></p><p>Now that we’ve walked through the code, it’s time to see it in action! Let’s run the app from the <strong>Visual Studio</strong> environment and take a look at how the initial screen appears:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U21Gc9rfr_G_XbJW" /></figure><p>In the text area, type <strong>“Summarize the contents of the IBD article ingested”</strong> and press <strong>Enter</strong>. This will send the prompt to Graphlit’s API. In the scrollable box on the page, you’ll see the prompt rendered in blue, followed by the response from the API below it. The output will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BkRm5hcFu0I7JGnh" /></figure><p>Let’s now ask a couple of follow-up questions. First, we prompt the system to <strong>list the companies mentioned, along with their ticker symbol and current stock price</strong>. The response will show <strong>CEG</strong> and <strong>NVDA</strong>, but it also notes that the article didn’t provide current stock prices. Fair enough!</p><p>Next, we rephrase the question to ask only for the <strong>company names and ticker symbols</strong>. The response will then focus solely on this information. As the conversation progresses, you’ll notice that the scrollable box automatically updates and scrolls, ensuring the latest request and response appear at the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LcJz_9uVDNP9bMsB" /></figure><p>That concludes this article. As always, we appreciate your feedback and look forward to bringing you more content in the next article. Thank you for taking the time to read this one.</p><p>To access all the code from this tutorial, please visit: <a href="https://github.com/sramaswami11/RAGaaSWithGraphlit">https://github.com/sramaswami11/RAGaaSWithGraphlit</a>.</p><p><strong>Happy New Year and Happy Coding!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53339d282534" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG to Riches: Using RAG with Kernel Memory]]></title>
            <link>https://medium.com/@sramaswami11/rag-to-riches-using-rag-with-kernel-memory-1bf23668b470?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bf23668b470</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Sat, 14 Dec 2024 17:51:16 GMT</pubDate>
            <atom:updated>2024-12-14T18:04:02.242Z</atom:updated>
            <content:encoded><![CDATA[<h3>RAG to Riches: Supercharge your app with RAG and Kernel Memory</h3><p>In this guide, we begin by discussing the shortcomings of LLMs like ChatGPT without augmenting it with an external data source , due to its very limited ability to browse the internet. Next, let us define some key concepts like RAG and Kernel Memory. We will then use Visual Studio and C# to implement code for ingesting a website and demonstrate how to query the ingested data to retrieve answers.</p><p><strong>Background</strong></p><p>ChatGPT-3, when released in November 2022, had limited capabilities outside of the data that it was trained with. To illustrate this, let’s ask it a question about the Roth IRA contribution limit for the year 2023. As shown below, ChatGPT-3 has no knowledge of events or information beyond January 2022.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/0*_n8pjPL8VG3bSa-h" /></figure><p>Lets now fast forward to Dec 2024 and we ask a similar question:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/0*oaaYTaWos69z8Nkn" /></figure><p>So, what exactly happened here?<br>This version of ChatGPT is equipped with tools such as browsing, file analysis, and advanced reasoning capabilities. These enhancements enable real-time internet searching and improved functionality for dynamic tasks. So we are definitely getting better results.</p><p>Let’s take this one step further. Here is my next prompt: asking it to read a webpage and summarize its content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*BuOUYVIUDzs9ScrO" /></figure><p>What happened this time? It appeared as though it could handle everything, but when given the actual webpage location, it failed to process it.</p><p>Let’s see if we can achieve our goal using RAG and another technology called Kernel Memory, a feature of Microsoft’s Semantic Kernel.</p><p><strong>What is RAG?</strong></p><p>Simply put, Retrieval-Augmented Generation (RAG) is a technique that enhances a large language model (LLM) by providing it with data retrieved from external sources — such as a web service, text file, or database. This additional data allows the LLM to generate answers to queries that cannot be addressed solely based on the information it learned during training.</p><p><strong>What is Kernel Memory?</strong></p><p>Kernel Memory (KM) is a multi-modal AI service optimized for efficient dataset indexing. It supports key functionalities such as Retrieval-Augmented Generation (RAG), synthetic memory, and prompt engineering. Seamlessly integrating with popular AI platforms, Kernel Memory enables natural language querying to retrieve indexed data, complete with citations.</p><p>It is versatile, capable of processing diverse data formats (e.g., PDFs, images, JSON, and Office documents), and supports various backends for storage and search.</p><p>The rest of this article focuses on how we implement RAG using Semantic Kernel in the .Net environment.</p><p><strong>Getting Started</strong></p><p>Let’s proceed by creating a console application using Visual Studio 2022. The first step is to obtain an OpenAI API key. Next, create a configuration file named appsettings.json and store the API key securely within it.</p><p>The appsettings.json file will look something like this (substitute your API key in place of xxxxx):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/0*r273EGWELyOWW0ag" /></figure><p>Next, click on the appsettings.json file in the <strong>Solution Explorer</strong>. In the <strong>Properties</strong> window, set the <strong>Copy to Output Directory</strong> property to <strong>Copy Always</strong>. This ensures that the file is copied to the appropriate directory where it needs to be available when the application is built and executed.</p><p><strong>Setting Up and Running the Kernel Memory Service</strong></p><p>Before making any other code changes, we need to set up and run the Kernel Memory service so that it is ready to receive requests from our application and provide responses. To do this, we need to create and set an environment variable called ASPNETCORE_ENVIRONMENT and assign it the value Development, as we are currently focusing on a development or test mode.</p><p>To run the Kernel Memory service, browse to the GitHub repository for Kernel Memory at <a href="https://github.com/microsoft/kernel-memory">https://github.com/microsoft/kernel-memory</a> and clone the code to your local machine.</p><p>Next, open a command prompt and navigate to the service/service directory. Once there, run the setup by issuing the following command:</p><p>Dotnet run setup</p><p>We won’t go into the details, as the steps are outlined on the webpage <a href="https://microsoft.github.io/kernel-memory/quickstart/configuration">https://microsoft.github.io/kernel-memory/quickstart/configuration</a>. For the most part, we will be using the default settings.</p><p>For this article, we are specifically using OpenAI (instead of Azure OpenAI). Be sure to enter the correct OpenAI key when prompted. Additionally, when asked for the logging level, enter “Information” (the default is “Warning”) so you can monitor the activity in detail.</p><p>Next, start the service by entering the following command:</p><p>dotnet run</p><p>If everything goes as expected, you should see something similar in your command window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2yQFLlSAkA3w7_zc" /></figure><p>The service essentially loads a set of handlers. By observing the command window, you can also see that the service is currently running on the local host at port 5000 (in this case).</p><p>You can access the Swagger UI by browsing to the following page:<br><a href="http://localhost:5000/swagger/index.html">http://localhost:5000/swagger/index.html</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pQmpyDKhl3BwTCnK" /></figure><p><strong>Back to the Code</strong></p><p>Now, while the service is running, let’s return to Visual Studio. We need to add three NuGet packages to the project:</p><ol><li><strong>Microsoft.Extensions.Configuration.Json</strong> — to read configuration data, such as the OpenAI key.</li><li><strong>Microsoft.KernelMemory.Core</strong> — to use Kernel Memory.</li><li><strong>Microsoft.KernelMemory.WebClient</strong> — to ingest data from a website.</li></ol><p>Here is the screenshot of the first part of the code: (for the complete code please refer to the Program.cs in the github repository specified at the end of this article)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eJ5NG9BhfoYUeEDP" /></figure><p>In lines 6–8, we are reading the configuration settings defined in the appsettings.json file and saving them in a config object (currently, it only contains the OpenAI key).</p><p>In line 10, we retrieve the OpenAI key stored in the config object.</p><p>In line 12, we instantiate a MemoryWebClient object, passing the URL of the service that we just launched.</p><p>If we examine the returned MemoryWebClient class, we can see several interesting methods, such as ImportDocumentAsync (for ingesting PDFs or other known format documents) and ImportWebPageAsync (for ingesting web pages).</p><p>For the purposes of this guide, we are using the ImportWebPageAsync method, which ingests a webpage specified by the URL (the first parameter) and sets a documentId of doc001.</p><p>BTW<strong>,</strong> please note that in line 14 (commented out), we have the logic to import a PDF document into memory. You can try that later as an exercise.</p><p>In lines 20 through 23, we are ensuring the document is ready before we proceed to ask questions.</p><p>Let us move on to the second part of the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UxRKSYqHzpXgNMqG" /></figure><p>In line 27, we are reading input from the console.</p><p>In line 29, we call AskAsync, passing the question to it, which returns an answer object.</p><p>In line 31, we display the answer using the Result member of the answer object.</p><p>In lines 35 through 37, we iterate through the RelevantSources collection to provide more information about the source from which the answer was obtained.</p><p><strong>It’s Showtime</strong></p><p>Now it’s time to run our code and it will prompt you to ask a question.</p><p>Here is a screenshot of a typical question/answer session:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JieFno_Hcyr8xwyr" /></figure><p><strong>Summary</strong></p><p>We walked through the process of integrating Kernel Memory with OpenAI to enable querying external data. We covered the setup of the Kernel Memory service, configuring the development environment in Visual Studio, and demonstrating how to ingest and query web data.</p><p>Access the full code here:<br><a href="https://github.com/sramaswami11/KernelMemory">https://github.com/sramaswami11/KernelMemory</a></p><p>Thanks for reading. Happy Coding Until Next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bf23668b470" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Semantic Kernel — Part 4 Go Local with local LLMs]]></title>
            <link>https://medium.com/@sramaswami11/mastering-semantic-kernel-part-4-go-local-with-local-llms-27be10c93f8c?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/27be10c93f8c</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Sun, 08 Dec 2024 22:58:12 GMT</pubDate>
            <atom:updated>2024-12-08T23:02:05.778Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Mastering Semantic Kernel Integration: Part 4 Go Local with local LLMs</strong></h3><p>In this article, we’ll talk about local LLMs, explore the benefits of deploying a local LLM (as opposed to using centralized options like OpenAI or Azure OpenAI). We’ll introduce a local LLM framework called <strong>Ollama</strong>, walk through the installation process, and demonstrate how to set up and use a local LLM. Finally, we’ll write and execute some C# code using Microsoft’s Semantic Kernel framework in the <strong>Visual Studio</strong> environment to get it running.</p><p><strong>Background</strong></p><p>There are at least two primary reasons why someone might prefer using a local LLM:</p><ol><li><strong>Control and Cost-Effectiveness</strong>:<br>Local LLMs can be deployed and used directly on your own hardware. They are cost-effective in the long run for high-volume or sustained usage, making them ideal for isolated or secure environments such as submarines, spacecraft, or private intranets.</li><li><strong>Low Latency and Offline Capability</strong>:<br>Since local LLMs operate on local hardware, there is minimal latency as data does not need to travel over the internet. This also enables them to function in offline mode, which is crucial in environments without reliable internet access.</li></ol><p><strong>What is Ollama?</strong></p><p>Now let us turn our attention to Ollama. What is <strong>Ollama</strong>?</p><p>Ollama is a platform that allows users to run large language models (LLMs) locally on their own machines. It is designed with a focus on <strong>privacy</strong>, <strong>efficiency</strong>, and <strong>ease of use</strong>, making it an excellent choice for those who want to harness the power of LLMs without relying on cloud-based solutions like OpenAI or Google.</p><p>One of the key technologies supported by Ollama is a high-performance, lightweight, open-source LLM framework. Ollama offers an excellent balance of efficiency and performance, making it well-suited for local deployment.</p><p><strong>Get your own local LLM</strong></p><p>To get started, open your browser and navigate to<a href="https://ollama.com/"> https://ollama.com/</a>. Download Ollama for Windows. Once the download is complete, double-click the installer to set it up on your local machine.</p><p>Now let us not forget that Ollama is only an <strong>environment</strong>, not an LLM itself. It serves as a platform for deploying and using LLMs. This raises an important question: <strong>Which LLM should you use?</strong></p><p>From the Ollama website, click on the “Models” link, which will take you to a page listing all the supported LLMs. Among these, you’ll find interesting options like <strong>“CodeLLaMA”</strong>, which can generate code from natural language prompts.</p><p>For this article, we’ll focus on a model called <strong>“Phi-3”</strong>, a family of models developed by Microsoft. The Phi-3 series includes two variants: <strong>mini</strong> and <strong>medium</strong>. In this guide, we’ll use the <strong>medium</strong> model to demonstrate its capabilities.</p><p><strong>Setup the LLM</strong></p><p>Open a Windows Command Prompt and type “ollama”. This will display the usage information, listing a variety of available commands. Among these, the most important for our purposes are <strong>pull</strong> and <strong>run</strong>, which we will use in this article.</p><p>Below is a screenshot showing what you’ll see in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/0*lrw0yAXknsupv7a0" /></figure><p>Next, type “ollama pull phi3:medium” in the Command Prompt. You should see an output similar to the one shown below in your command window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oo9ytvRG_btDqaJT" /></figure><p>To explore different models, their sizes, parameters, and the commands to run them in your environment, visit the <strong>Ollama GitHub</strong> page from the main website. Scroll down to the <strong>“Model Library”</strong> section, where you’ll find detailed information. For example, you can compare the <strong>mini</strong> and <strong>medium</strong> variants of the Phi model, including their respective number of parameters and model sizes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*TYKCCPQbFJmJ1e_Y" /></figure><p>Now let us go back to the command window and execute the run command and you will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/0*SN-yP7PaRLpdz35x" /></figure><p>We can start interacting with this LLM and you can see that the response is quick since it does not need to go through the internet to get a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/0*KEk_mOBH0XXJyduF" /></figure><p>We can keep interacting with this and see that this has very low latency compared to interacting with a cloud based model.</p><p><strong>Let’s do some Code</strong></p><p>Next let us use “Semantic kernel” and write some code to accomplish what we just did from the command line prompt. Below is the screenshot for all the code that you need to accomplish this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZRlpwfD-gYgBi1NA" /></figure><p>In order for the semantic Kernel to work, you need to install 2 nuget packages. They are “Microsoft.SemanticKernel” and “Microsoft.SemanticKernel.Connectors.Ollama”. Here is how it looks once they are installed into your project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mYRnrGoBALtRNBgb" /></figure><p>Now, let’s go over the code to understand what it does:</p><ol><li><strong>Kernel Builder</strong>:</li></ol><p>In line #6, we create a <strong>kernel builder</strong> object.</p><p><strong>2. Setting Up the Chat Completion Service</strong>:<br>In lines 9 through 13, we call the AddOllamaChatCompletion method on the kernelBuilder object. We pass two parameters: modelId and the endpoint where the LLM service is running locally. This call returns a <strong>kernel object</strong>.</p><p><strong>3. Get Required Service</strong>:<br>We then call the GetRequiredService method on the kernel object, passing it IChatCompletionService. This method creates the necessary service for sending a question to the LLM and receiving the response.</p><p><strong>4. Infinite Loop for User Interaction</strong>:<br>The code then enters an infinite loop where it continuously takes questions from the user. The question is passed as a parameter to the GetStreamingChatMessageContentAsync method of the chat service, along with the kernel object. This call returns the response from the model, which is then displayed in the console.</p><p>Now, let us go ahead and run this application, similar to what we saw before in the console, we will see a question answer loop looking something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/0*plW-fAs9M1rUXDQT" /></figure><p>That concludes this installment. As always, we appreciate your feedback on this article and look forward to seeing you all in the next part of this series. Thank you for taking the time to read this. To access all the code for this tutorial, please visit the following URL: <a href="https://github.com/sramaswami11/SKOllama">https://github.com/sramaswami11/SKOllama</a>. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27be10c93f8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Semantic Kernel Integration: Part3 Native Functions]]></title>
            <link>https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-part3-native-functions-1a315cc21c94?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a315cc21c94</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Tue, 05 Dec 2023 21:51:07 GMT</pubDate>
            <atom:updated>2023-12-05T21:51:07.133Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-part2-being-intent-ional-with-semantic-functions-eb593f66ceb4">Part 2</a> of this series, we explored how to construct plugins using Semantic Functions that communicate with AI services and yield valuable results. In this part, let’s delve into Native Functions.</p><p>If you recall <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-part2-being-intent-ional-with-semantic-functions-eb593f66ceb4">Part 2</a>, we employed a body metaphor for the application that integrates with the semantic kernel. In this metaphor, the semantic kernel is likened to the brain (the central orchestrator), the input is analogous to information received by the ears, and the resulting response is comparable to the output from the mouth.</p><p>Similarly, native functions can be thought of as the hands in this metaphor. They serve various purposes, such as persisting data to permanent storage like a file or database, retrieving data from a file or another location via a web service, or performing other operations involving complex mathematics that can be executed more efficiently through custom code written in C# or Python. This custom code may not represent the most efficient use of a Language Model.</p><p>Here is an illustration from the Microsoft Semantic Kernel documentation showcasing some of the actions performed using native functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*-_VZeJFwh1z321bT" /></figure><p>Let’s proceed to examine the mechanics of creating and calling these native functions. We are going to create two functions; the first one will convert a given temperature in Fahrenheit to Celsius. The second will read an in-memory dictionary of 10 cities and their high temperature in January. For the given two cities, it retrieves the temperature difference.</p><p>Before we create a project to demonstrate native functions, if you look at the <em>Init</em> class under the Common project, you will notice a few things. We have removed the two methods, <em>GetIntent</em> and <em>GetIntentTemplatized</em>, since the common library should not have knowledge about obtaining the intent. We have refactored the logic into two method overloads with the name RunKernelAsync. Each of these overloads will take four arguments: a kernel object, a contextVariables object (or an input string), a dictionary object storing the plugins, and the key to look up into the dictionary object. These methods essentially run the kernel’s <em>RunAsync</em> method, passing either the input or the context, and the appropriate plugin indexed into the dictionary object via the key passed. I have refactored this since these Run methods can be used whether we are running a semantic function or a native function.</p><p>Here is a screenshot illustrating the definitions of these overloads:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y9JJo7VYDi7SbWtO" /></figure><p>Next, let’s create a new project called “SK-Master3.” Just as we did in <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-part2-being-intent-ional-with-semantic-functions-eb593f66ceb4">Part 2</a>, we will create a “Plugins” folder, and underneath that, create a “WeatherPlugin” folder. Inside the “WeatherPlugin” folder, create a file called “weather.cs,” which will house our native functions.</p><p>The folder structure should resemble the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/0*3sjYc-hF0GDqcqPU" /></figure><p>In the class that houses native functions, each native function should be decorated with the attribute called <em>SKFunction</em> with a description that explains what the function will do. Let’s proceed and create our first native function, <em>ToCelsius</em>, which takes an argument called input that represents temperature in Fahrenheit and returns the equivalent value in Centigrade.</p><p>Here is a screenshot of the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eIPWyqUFTRFp1EUQ" /></figure><p>Now, we can navigate to the <em>Program.cs</em> and add code to first make a call to <em>ImportFunctions</em>() (Contrast this with Part 2 where we used the kernel method <em>ImportSemanticFunctionsFromDirectory</em> to import a bunch of semantic functions we configured in the plugins directory). We will pass it an instance of the Weather class and also the plugin name (in this case, it is “WeatherPlugin”). Afterward, we can use our helper function <em>RunKernelAsync</em> by passing the required parameters.</p><p>The code should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vrou7fRrXS_6myXC" /></figure><p>Executing the above code will output the Celsius value for a temperature input in Fahrenheit of 95 as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xdzpraJc6tEdWxVD" /></figure><p>Next, let’s proceed to the task of writing a native function that looks up a dictionary containing 10 cities and their maximum temperatures in January. From the given 2 city names, it will retrieve those values from the dictionary object and print the difference in temperature. If either of the cities is not in the dictionary object, it will print an error.</p><p>In our weather class, we first need to define a dictionary object called cityTemperatures to hold some cities and their average maximum temperature in January. This is shown in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jv_lfPD2MDc6LaF4u8EIxg.png" /></figure><p>Next, we will need a native function called <em>GetTemperatureDifference </em>that has two arguments, city1 and city2, and returns a double value. The logic is simple: if either one of the cities is not in the dictionary, it returns an invalid city message. Otherwise, it computes the difference in temperature between those two cities. Here is the code that accomplishes that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7uoOR_O_kqV_1pw3z3Wgg.png" /></figure><p>Next, let’s go back to the <em>Program.cs</em> and add the following code to first create the contextVariables object to provide the input cities, and then call our <em>RunKernelAsync </em>helper method to accomplish what we need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gBbrcHXjMjh5FLAm" /></figure><p>Executing the above code will produce the result as shown in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6PFIixS2KAmZ7c58" /></figure><p>Checking from our code above, we can see that the daytime high in January for Houston is 60, and for Atlanta, it is 53, so the difference is 7. Therefore, our native function has worked as intended.</p><p>That concludes this installment, folks. As always, we appreciate your feedback on this article and look forward to seeing you all in the next part of this series. Thank you for taking the time to read this. To access all the code for this tutorial, please visit the following URL: <a href="https://github.com/sramaswami11/Master-Semantic-Kernel-Step-By-Step/tree/main/SK-Master2"><em>https://github.com/sramaswami11/Master-Semantic-Kernel-Step-By-Step/tree/main/SK-Master2</em></a>. Specifically, take a look at the Common project to see the refactored methods, as well as the <em>SK-Master3</em> project to see the code specific to this part. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a315cc21c94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Semantic Kernel Integration: — Part2 Being “Intent”ional with Semantic Functions.]]></title>
            <link>https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-part2-being-intent-ional-with-semantic-functions-eb593f66ceb4?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb593f66ceb4</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Wed, 29 Nov 2023 17:30:27 GMT</pubDate>
            <atom:updated>2023-11-29T17:30:27.041Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Mastering Semantic Kernel Integration: — Part2 Being “Intent”ional with Semantic Functions.</strong></h3><p>In <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-a-step-by-step-guide-for-your-application-e51f2c91bcad">Part 1</a> of this series, we discussed LLMs, explored challenges in calling their APIs directly, and looked at high-level SDK tools like LangChain and Semantic Kernel. We examined the high-level architecture of Semantic Kernel and presented code samples in C#, importing functions built into the Semantic Kernel system. We showcased how to determine the Utc DateTime value and to summarize a given conversation.</p><p>In this part of the series, let’s delve into what a plugin is. Plugins are basic building blocks of Semantic Kernel, enabling developers to encapsulate features into a single unit of functionality run by the kernel. Plugins can essentially contain two types of functions:</p><ul><li>Semantic Functions: Communicate with AI services and return valuable results.</li><li>Native Functions: Developer’s code in C# or Python, which may not be optimal for an LLM to perform.</li></ul><p>Let’s briefly examine Semantic Functions and understand them at a high level. Native functions will be explored in another part of this series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m_SRpRordKf8KA13" /></figure><p>Reproducing the above image from Microsoft’s semantic kernel documentation page.</p><p>In the above illustration, a semantic function can be considered as the ear and mouth of the AI app. The function essentially lets the AI app listen to the requests from the user and respond back with a response in a language understandable by humans.</p><p>Semantic Functions can be either loaded inline along with your code that works with the kernel or, more commonly, can be created in a separate file. As an example, let us go ahead and see how to get the intent of a text that the user is sending as part of the request. The Semantic function that accomplishes this task is called GetIntent and will be a part of a plugin called OrchestratorPlugin. There are two files needed to accomplish this task, and they need to be placed in a certain way inside the runtime folder of your app.</p><p>All the plugins should go inside a “Plugins” folder and inside that folder, create another folder called “OrchestratorPlugin,” which should contain another folder called “GetIntent.” All these folder names are entirely arbitrary, and these names are just a suggestion. They can be anything as long as they mean something to you and the code accurately references them.</p><p>Inside the semantic function folder (in our case, “GetIntent”), you will be creating two files: skprompt.txt and config.json. The former contains the prompt that will be sent to the AI service, while the latter will contain the configuration required to run these functions.</p><p>Let us go ahead and launch Visual Studio 2022 and open the solution that we created in Part 1 of this series. You will notice a few changes:</p><p>We have created a new Common project that contains shareable code between multiple projects. This includes, for instance, the Setup() method which initializes the kernel.</p><p>We have also created a new project called SK-Master2, which essentially contains the code that will import the semantic functions we will be dealing with in this part.</p><p>After creating the folder structure and the files, here is how the hierarchy in which the semantic function files look like inside of your solution explorer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*ORD1ZlI7SeqWrsgE" /></figure><p>Here is how the skprompt.txt file will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bu4qjCNMIQ-KPAMI" /></figure><p>We are using a variable called <em>input</em> in the prompt which is configured in the accompanying config.json file and is used to pass the user’s input to the AI service.</p><p>Here is a screenshot of the configuration file config.json file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/0*w3T-qDj26cDtwozl" /></figure><p>Here are some of the key settings that need to be in the config.json:</p><p><em>type</em> — The type of prompt. In this case, we’re using the completion type.</p><p><em>description</em> — A description of what the prompt does.</p><p><em>completion</em> — The settings for completion models. For OpenAI models, this includes the max_tokens and temperature properties.</p><p><em>input</em> — Defines the variables that are used inside of the prompt (e.g., input which we just covered in the other file skprompt.txt).</p><p>Let’s go ahead and add 2 methods to the init.cs file under the Common project.</p><p>The first one is ImportPlugins, which takes 3 parameters: the kernel object, the pluginRoot (the root folder name we created for the plugins — in our case “Plugin”) and pluginTopDir (we created a subfolder called “OrchestratorPlugin” underneath the root).</p><p>This method first gets to the top level plugins folder and then calls the built-in function ImportSemanticFunctionsFromDirectory and returns the collection of all semantic functions (as of now, we just have one called “GetIntent”).</p><p>The second method that we added was GetIntent, which takes 2 parameters: the kernel object and the dictionary representing a plugin. Inside this method, we are first instantiating a ContextVariables object and setting the value for the variable “INPUT” which will be set in the INPUT variable inside the prompt (in skprompt.txt). We then run the kernel async method (RunAsync, remember from <a href="https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-a-step-by-step-guide-for-your-application-e51f2c91bcad">Part 1</a>?) and pass it the context variable and the plugin value from the dictionary for the plugin that we are interested in, in this case “GetIntent”. Here is how the code looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N0UF0npw1-9y2jnl" /></figure><p>Now let us call these methods from our new created project SK-Master2’s Program.cs code as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qHMTIi_J1r6qWnv1" /></figure><p>Running this code now will return the intent of the prompt as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yGX9DdVWXuGJw0vu" /></figure><p>It is nice to be able to get the intent of the user by running this semantic function, but this is not reusable. For instance, if we would like to run specific code based on the intent, we will need to constrain the output of this function. Enter templatizing functions:</p><p>One way to templatize semantic functions is to provide a list of options to choose from when we want it to output the intent. Let us create another folder under the OrchestratorPlugin folder called GetIntentTemp. We will also be creating the skprompt.txt and config.json files in there. Here is how the skprompt.txt file looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L9j4uVh4oBRZmXNN" /></figure><p>You can see that there is a variable called <em>options</em> that has been added to serve as a list of options for the LLM to choose from. There is also a <em>history</em> variable added so the previous conversation is included. Config.json file should have these variables updated. Here is how the config.json will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*4QyzbSURybuG6ydq" /></figure><p>We need to create a method in our Common project called GetIntentTemplatized() to provide a list of options to the GetIntent function. Here is how we do that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hppkZgMWIy4KhT-t" /></figure><p>In the above code, we are creating a ContextVariables object and setting the <em>input,history and options</em> variables. Finally we are passing the object into the kernel’s RunAsync function.</p><p>Next we add code in the Program.cs to call this newly created method just below our previously created code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*os4T1uenwqJ62TVL" /></figure><p>This is the output displayed upon running this code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NF2s1bNj6MkPO931" /></figure><p>That’s all for now, add a comment on what you think about this article. More features and more code on the semantic kernel will follow soon. Thanks for your time reading this! To see all the code for this tutorial please browse to the following URL:</p><p><a href="https://github.com/sramaswami11/Master-Semantic-Kernel-Step-By-Step/tree/main/SK-Master2">https://github.com/sramaswami11/Master-Semantic-Kernel-Step-By-Step/tree/main/SK-Master2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb593f66ceb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Semantic Kernel Integration: Part1 Core Plugins]]></title>
            <link>https://medium.com/@sramaswami11/mastering-semantic-kernel-integration-a-step-by-step-guide-for-your-application-e51f2c91bcad?source=rss-3c1885989691------2</link>
            <guid isPermaLink="false">https://medium.com/p/e51f2c91bcad</guid>
            <dc:creator><![CDATA[Siva Ramaswami]]></dc:creator>
            <pubDate>Sat, 18 Nov 2023 19:36:28 GMT</pubDate>
            <atom:updated>2023-11-25T16:54:01.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Unless you’ve been living under a rock for the past eleven months, most likely, you have played with OpenAI’s ChatGPT. Since ChatGPT was introduced to the public towards the end of November 2022, this resourceful tool has been utilized for multiple purposes, including (but not limited to) getting answers for your questions, improving your writing skills, learning new languages, cranking out code, and generating poems and jokes, just to name a few.</p><p>Tools like ChatGPT and Google’s BERT among others are examples of what are called as LLMs (short for “large language model”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/0*a2IqTeUT14jIEW4r" /></figure><p>While it is interesting to talk to these Large Language Models (LLM) like ChatGPT, the real value for app developers is the ability to integrate it into their business applications. Some of the best use cases one can conceive of include generating text, content moderation and summarization, spam filtering and sentiment analysis among others. LLMs like ChatGPT expose Application Programming Interfaces (APIs) to achieve these.</p><p>However, consuming the LLM APIs can be quite a challenging task. It puts a big onus on the developer to explicitly handle resources, allocate memory responsibly, and also implement any tools as they go through the integration process. This often results in overhead and technical debt that the app developer may consider to be an unneeded distraction from solving their core problem.</p><p>Luckily for application developers, powerful Software Development Kits (SDKs) are available to integrate LLMs into their business applications. Semantic Kernel (developed by Microsoft) and LangChain (developed by Harrison Chase) are the popular ones, which are also offered as open-source solutions</p><p>LangChain and Semantic Kernel are robust frameworks that facilitate business applications to be powered by the large language models. While they are similar in certain aspects, they have their own unique characteristics that can be tailored to specific requirements. LangChain is a powerful framework, built around a foundation of Python and JavaScript, offering a number of out-of-the-box tools and seamless integration options. In contrast, Semantic Kernel, on the other hand, is lightweight architecture, supporting not only Python but also C# and Java. Both have a great range of use cases and can be compelling toolkits for developers. As you may have guessed, the primary focus of this article, as well as several forthcoming pieces in this series, will be based on integrating with Semantic Kernel.</p><p><strong>Semantic Kernel Defined:</strong></p><p>Semantic Kernel is an open-source Software Development Kit (SDK) that facilitates combining AI services from providers like OpenAI, Azure OpenAI, and Hugging Face with conventional programming languages like C# and Python, resulting in AI apps that combine the best of both worlds.</p><p><strong>What is the Kernel in Semantic Kernel?</strong></p><p>Just as in an operating system, the kernel sits at the core of the operating system and manages resources, the semantic kernel orchestrates and manages various components that are crucial for the seamless execution of the code residing in an AI application. This orchestration involves managing configuration, services, plugins, and ensures that the native code and AI services work together to produce the desired outcome.</p><p><strong>Semantic Kernel the Orchestrator</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eQtY4A6Dmx-RaoPY" /></figure><p>Semantic Kernel flow is depicted in the above diagram. Let us examine the steps:</p><ul><li>Ask: This is the input user request to the semantic kernel. This could be a question the user can ask the LLM like ChatGPT.</li><li>Kernel: This component serves as the central control hub within the SDK, orchestrating the seamless integration and cohesion of other constituent elements, ultimately forming a comprehensive language application.</li><li>Skills (or Plugins): Skills have been recently renamed to “Plugins”. Plugins use prompts and configuration settings to establish communication with language models, and generate responses that can be integrated effectively into your application.</li><li>Memory — Ability of the system to retain and utilize knowledge or information from previous interactions or inputs.</li><li>Connectors — Enables your application to use external APIs to bring in data to enrich your application.</li><li>Planner — From the application’s code, you can have the semantic kernel to auto create the flow in order to solve a specific problem. Planner mixes and matches the plugins and connectors that are loaded into the kernel in order to create additional steps.</li><li>Get: Response that can be sent back to the user.</li></ul><p><strong>Tools needed to get started</strong></p><ul><li>VSCode or Visual Studio</li><li>An OpenAI key via either OpenAI or Azure OpenAI service</li><li>.Net 7 or .Net 8 SDK</li></ul><p>Additionally you can install Jupyter notebook if you would like to run the samples given in the Microsoft Semantic Kernel documentation website but that is beyond the scope of this article. If you already don’t have an API key, head over to <a href="https://openai.com/blog/openai-api">https://openai.com/blog/openai-api</a> , sign up for an API key and save it off at a safe location.</p><p>There are a number of tutorials available on the internet to get started with integrating Semantic Kernel in your application using VS code. In this article I will be focusing on building using Visual Studio (VS) 2022. If you already do not have VS installed on your machine, you can download the free community edition from Microsoft at this url: <a href="https://visualstudio.microsoft.com/vs/community/">https://visualstudio.microsoft.com/vs/community/</a></p><p>I will also be focusing on developing using the C# language and the windows operating system for the purposes of this article. We are also limiting ourselves (at least for now) to integrating with OpenAI as opposed to using Azure OpenAI</p><p>Now let us launch Visual Studio and click on “Create a new project”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7ycKuMYO2_F0YIJU" /></figure><p>In the “Create a new project” screen, select the Console template and click on “Next”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CKeqXnkQemIWoGvl" /></figure><p>In the Configure your new project screen, name your project and browse to the location where you want it to be created. Then hit Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kYejG_NeGrhKob6F" /></figure><p>In the Additional Information screen, select .Net 8.0 (Standard Term Support) as the framework and hit “Create”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4kGawenRC1rqJWkZ" /></figure><p>Now Visual studio will go ahead create the solution and project and also will generate some files and boiler plate code. The main file Program.cs file contains just a single line of code to print “Hello World” on the console.</p><p>Your screen will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hYzjtXwhWCeS5n31" /></figure><p>The next order of business would be to install a nuget package to use SemanticKernel in your application. From the Solution explorer, right click on the project and click on “Manage Nuget Package” and select the “Browse” tab and enter “SemanticKernel” at the search tab , make sure that we check the Include prerelease since SemanticKernel is still in pre release as of writing this article. Now you will see a bunch of nuget packages whose name starts with “Microsoft.SemanticKernel”. At the time of writing this article, SemanticKernel is beta5. Select this package from the list and click on “Install” as shown in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CoDezvIy8mA8PK-m" /></figure><p>Visual studio will display a window with “Preview Changes”, click on “Apply” .You may be prompted with a license acceptance dialog with additional packages that will also be installed into your project and you need to click on “I Accept” . Now the SemanticKernel package will be installed into your project. Now you are ready to start integrating with the semantic kernel.</p><p>If you now open the packages folder under your Dependencies project under your project, you will see that a package called “Microsoft.SemanticKernel” with version ending in beta5 as shown in the screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*-Nj9NRJdndpIcUoF" /></figure><p>In this part of the tutorial series, we are going to do the following:</p><ul><li>Initializing kernel</li><li>Importing a couple of in-built functions (aka core plugins) as plugins from the kernel object instance returned by the initialization process we saw in the previous step.</li><li>For each one of these functions imported, we will be passing the resulting handle into an asynchronous function call to run it and output the results on the console.</li></ul><p>Let’s proceed embarking on this journey:</p><p>Remove the generated greeting from Program.cs</p><p>As the first step outlined before, let us go ahead and add a function in Program.cs called Init which essentially returns a new instance of the kernel builder. Here is how the code from this step looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BDnwmElQH1WUcWEq" /></figure><p>The heart of the Semantic Kernel, the Kernel class has a static function called Builder which calls an Open AI service called WithOpenAIChatCompletionService. This service needs at least 2 parameters to be passed, one is the apiKey and the other the modelId. BTW, depending upon the beta version of the Semantic Kernel package installed, you may get a warning saying that the “KernelBuilder is obsolete”, and it may recommend you to use a different method. Ignore that for now, since SemanticKernel is a fast moving project and changes are taking place so quickly that it will be hard to keep up with the changes. So it is good to stay at a certain version unless the newer version offers additional goodness.</p><p>Now back to the parameters, modelId can be one of several models, in this case I have set it to be “gpt-3.5-turbo”. From Microsoft’s learn webpage on semantic kernel (<a href="https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/kernel/adding-services?tabs=Csharp">https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/kernel/adding-services?tabs=Csharp</a>) you can see that the following models and their corresponding model types are available:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/0*lFNa1cbJG2T6orwB" /></figure><p>It is also not a best practice to leave your OpenAI API key in the open like shown in this screenshot. I have done it this way just for quick demonstration purposes. The key should be stored in a secure location. For a more best practice guidance, please refer to the following webpage:</p><p><a href="https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety">https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety</a></p><p>Let’s now focus our attention to some of the out of the box core plugins that the Semantic Kernel Github repo has made available.</p><p>For a full list of such plugins checkout the following link:</p><p><a href="https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/plugins/out-of-the-box-plugins?tabs=Csharp">https://learn.microsoft.com/en-us/semantic-kernel/ai-orchestration/plugins/out-of-the-box-plugins?tabs=Csharp</a></p><p>Let’s import one of those core plugins here called TimePlugin and print the current UTC date and Time. Here is the Program.cs code that accomplishes this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t72XSzHtNU1EBf-6" /></figure><p>So, we are doing the following steps here:</p><ul><li>Call the Init() method that was shown in the previous screenshot which returns a kernel object.</li><li>From the kernel object, call the inbuilt method ImportFunctions and pass an instance of the TimePlugin. This call returns a dictionary of various semantic functions available as part of the time object.</li><li>We now call the RunAsync method from the kernel object and pass to it as an argument the particular semantic function present in the dictionary object, in this case the UtcNow</li><li>Print the Utc Date Time value.</li></ul><p>Running this from the visual studio yields the following result on the console.(you may get a different result based on when you run this).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W5cZ5jg4BVRoA-Lq" /></figure><p>Now let us go ahead and import one more core plugin , this time it is a plugin that summarizes a conversation between two people. Let us go ahead and add code to Program.cs right below where we added code previously to import and run the TimePlugin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*He7Isn0luJ-0-wTk" /></figure><p>The ChatTranscript is defined as a string containing the conversation between two persons at the top of the program.cs file as shown here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PMRTZ0mM5hjfHNcf" /></figure><p>Running the above code produces the output as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/0*VByBmi3YpmNTPCs5" /></figure><p>That’s all folks, look forward to hearing from you on what you think about this article. More features and more code on the semantic kernel will follow soon. Thanks for your time reading this! To see all the code for this tutorial please browse to the following URL:</p><p><a href="https://github.com/sramaswami11/Master-Semantic-Kernel-Step-By-Step">https://github.com/sramaswami11/Master-Semantic-Kernel-Step-By-Step</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e51f2c91bcad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>