Open emilmuller opened 2 weeks ago
Thank you for reaching out, @emilmuller ! All the clients (including the OpenAIClient
and the EmbeddingClient
) are thread-safe. What you have above works.
thanks, I was after this question too, the Azure OpenAI SDK mentions it is thread-safe here.
I want to use this library outside of Azure SDK and wasn't sure if ChatClient
is thread-safe and its safe to register a single instance.
I can see the OpenAIClient
is a factory class to create new instances of other clients
but is it safe to reuse a single ChatClient
instance across different threads in parallel for different chat completions?
Confirm this is a feature request for the .NET library and not the underlying OpenAI API
Describe the feature or improvement you are requesting
There seems to be a lack of documentation regarding DI and thread-safety, which makes it difficult to migrate to version 2 with confidence. Even though the code below mentions Azure, it is a non-Azure-OpenAI issue as well.
Before, using Azure.AI.OpenAI 1.0.0-beta.xx, I had this in my Program.cs:
This seems to have been deprecated. At least, I cannot find out how to set up dependency injection like that.
If I wanted to use OpenAIClient, should I just add a singleton? Is it thread-safe? I cannot find any mention of this. Something like this?
Now, how do I generate embeddings? The obvious way, if I already have an OpenAIClient, would be something like:
But that would create a new instance of EmbeddingClient each time. Could I have EmbeddingClient as a singleton then?
Or is that not thread-safe to use?
Additional context
No response