BrandGhost

OpenAI Web APIs in .NET C# - Refactoring

This video is the second of a multi-part video series where I explore working with OpenAI's web APIs! This is all done in C# and #dotnet. Join me as I try to explore OpenAI's web API in C#! This entire video is me experimenting and given that I am very new to many concepts in AI, I make many incorrect assumptions. The purpose of this video is: - Looking at some previously written code to access Open AI - How I am approaching refactoring this code It's worth noting again that I make incorrect a...
View Transcript
I wanted to focus on instead in this video that I just started refactoring basically all of the the test code that I had to kind of play with the API and I started forming it into what I will probably end up releasing as an open source library for interacting with open AI um their public API that they have so what we can start looking at here what that I have on screen is this key which I'm going to have to delete after the video but this is sort of the skeleton that I had before for kind of my use case where I wanted to upload some training data it's not really important because this is the part that's very specific to my use case what is kind of neat though in the focus that I want to have today is that I have this open AI folder here which is where I've actually started building out the API that I plan on releasing so um I guess where we should start is maybe looking at some of the use case here so let me just blow away some of this code off the screen but what we would do is get a couple of factories put together and I'll probably release an auto fact package as well because in all of my use cases I just want things set up through Auto fact and never have to actually type anything like this so um I will likely put these two factories behind um Auto fact and then basically you'll just be able to resolve the interface for this API client Factory so that will come you'll probably still have to create a a configuration I don't know what other parameters we might need but to start just your API key is so far all that I've kind of seen is necessary so it should be pretty easy to instantiate and then what I will have is um this type of syntax here where you can see like we have this client and then files right after it will um correlate to the documentation that open AI has so in particular open AI has all their sections broken out um into separate topics and it seemed like a really intuitive way to navigate so I will likely continue to do that so what we will have is access to something like files for example and then I'm going and implementing all of the API calls that their files API has so for example I'm going to jump over right into the implementation of list all let me go ahead and just collapse this so we can kind of see where we're at if you're looking at the name spaces and stuff no I'm not going to release it under lower bot I'll come up with something and publish the package but this is just because of where things are right now and it looks like the you know the hacky refactoring I've done so far hasn't even updated any of the name spaces for the folder so if you're looking at that don't worry I'll have it fixed up and it'll be pretty so this files API client though if we look at the public methods that we have on here so I'm just going to highlight quickly these ones um that's basically what they have published on their spec and um I'm gonna go Implement these such that they're a little bit more Rich than what I was showing in my previous video so in the previous video I was basically saying like look for example I want to upload a file and when I do that I only care about the ID like nothing else for now I just want to see if it works but I'm actually going to go and build out um basically having full type resolution so that we can deserialize the responses and then have a lot more robust information coming back so for example when you call this upload a sync method I'm just going to go show you where I'm calling it from right so um I'm uploading this test underscore prepared Json L file and if we look at the upload result we can see that it is of type file info so it does actually have more information than just the ID and sorry I'm jumping around a little bit here I'm just going to go to the definition of file info but you can see I'm using records here so it'll have an ID I might do a little bit of renaming because I don't like just seeing things like bytes like it's supposed to be like file size or like content size I guess but they just have bytes so far I'm kind of keeping it mapped I did make an exception here for even like they have a created at timestamp and it's a it's an Epoch number so I basically just gone and converted it to a date time and indicated that it's UTC so I might do a little bit of tweaking just to make it read a little bit uh better in my opinion but I do plan on putting in uh like full type resolution so that there's a lot of uh a lot more info than what I originally put in my last video or it was just like grabbing the most simple stuff I haven't looked into all of the different errors and things that can come back so I'm probably gonna have to do a bunch of revisions but um this is sort of the flow for how it will get used so um you know with respect to the syntax here so using um basically like these they're not name spaces but like these uh sub components of the actual overall client itself just because like I said they did a good job mapping it in their API spec and it felt really good I thought um so far I've got files done um and I think fine tunes but models completions are still I still have to do a bit of mapping with the the types so it's kind of tedious but I'll sort that out and then there's a handful of other things that open AI offers as part of their API and I'll have to follow up with that because I haven't used them and it's a little bit awkward for me to go basically Implement them and not really know what they're doing yet so I'll poke through them and if it feels like they're pretty straightforward for me to actually try out and then I'll go ahead and add them if not it might be something that I have to follow up with later when there's more time so I think that's mostly it I just wanted to show that you have like full C sharp Syntax for this kind of stuff which I'm happy about we'll probably do an auto fact package like I said just so you can resolve the interface for this one and then call create with with your config and boom you have all of the open AI API access you could want so I think that's it thanks so much for watching if you thought this was useful please give the video a thumbs up leave a comment below if you have any thoughts about the different um API methods that you'd be interested in using and of course if you enjoy the content on the Channel Please Subscribe it helps a lot so thanks

Frequently Asked Questions

What is the purpose of the open source library you are creating?

I'm creating this open source library to provide an intuitive way for developers to interact with the OpenAI public API using .NET C#. It will help streamline the process of making API calls and managing responses.

How will you handle the configuration for the API client?

The API client will require an API key for configuration, and I plan to implement an AutoFact package to simplify the setup process. This way, developers can easily resolve the interface for the API client without having to type out extensive configuration code.

What features can we expect in the library regarding API calls?

You can expect a robust implementation of the API calls, including full type resolution for responses. This means that when you make a call, you'll receive detailed information beyond just the ID, such as file size and timestamps, making it easier to work with the data returned from the API.

These FAQs were generated by AI from the video transcript.
An error has occurred. This application may no longer respond until reloaded. Reload