Calling API for Train your Own Enterprise Data with Azure OpenAI Service | ChatGPT Azure OpenAI API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back this is the on-demand video that we'll be creating we had created a video where you can train your custom Enterprise data using Azure open AI services and cognitive search now I would like to explore how we can call that API from our custom application if you don't know about the video that I'm talking about so this is the one train your own Enterprise data with Azure open AI service so we will be trying to explore how we can call the API from Postman as well as from a custom application for custom application I'll be building uh chatbot using Microsoft bot framework and then I'll be calling this particular API okay so let's dive into so to get started first of all we need Azure open AI resource let's create one quickly thank you and we also need a cognitive search resource so by the time this process is executing let me create a cognitive search Resource as well and I'll be picking up the free pricing Tire and review and create uh no okay let's use a free pricing tag for now okay okay I think I already have a free pricing Tire in the subscription so that's fine I'll be using the same free pricing tag yeah this is a cognitive search results okay so let's go to Azure open AI Studio go to chat create a new deployment of 3.5 Turbo let me use the same name so once we have our open air model deployed we can go to add your data add source let's search Azure cognitive search oh okay free tire is not supported that means we have to create a cognitive search resource I thought earlier [Music] we could create this on free pricing Tire but that's fine let's create one I'll be picking up the basic and review and create okay I have my document ready so I'll be picking up this hackathon in guidelines document so that's msme idea hackathon for women innovators so I'll be picking up this particular document to train and to do that I also need a storage account let me create that here now okay so let's wait for that deployment to get completed by the time let me show you few things the first thing is if you only need the chat GPT source code you can click on view code and whatever programming language you are interested in you can pick that from here currently Python and C sharp are the ones and if at all you want to implement in another language you can look at this curl command for all the properties that are required if you want so want the Json body you can click on this Json and this will contain the Json body if if I interact with the bot the code will automatically update so see here now the Json body is updated the first element in the Json body is a system message you can update that and this is a user message you can leave this blank while calling your first request and if I go to C sharp it uses the this dot Azure AI open AI library that is still in preview you will not find in the new git package manager you need to install it through the command line okay and if you're a python developer then yeah open AI libraries are already there okay yeah I think it's still in preview but you can find that all right let me quickly check the state of sub storage account yes it's done let's go to storage browser add a new container the container that I'll name this as data and inside this container I am going to upload my document let me drag and drop foreign upload a perfect now I can just add a source select as your blob storage Azure blob resource I think it's still not updated I need to refresh the page Okay add your data source blob storage okay there it is maybe some cash okay there we have our resource name let me give the name as MSM index next save and close it will take a minute and even less to train our data and by the time let me just open the inspect tool because I want to know how the API calls are being made and let's wait for this pre-processing to get completed and then we can get started okay we have our data source connected you can also see the index details like how many chunks it has converted our data into if you see the number of documents that are converted that I've created from my main document and it says 0 okay let's see if something is there in there yes it is there chunk id102 so there are three chunks that are created for my document okay that's good now I can close this window and now let's start interacting with the chatbot first of all I would like to know how to apply to M SME hackathon yeah this much of latency is expected as you all know the open AI models but yeah sometimes there is an issue with this chat playground it doesn't get the response if you ask the same question you can stop processing this request and ask it again and there we have to apply for the msme idea hackathon and do this and this but the thing that we need is this one okay that's the request URL extension chat completions and it takes the API key that's fine payload this is important piece this is very important let me copy this payload open by Notepad paste it here okay and the best is let me put that to Postman this will be a post request let's save that raw Json let's paste this one and let me format this uh so that I can view it in nice formatted way a new file data dot Json format document prettier perfect okay let me copy this and paste it here in the postman okay yeah so in order to call the API this is the important piece the data source because your chat GPT model Azure chat CPT model may not know what data source you are targeting to so this is a new object that needs to be passed in the Json body this is my end point this is the cognitive search and this is a cognitive search API key this is my index if at all I have configured the semantic configuration in cognitive search then you can put that configuration name here okay and yeah this is a system message and let me remove this and go to code copy the end point paste it here also copy the API key go to curl operation so API Dash key is my header key let's add that API Dash key okay I guess we are ready let's send it your request contained invalid Json expecting value line 19 column three okay line 19 column three care okay I think that's uh extra comma unrecognized request argument supplied data sources and deployment okay unrecognized request arguments Let's cross check what request has been made Let's copy exactly the same one and see if there is some difference yes there is a difference that's extension slash chat slash completion let's see if this works okay something is working I guess this is a streaming data I'm assuming that connection closed okay I think that's a streaming data yeah so choices Delta done let's see the next request content question mark content questions okay content other let's see the last one let's see the timestamp 1948 58 okay that's the starting point connected to to yeah this should be the one roll tool contend them for women okay that's citations and let me cross check what type of data is in because that's streaming data okay ah okay this is one property here uh in order to not to get the streaming data let's see where is that property um let's see the official documentation Azure open AI what's new Azure open AI with your data and yeah this one streaming data stream let's add this property as well and let's make it false okay let's try this um no still it's taking the streaming um is that the correct one let me add it here that will be much better stream false uh is the name correct yes message is messages deployment oh yeah it's already there Stream True let me make this as false hoping this should get me a single Json perfect perfect this is good okay so we have a tool that gets us the citations and we have the content role assistant and this is the perfect answer that we got through the API this is really cool but yeah it takes almost seven seconds delay and let me ask some other question I can also include the history if I want I just need to copy paste this object into here and then create a history okay and let me ask another question what are the themes available okay okay and there's a msme hackathon the themes for the hackathons are agriculture reverse ocean okay this is a good good answer it's a good answer okay at least we know how to call the API using the streaming endpoint as well as without streaming endpoint initially by mistakenly we tried the streaming one and it did good it did provide us with a response okay and this time let's drive using the coding okay we have explored how we can call this API from the postman now it's time to call from our c-sharp code through my custom application okay so if you look at on the right hand side you can also see the code given by the postman for almost all the languages and I'll be picking up C sharp using the HTTP client and this is a ready-made code available uh also I can also make use of this one C sharp Library but I am not sure about the properties to set apart from chat completion options but yeah I'll be making a standard API call using this code okay let's try that okay I do not have my Microsoft board frame templates so what I'll do I'll pick up my existing implementation of open AI bot this uses a completion API that is Darwin C 003 model and I would like to modify this okay so I just need to modify this particular statement let me comment that out and let's say Azure open [Music] AI response okay call azure chat GPT and I'll be passing the input prompt that is uh the message sent by the user let's create a method out of this okay this is the method and the return type is string oops oh it has to be async okay let's make this method as a thing that's let's use a standard naming convention okay and now let's copy paste the code from The Postman perfect uh client HTTP client HTTP post this is my endpoint URI API key then this is the whole body and I would like to change um okay let me copy the body manually because I want to add my custom data inside that body so let me remove till here add interpolation and paste it okay the good part is Visual Studio automatically adds this uh Escape string Escape characters and where is my input GPT user content yeah this is input that needs to be dynamic so the name is input prompt if at all uh you want to make other fields come from the configuration file such as cognitive search URL cognitive search API key you can pass it through the configuration file that's the recommended way but this is just a POC for quick demonstration how this works I'll be just hard coding them in the code okay and this statement I would like to be added okay um let me add it here first War result equals to read as strain let's get rid of this statement and let me surround this in a try catch block okay let's copy paste okay and if at all any exception has occurred let's return null if there is no exception we would like to Powers this result and we need to get the response from here that is choices and it is on the index 2. sorry index one role content okay let's try that return Json object choices index one then content okay that's that's the one I can type cast that with string okay so this I'll be returning all right and that is all I guess okay what's the issue here the name prompt result does not exist because we change the property name let's rename that okay let's execute this and test it out in order to test this let's open the emulator foreign how to apply to msme hackathon okay so I'm having some trouble so let's try to debug what exactly is the issue I am going to put a breakpoint here and also let me put a breakpoint here okay let's see what's the issue so basically it's returning me null I'm assuming the issue will be there in the passing but let's see msme themes okay let's continue let's step over API key body content send request let's see what is output of that request yeah it takes time even on the online portal it took almost uh 7 to 10 seconds but here uh since it is debugging that's why it's taking more time okay the request is still pending thread destroyed how can just that be that's okay let me put a breakpoint here and this time let me restart the conversation themes of msme this time I will not stop there let me continue okay there we have 200 okay so we scored the response let's read that and yes we do have some response let's see um choices is my object okay and that is in index one yes then content I don't find any information related to the question from the fetch document okay that's fine we can change the prompt but still we are getting some response let me close this okay pass say something some issue with that Gateway timeout okay that means I need to do it quickly and let me now remove the breakpoint from there and put it there what are the themes of msme let's continue [Music] okay let's pass it okay and let's see ah index out of range must be non-negative and less than the size of the collection um how the index is out of range let's see okay okay okay a parts result this is a parse result okay so it is coming under messages not under choices and that is strange but it was coming under choices right ah yeah inside choices I have messages and inside messages and I have that so messages is again an array okay got it let me remove this uh inside choices uh that's a first index that is index 0 inside that I have messages and messages is the index one okay let's try this out how to apply to msme perfect perfect now we're getting some response let's ask something what are the themes of msme okay that's fine uh okay let's ask our standard question Who is the fastest man alive it should not answer that and it is answering that that's not good um but somewhere uh there must be a property which says that uh it should reply it from the data source and not from outside hmm um let me ask this question that we have asked though there is an msme idea in the themes are so it is actually giving us a response uh so we are good here we can close this session and I hope you know how to call this API I just gave you an example of calling this from Microsoft Word framework but if you're a front-end expert you can utilize that streaming endpoint and do it step by step in a very Dynamic way so Microsoft already has that implementation available you can just deploy this solution and you will automatically have a web application created for you okay so that is all see you in the next video thanks everyone
Info
Channel: Dewiride Technologies
Views: 2,756
Rating: undefined out of 5
Keywords: Azure, Open AI, Search Demo, ChatGPT, enterprise data, training, chatbot, AI, machine learning, NLP, natural language processing, artificial intelligence, tutorial, setup, custom knowledge, cloud computing, Azure services, Microsoft, azure search, openai, bot, train own data chatgpt, chatgpt train custom data, use own data in chatgpt, enterprise data in chatgpt, cognitive search, vector db, train custom data, chatgpt train own data, azure open ai train data, open ai, api, chatgpt api
Id: itbTh5Sqmbw
Channel Id: undefined
Length: 34min 57sec (2097 seconds)
Published: Fri Jul 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.