AI calling pattern

To call OpenAI's API (like ChatGPT API) using C# programming language, here's a step-by-step guide: Step 1: Create an OpenAI Account and Get an API Key Go to OpenAI's website. Create an account or log in. Navigate to the API section and generate an API key. Make sure to copy and save it securely. Step 2: Set Up Your C# Environment Ensure you have Visual Studio installed or any preferred IDE for C# development. Create a new project (Console App or Web App based on your need). Install necessary libraries such as System.Net.Http for making HTTP requests. Step 3: Install Required Packages Using NuGet Package Manager, install the package for HTTP client functionality, like RestSharp or similar. Run the command below in the NuGet Package Manager Console: Install-Package RestSharp Step 4: Write C# Code to Call the OpenAI API Here is a sample implementation for making a POST request to OpenAI's API: using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace OpenAI_API_Demo { class Program { static async Task Main(string[] args) { string apiKey = "your_openai_api_key"; // Replace with your API Key string apiEndpoint = "https://api.openai.com/v1/chat/completions"; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); var requestData = new { model = "gpt-3.5-turbo", // Replace with the model you want to use messages = new[] { new { role = "system", content = "You are a helpful assistant." }, new { role = "user", content = "Write an example API call using C#." } } }; string json = JsonConvert.SerializeObject(requestData); var content = new StringContent(json, Encoding.UTF8, "application/json"); try { HttpResponseMessage response = await client.PostAsync(apiEndpoint, content); string responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine("Response:"); Console.WriteLine(responseString); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } } } } Step 5: Run and Test Replace your_openai_api_key with the actual API key obtained in Step 1. Run the program. Observe the output response from OpenAI's API in the console. Step 6: Handle Response The API will return a JSON response with the model's completion. You can parse it to extract useful information. For instance, use the Newtonsoft.Json package to deserialize the JSON. Notes: Ensure you follow OpenAI API Documentation to understand the endpoint options, parameters, and available models. Use environment variables or secure storage for your API key to enhance security. some api need you to buy some credits first, be wise for your pocket many api do the same things so use this as a pattern

ChatGPT AI alternative

When building solution in AI for your application you might visit the ChatGPT API. However, if you need some alternative AI.  Here are some notable alternatives to the ChatGPT API that you might find useful, depending on your needs: Claude AI by Anthropic: Known for its large context window (up to 200,000 tokens) and creative writing capabilities. Offers multimodal support, allowing both text and image inputs. Google Gemini: Excels in real-time internet integration for up-to-date responses. Versatile for tasks like document summarization, creative content generation, and language translation. Microsoft Azure OpenAI Service: Provides access to OpenAI models like GPT-4 and Codex. Offers enterprise-grade security and scalability. Hugging Face Transformers: Open-source library with a wide range of pre-trained models for natural language processing. Highly customizable for specific use cases. IBM Watson Assistant: Focused on enterprise solutions with robust integration capabilities. Offers tools for building conversational AI tailored to business needs. Perplexity AI: Designed for answering complex queries with a focus on reasoning and contextual understanding. Each of these APIs has unique strengths, so the best choice depends on your specific requirements, such as creativity, scalability, or integration capabilities. The good news is Claude AI, Gemini, Hugging, IBM, and Dialog flow provides free tier so you can get started without worry your bank account!

The easiest way to create NLP Solution with Azure AI Language

When you want to create a solution that uses natural language processing (NLP), you can use a lot of open-source libraries. However, if you take a closer look at the Azure AI, they have NLP features through Azure AI language, and it starts from FREE.   Natural Language Processing (NLP) development with Azure AI involves utilizing Microsoft's suite of tools and services to build, deploy, and manage NLP models and applications. Azure offers a range of NLP-related services such as Azure Cognitive Services, Azure Machine Learning, and Azure Databricks, which provide capabilities for language understanding, sentiment analysis, named entity recognition, and more.   Using Azure AI for NLP development allows developers to harness the power of pre-built models and APIs for common NLP tasks, as well as the flexibility to build custom NLP models using machine learning frameworks like TensorFlow and PyTorch on Azure Machine Learning. Additionally, Azure provides infrastructure and tools for data processing, model training, and deployment, making it a comprehensive platform for NLP development.   By leveraging Azure AI for NLP development, businesses and developers can expedite the creation of language-aware applications, automate text analysis workflows, and gain insights from unstructured data sources. Azure's robust security and compliance features also ensure that NLP applications built on the platform adhere to industry standards and best practices. Overall, Azure AI empowers developers to create sophisticated NLP solutions while benefiting from the scalability, reliability, and performance of the Azure cloud platform. To create an Azure AI Language project using Visual Studio, follow these steps:   Provision Azure Resources: Create an Azure Subscription (you can create one for free). Log into Language Studio. If it’s your first time logging in, choose a language resource and select “Create a new language resource.” Provide details such as name, location, and resource group. Use Language Studio with Your Own Text: Once you’re ready to use Language Studio features on your text data, you’ll need an Azure AI-language resource for authentication and billing. I recommend you do not need to activate this because it needs to be paid, but of course, I recommend you to subscribe when the transaction goes up. Follow the setup process to create your resource. You can then call REST APIs and use client libraries programmatically. You can see a lot examples here Language Studio - Microsoft Azure Remember to choose a location for your Azure AI language resources so the latency of the resources   Some NLP scenarios that you can expect: Extract information that comes from the document/text. For example, you want to understand the main topic or contribution of an article Classify text for sentiment analysis, language detection, and custom text classification. For example, you want to moderate content in the forum Question and answer. For example, creating a Bot for simple question-and-answer. Summarize information. For example, you want to create meeting notes based on the meeting documents / conversational text Customize translation. For example, you want to create a translation of a natural language to cat language :D  

AI Learning Path for Novice

Learning AI by Doing It As a person who does not have a perfect background on Mathematics and Basic Science, learning AI is somewhat challenging. However, AI is not a new kid on the block. If you want to start to learn AI by today, you shall find numerous things to learn and it will become complicated. On this article, I want to share about how to learn AI with the minimum effort at the beginning and then increasing based on your need. I split the steps into three major steps: Level 1 (Fundamental), Level 2 (Associate), and Level 3 (Expert). As a case study, I use Microsoft ecosystem to start the learning process. Let's get started. Level 1 Fundamental Start to learn what is AI all about. Think the AI as a solution rather than a set of mechanism / process. On this level, you should learn what AI impact in the society. On this level, you will learn AI as a black box that empower you to do more. You can start by understanding the AI on Azure. If you want to learn how AI is applied in the cloud computing. After you grab the fundamental, try to explore which one do you find most interested to understand. If you interest with image / audio / visual, you can start learning how to use AI on computer vision If you interest with speech / text / understand the meaning, you can start learning how to use AI on natural language processing If you interest with chatbot, you can start learning how to use AI on chatbot Enriching your knowledge about the AI in this MOOC Course After you grab the fundamental knowledge my recommendation is to join AI-900 exam to validate your knowledge. medianet_width = "600"; medianet_height = "250"; medianet_crid = "858385152"; medianet_versionId = "3111299"; Level 2 Associate On this level, you will learn how to develop customized AI solution based on the 'existing' model. You will need Microsoft Cognitive Services. It is a set of services that can be extended to provide a set of AI service. Azure Machine Learning Studio. It is a tool to design, develop, and deploy the AI solution. You can start the learning process by Understanding the role and the benefit of cognitive services. Azure Cognitive Language Services Azure Cognitive Speech Services Azure Vision Services Azure Decisions Azure Search Creating a model with Azure Machine Learning Studio by learning this course to learn Try to build the classification model Try to build the clustering model Try to build the regression model After this course, you can join AI-100 exam to validate your knowledge as AI engineer Level 3 Expert On this level, you will learn custom development of AI solution based on the 'niche' problems that need you to build the model from the scratch. You will need Visual Studio / Visual Studio Codes. SQL Server / Azure Data Lake / Azure Storage or any data solution that can help you to build and to maintain your model. You can start the learning process by Understanding the option to build machine learning Choosing the right tools If your computer is not sufficient you can try the Data Science Virtual Machine If your computer is good enough you can build the AI Solution with AI tools with Visual Studio Learn ML.NET if you are .NET developer, I recommend you to use Visual Studio 2019 or newer. Learn Python if you are non .NET developer, I recommend you to use Visual Studio Codes. There is a lot of option to learn after this. For example, you can learn how Deep learning, AI on IOT, AI works on data analytics, how to use ML Flow in Databricks, or using R as your choice of your programming language. After this course, my recommendation is to visit Azure Architecture Center to understand the recommended architecture to build better solution. You can learn further by clicking the links. medianet_width = "600"; medianet_height = "250"; medianet_crid = "858385152"; medianet_versionId = "3111299";

Topics Highlights

About @ridife

This blog will be dedicated to integrate a knowledge between academic and industry need in the Software Engineering, DevOps, Cloud Computing and Microsoft 365 platform. Enjoy this blog and let's get in touch in any social media.

Month List

Visitor