Skip to content

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

Description

@DavidLuong98

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugCategory: Something isn't working and appears to be a defect in the client library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions