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

A bug is found on EmbedContentRequest #14

Closed
doggy8088 opened this issue Mar 27, 2024 · 1 comment
Closed

A bug is found on EmbedContentRequest #14

doggy8088 opened this issue Mar 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@doggy8088
Copy link
Contributor

doggy8088 commented Mar 27, 2024

When serializing EmbedContentRequest object, the JSON will be:

{
    "model": "models/embedding-001",
    "content": {
        "parts": [
            {
                "text": "Hello"
            }
        ],
        "text": "Hello"
    }
}

Here is my sample code:

var request = new EmbedContentRequest("Hello");

var json = JsonSerializer.Serialize(request, new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
	DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
	PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
	DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
	NumberHandling = JsonNumberHandling.AllowReadingFromString,
	PropertyNameCaseInsensitive = true,
	ReadCommentHandling = JsonCommentHandling.Skip,
	AllowTrailingCommas = true,
	Converters = { (JsonConverter)new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper) }
}).Dump();

See screenshot:

image

There are two issues:

  1. The model property is not necessary, but no error will be thrown.
  2. The content.text property will produce error.
{
    "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"text\" at 'content': Cannot find field.",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.BadRequest",
                "fieldViolations": [
                    {
                        "field": "content",
                        "description": "Invalid JSON payload received. Unknown name \"text\" at 'content': Cannot find field."
                    }
                ]
            }
        ]
    }
}

The ContentResponse class is not obey the API doc Content definition. Only parts and role are defined.

image

@doggy8088 doggy8088 changed the title A bug is found on models/embedding-001 on EmbedContentRequest A bug is found on EmbedContentRequest Mar 27, 2024
doggy8088 added a commit to doggy8088/Mscc.GenerativeAI that referenced this issue Mar 27, 2024
@jochenkirstaetter
Copy link
Contributor

Thanks @doggy8088

@jochenkirstaetter jochenkirstaetter added the bug Something isn't working label Mar 28, 2024
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

Successfully merging a pull request may close this issue.

2 participants