Hello together! Im just new to openAI API and using the new sdk from openAI. I want to archive that I can upload a PDF and then let openAI extract its data to a JSON, but I only get back a example JSON with John Doe, etc.
Anybody could tell me please what I am doing wrong?
Current code is in attachment as image, here as text:
private async void TextBlock_Drop(object sender, System.Windows.DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
OpenAIClient openAIClient = new("xxx");
FileClient fileClient = openAIClient.GetFileClient();
ChatClient chatClient = openAIClient.GetChatClient("gpt-3.5-turbo-0125");
foreach (string file in files)
{
using FileStream document = File.OpenRead(file);
OpenAIFileInfo uploadedFile = await fileClient.UploadFileAsync(document, Path.GetFileName(file), FileUploadPurpose.Assistants);
MessageBox.Show("uploaded: " + uploadedFile.Id);
ChatCompletion chatCompletion = await chatClient.CompleteChatAsync(
[
new UserChatMessage($"Extract the PDF file and write it to JSON (sender, consignee, items, weights, etc.)\n\nFile ID: {uploadedFile.Id}"),
]);
var response = chatCompletion.Content[^1].Text;
MessageBox.Show(response);
fileClient.DeleteFile(uploadedFile.Id);
}
}