Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating embedding with EmbeddingClient causes throw reference exception for 2.0.0-beta.6 #84

Closed
DavidLuong98 opened this issue Jun 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@DavidLuong98
Copy link

There is a crash when trying to generate an embedding, both synchronous and async methods. This only occurs for 2.0.0-beta.6. Downgrading to 2.0.0-beta.5 is a workaround.

Minimal code repro:

using OpenAI.Embeddings;

EmbeddingClient client = new(model: "text-embedding-3-small", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
string description = "Foo";
Embedding embedding = client.GenerateEmbedding(description);
ReadOnlyMemory<float> vector = embedding.Vector;
EmbeddingGenerationOptions options = new() { Dimensions = 512 };

Embedding embedding = client.GenerateEmbedding(description, options);

Stack:

System.NullReferenceException: Object reference not set to an instance of an object.
   at OpenAI.OpenAIClient.<>c__DisplayClass21_0.<CreateAddCustomHeadersPolicy>b__0(PipelineMessage message)
   at OpenAI.GenericActionPipelinePolicy.ProcessAsync(PipelineMessage message, IReadOnlyList`1 pipeline, Int32 currentIndex)
   at OpenAI.GenericActionPipelinePolicy.ProcessAsync(PipelineMessage message, IReadOnlyList`1 pipeline, Int32 currentIndex)
   at System.ClientModel.Primitives.ClientPipeline.SendAsync(PipelineMessage message)
   at OpenAI.ClientPipelineExtensions.ProcessMessageAsync(ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
   at OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingsAsync(BinaryContent content, RequestOptions options)
   at OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingAsync(String input, EmbeddingGenerationOptions options, CancellationToken cancellationToken)
@joseharriaga
Copy link
Collaborator

Thank you for reporting this issue, @DavidLuong98 ! I got a fix for it here: #85

@joseharriaga joseharriaga added the bug Something isn't working label Jun 23, 2024
@trrwilson
Copy link
Collaborator

@DavidLuong98, the fix @joseharriaga described is published now as 2.0.0-beta.7. Thank you again for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants