Hello everyone,
I am trying to use the GPT-4 Vision API but need to run the code synchronously instead of asynchronously.
Here is the code I tried. It works in my tests, but due to the use of the ?
syntax in the last line to get the response, it requires Microsoft.CSharp
, which is not compatible with .NET Framework 4.6.2.
To work around this, I removed the ?
syntax, but now, when I try to access responseData
, I always get the following error:
Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create
Unfortunately, running the code asynchronously is not an option as it needs to be executed in a plugin that does not support async code.
Does anyone know how to handle this issue or have any suggestions on how to make this work synchronously without running into compatibility problems?
Thank you!
private string GetKeyValuePairsViaOpenAiVision(string payload)
{
string JSONContent = "";
var httpClient = Ctx.Azure.HttpClientWithHeaders; // Get the HttpClient instance from Azure class
var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = httpClient.PostAsync(Ctx.Azure.OpenAiVisionEndpoint, content).GetAwaiter().GetResult(); // Use .Result to run synchronously
if (response.IsSuccessStatusCode)
{
var responseData = JsonConvert.DeserializeObject<dynamic>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
JSONContent = responseData?.choices[0]?.message?.content;
}
return JSONContent;
}