[BUG] Error loading OpenAI.Chat.ChatCompletion
Closed this issue · 2 comments
Describe the bug
Could not load type 'OpenAI.Chat.ChatCompletion' from assembly 'OpenAI, Version=8.3.0.0, Culture=neutral, PublicKeyToken=null'.
Steps to reproduce
protected virtual async Task<string> GetJsonResponse(string pdfBase64)
{
var client = new ChatClient(
model: "gpt-4o",
apiKey: _configuration.ChatGPTAPIKey
);
var prompt = GetPrompt();
var chatMessageContentParts = new List<ChatMessageContentPart>()
{
ChatMessageContentPart.CreateTextPart(prompt)
};
IReadOnlyCollection<byte[]> imagePageImages = await _pdfService.SplitOnImagePages(pdfBase64);
foreach (byte[] imageData in imagePageImages)
{
chatMessageContentParts.Add(ChatMessageContentPart.CreateImagePart(BinaryData.FromBytes(imageData), "image/png"));
}
ChatCompletion completion = await client.CompleteChatAsync(ChatMessage.CreateUserMessage(chatMessageContentParts));
string response = completion.Content.FirstOrDefault()?.Text ?? string.Empty;
response = response.Replace("```json", "").Replace("```", "");
if (!response.IsJsonDocument())
throw new Exception("The response from OpenAI API is not a valid JSON document.");
return response;
}
Code snippets
OS
Windows
.NET version
9
Library version
2.3.0
Hi @jrmaquiles. Thank you for reaching out and we regret that you're experiencing difficulties. The error that you're seeing is not related to the OpenAI library; it is local to your project and occurs when the runtime cannot resolve a type from the project's references. This is not something that we can reproduce, as it involves the specific scenario for your application - including your project type, target runtimes, and full list of dependencies. We would recommend that you attempt to isolate the issue in in a separate project, starting with just the OpenAI library and then slowly adding in your full list of dependencies one-at-a-time.
One thing that jumps out at me from the description, which may simply be a typo is:
OpenAI, Version=8.3.0.0, Culture=neutral, PublicKeyToken=null
- There is no version 8.3.0.0 of the OpenAI library. The current version is 2.3.0.
- The OpenAI client library is signed and has a public key token associated with it.
This looks like you may have another reference in your project/solution to something called OpenAI which is not our package.
You're absolutely right, @jsquire. Version 8.3.0.0 of OpenAI.dll comes from another dependency in the project that overwrites the one from OpenAI's nuget. It's our problem.
Thank you very much.