RageAgainstThePixel / OpenAI-DotNet

A Non-Official OpenAI RESTful API Client for DotNet
https://openai.com
MIT License
700 stars 149 forks source link

json validation errors #174

Closed czlowieku closed 11 months ago

czlowieku commented 11 months ago

Bug Report

Overview

validation errors are appearing when I do vision call from examples in readme

I do any call and I get:

5 validation errors for Request
body -> n
  none is not an allowed value (type=type_error.none.not_allowed)
body -> stop
  none is not an allowed value (type=type_error.none.not_allowed)
body -> logit_bias
  extra fields not permitted (type=value_error.extra)
body -> tool_choice
  extra fields not permitted (type=value_error.extra)
body -> tools
  extra fields not permitted (type=value_error.extra)

the msg is:

{
  "messages": [
        {
            "role": 3,
            "content": [
                {
                    "type": "text",
                    "text": "What\u0027s in this image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
                    }
                }
            ]
        }
    ],
    "model": "gpt-4-vision-preview",
    "frequency_penalty": null,
    "logit_bias": {},
    "max_tokens": 300,
    "n": null,
    "presence_penalty": null,
    "seed": null,
    "stop": null,
    "temperature": null,
    "top_p": null,
    "tools": null,
    "tool_choice": null,
    "user": null
}

code that I have


 public async Task GetVision()
 {
     var api = new OpenAIClient(
         new OpenAIAuthentication("xxx"));

     var messages = new List<Message>
     {
         new Message(Role.User, new List<Content>
         {
             new Content(ContentType.Text, "What's in this image?"),
             new Content(ContentType.ImageUrl,
                 "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg")
         })
     };
     var chatRequest = new ChatRequest(messages, model: "gpt-4-vision-preview",maxTokens:300,logitBias:new Dictionary<string, double>());
     var response = await api.ChatEndpoint.GetCompletionAsync(chatRequest);

 }

it seems it is sending nulls in msg even thou I see serializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; in the client.

StephenHodgson commented 11 months ago

I'm not able to reproduce this. What happens when you enable debug?

var api = new OpenAIClient("sk-key");
api.EnableDebug = true;
StephenHodgson commented 11 months ago

Also, I want to know which versions you've tried.

StephenHodgson commented 11 months ago

Nvm, I was able to repro it. Fix incoming.

StephenHodgson commented 11 months ago

@czlowieku keep in mind openai services are also having outages

czlowieku commented 11 months ago

Works now, thank you for fixing this :-) ( and for the nuget as well )