OpenAI Assistant API for File Analysis - Full C# / .NET Code Tutorial

preview_player
Показать описание
How to build a custom C# / .NET console app that analyses the contents of files using either the Azure OpenAI service or the OpenAI API. In this app we will upload a PDF file to the OpenAI Assistant API service and ask it questions about the file.

0:00 Uploading a local file to the OpenAI Assistant
4:00 Creating the OpenAI Assistant and starting a Thread
6:40 Analysing the provided PDF files with natural language queries using the Assistant

#openai #csharp #dotnet
Рекомендации по теме
Комментарии
Автор

If it wasn't for your video, I don't know where I would be with my project. Thanks

tanakamawere
Автор

you've revived my love for coding :)

m.houdeib
Автор

Nice video Ted. There's a lot of looping and id tracking for a simple question and answer scenario. I hope they improve the API to simplify this at some stage.

dpbt
Автор

I am just following this code, but getting error while uploading the file at line # 25. I updated the code like this " var fileUploadResponse = await client.UploadFileAsync(File.Open(filename, FileMode.Open), its working now . Thank you for this video.

PAJANI
Автор

Is anyone else out there using OpenAI with C# code? How are you getting on?

edandersen
Автор

If the costs are still token based this can get expensive. Seeing that some documents may contain hundreds of pages whereas the relevant data you are looking for might only be in 5 to 10 of those pages. I suppose it also comes down to how many documents you will be processing daily or infact monthly as that is typically how you will be billed by Mr Gates. Do you perhaps have an up to date cost analysis video or resource I can check on costing for the assistant api? We recently did costing for the Document Intelligence studio thingy and it basically boils down to 2 pounds 50 per document to process. So you can imagine if your business does thousands of documents per month what the end cost will run to.

debeerpaul
Автор

this is so informative, but i do have the requirement of a pdf like a microwave / fan manual (images not text) uploaded and ask questions about the the assembly instructions or trouble shooting etc ... I cudnt make it work for images, when i upload a normal pdf which does have text it is working fine ... can you do anything that wud be of gr8 help ... thanks

MrRaviEdara
Автор

I know this is in beta, but could you do more scenarios or a walk-through of the assistants package since there are no docs for it? I am trying to make a web chat ui using Blazor like copilot and it's giving me headaches... I wanted this functionality to be on my API but can't because threads have to be managed and all so it has to be local.... or I am not smart enough to make it work...

tanakamawere
Автор

Do you know how to specify the endpoint for OpenAI instead of Azure's ?

I don't see a place to specify this nor a place to specify OpenAI's key using this library.

I'm using the code in your repository w/ only this change (non-Azure):

// OpenAI API
var client = new AssistantsClient(APIKey);

It's definitely hitting some endpoint, but I am not sure which one. I get the following error every time:

Unhandled exception. Azure.RequestFailedException: Additional properties are not allowed ('filename' was unexpected)
Status: 400 (Bad Request)

Content:
{
"error": {
"message": "Additional properties are not allowed ('filename' was unexpected)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}

Any ideas?
I'd use Azure, but cannot as they do not accept debit cards.

davestorm
Автор

Hi @TedsTech

Firstly, thanks for the wonderful video on Assistants. Really helps. However, I have few roadblocks and have been trying to sort for last 2-3 days and apprciate your guidance here.

The solution, whatever you have provided worked defintiely for PDF file, but when I am upload the docx file, the upload says successful, but unfortunately, i am unable to extract any information from the file. Also, to double check, i checked those files in the data file section (Azure Open AI Studio -> Data Files). I see those files and in processed state, when but i try to download them, I see Download Failure error.

I tried converting the docx file to jsonl and push it again, again same result.
Convert the docx to pdf, still same error

But when i try to convert a genuine pdf from internet, it works.

Any inputs here, will help!

pratapbontha
Автор

Thanks so much for this, looks good however at await client.UploadFileAsync I am getting an error Azure.RequestFailedException 'additional properties not allowed ('filename' was unexpected) 400 (bad request). I am using the openai apikey method. Any thoughts?

prmagic
Автор

This was nice.
Can you please let me know how we could do this in web api application so that it shouldn't be creating new thread session and new assistant everytime user asks a question.

chiragsheth
Автор

Love to see how to do this without Azure account, just an OpenAI API account (already have, why spend more $$$)

davestorm
Автор

D:\New folder\ConsoleApp1>dotnet run "/New folder/ConsoleApp1/rp.pdf"
Unhandled exception. Azure.RequestFailedException: Additional properties are not allowed ('filename' was unexpected)
Status: 400 (Bad Request)

Content:
{
"error": {
"message": "Additional properties are not allowed ('filename' was unexpected)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
I get this error is there any solution?

tajrianislamishan
Автор

Hey Ted,

Just wanted to let you know that the video looks fantastic! However, when I attempted to run it, I encountered an issue. Specifically, I received an Azure.RequestFailedException error with the following details:

Status: 400 (Bad Request)
Content:
{
"error": {
"message": "Additional properties are not allowed ('filename' was unexpected)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}

that error when I try to upload the file

mahmoudyousry