DEV Community

Brady Guy Chambers
Brady Guy Chambers

Posted on

Azure OpenAI C# some Learnings

I have shared a detailed practicle example of using Azure OpenAI with REST and the OpenAI SDK at the link below. Some of the quick learnings are:

  • Models that don't support standardized_output you pass in either a json schema or an example json document that represents what you want to come out of the model.
  • If content filters are triggered you still get a 200, your json is truncated and the response includes a json section that defines the content filtering results. Note: this is what I observed with the Azure OpenAI hosted models. Be sure and look at the returned response and parse through the content filter sections.
  • If the model does not support image input an error something like : Error copying to stream is returned.
  • structured_output – way cool for the models that support it, if you have a class that you want the model to return the answer in use the CreateJsonSchemaFormat with your class. Not that many models currently support structured output.

ChatCompletionOptions options = new ChatCompletionOptions()
{
ResponseFormat = StructuredOutputsExtensions.CreateJsonSchemaFormat<Recipe>(“Recipe”, jsonSchemaIsStrict: true),
MaxOutputTokenCount = 14000,
Temperature = 0.1f,
TopP = 1.0f,
};

Azure OpenAI C# Learnings

Top comments (0)