generative-ai-js icon indicating copy to clipboard operation
generative-ai-js copied to clipboard

responseSchema typing requires Enums, prefer string literals.

Open mfrancis107 opened this issue 8 months ago • 3 comments

Description of the feature request:

This is an invalid type because you define responseSchema using enums.

responseSchema: {
            "type": "object",
            "properties": {
              "test": {
                "type": "string"
              }
            }
          }

We must do this to avoid type errors.

responseSchema: {
            "type": SchemaType.OBJECT,
            "properties": {
              "test": {
                "type": SchemaType.STRING
              }
            }
          }

What problem are you trying to solve with this feature?

No response

Any other information you'd like to share?

No response

mfrancis107 avatar Apr 08 '25 17:04 mfrancis107

Hi @mfrancis107 ,

Thanks for highlighting this. I can see, we're largely consistent in using SchemaType for responseSchema definitions. Could you please pointout the specific instances where hardcoded type values are being used in the code?

shmishra99 avatar Apr 09 '25 12:04 shmishra99

@shmishra99 I think the user's complaint is not about inside our codebase, but in their code, they have to lookup the enum object instead of just writing the string. ANd maybe that would be fine if we were on an island, but it makes it harder to use this with external tools that generate the Schemas (zod?), since they return strings.

MarkDaoust avatar Apr 10 '25 00:04 MarkDaoust

@MarkDaoust Is exactly right in explaining the reasoning for the request.

mfrancis107 avatar Apr 10 '25 01:04 mfrancis107