Skip to content

.Net: Fixed JSON schema name in Structured Outputs for generic types - #9490

Merged
Dmytro Struk (dmytrostruk) merged 7 commits into
microsoft:mainfrom
dmytrostruk:structured-outputs-schema-name-fix
Nov 1, 2024
Merged

Dmytro Struk (dmytrostruk) merged 7 commits into
microsoft:mainfrom
dmytrostruk:structured-outputs-schema-name-fix

Conversation

@dmytrostruk

Copy link
Copy Markdown
Member

Motivation and Context

Resolves: #9416

When C# type is passed as a response format to OpenAI chat completion service, we use the type name as JSON schema name. When the type is generic, its name will contain characters that are not allowed in JSON schema name according to OpenAI API. This PR fixes the issue by replacing invalid characters with empty string.

Contribution Checklist

@dmytrostruk
Dmytro Struk (dmytrostruk) requested a review from a team as a code owner October 31, 2024 18:07
@markwallace-microsoft Mark Wallace (markwallace-microsoft) added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Oct 31, 2024
@asvishnyakov

Copy link
Copy Markdown

Wouldn't it better to use fully qualified type names, as they are truly unique, and because OpenAI doesn't support symbols, use for example hash of string?

@dmytrostruk

Copy link
Copy Markdown
Member Author

Wouldn't it better to use fully qualified type names, as they are truly unique, and because OpenAI doesn't support symbols, use for example hash of string?

Aleksandr Vishniakov (@asvishnyakov) Thanks for your feedback! I don't see a requirement for this property to be unique in OpenAI docs or usage of hash in their examples. It would be also nice to be consistent with Python implementation, which uses just a name.

@dmytrostruk
Dmytro Struk (dmytrostruk) added this pull request to the merge queue Nov 1, 2024
Merged via the queue into microsoft:main with commit f80528f Nov 1, 2024
@dmytrostruk
Dmytro Struk (dmytrostruk) deleted the structured-outputs-schema-name-fix branch November 1, 2024 19:05

This branch was previously deployed

1 inactive deployment
integration — ccd536e8 Deployed Nov 1, 2024 by dmytrostruk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP 400 error "Invalid 'response_format.json_schema.name'" when generic type is used for ResponseFormat

4 participants