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

.Net: New Feature: Add missing optional parameter responseMimeType to GeminiPromptExecutionSettings to allow for valid JSON output #9863

Closed
Millmer opened this issue Dec 2, 2024 · 2 comments · Fixed by #9870
Assignees
Labels
.NET Issue or Pull requests regarding .NET code

Comments

@Millmer
Copy link

Millmer commented Dec 2, 2024


name: Add missing optional parameter responseMimeType to GeminiPromptExecutionSettings

about: The optional API parameter responseMimeType is missing from the GeminiPromptExecutionSettings which is preventing the ability to have valid JSON responses returned from requests to Gemini (similar to OpenAI's response_format: "json_object"). This allows you to set the appropriate response type to avoid unintended behaviours.


Suggested Property:

[JsonPropertyName("responseMimeType")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ResponseMimeType { get; set; }

Available values are:

  • application/json: JSON response in the candidates.
  • text/plain (default): Plain text output.
  • text/x.enum: For classification tasks, output an enum value as defined in the response schema.

Google documentation:
https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerationConfig
https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference

Ideally the responseSchema property should also be incorporated to allow for "controlled generation", as Google call it (the same as Structured Output with OpenAI), but that's a much larger implementation. Adding responseMimeType would be a great start and seems like a low handing fruit, I may be wrong though... 🤔 It looks like this has been added on the Python version already.

@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage labels Dec 2, 2024
@github-actions github-actions bot changed the title .Net: New Feature: Add missing optional parameter responseMimeType to GeminiPromptExecutionSettings to allow for valid JSON output Python: .Net: New Feature: Add missing optional parameter responseMimeType to GeminiPromptExecutionSettings to allow for valid JSON output Dec 2, 2024
@github-actions github-actions bot changed the title Python: .Net: New Feature: Add missing optional parameter responseMimeType to GeminiPromptExecutionSettings to allow for valid JSON output .Net: New Feature: Add missing optional parameter responseMimeType to GeminiPromptExecutionSettings to allow for valid JSON output Dec 2, 2024
@moonbox3 moonbox3 removed the python Pull requests for the Python Semantic Kernel label Dec 2, 2024
@shethaadit
Copy link
Contributor

Hi @markwallace-microsoft, @moonbox3, I will work on this and raise PR soon. :)

@Millmer
Copy link
Author

Millmer commented Dec 3, 2024

Thank you 🙏 I noticed a similar PR referring to the missing responseSchema property I mentioned: #9501

I'm not sure how I missed that one before making this one 🤔 🙃

github-merge-queue bot pushed a commit that referenced this issue Dec 3, 2024
… for Enhanced Output Control. (#9870)

### Motivation and Context

**Why is this change required?**
The absence of the `responseMimeType` property in .NET prevented users
from leveraging structured output formats available in the Gemini API,
causing unintended behavior in scenarios requiring JSON or controlled
output.

**What problem does it solve?**
Adds flexibility for developers by enabling control over MIME type
responses, particularly for JSON data parsing and classification tasks.

**What scenario does it contribute to?**
- Requests with structured response needs, such as JSON objects or
controlled classification outputs.
- Seamless migration and parity with the Python SDK's `responseMimeType`
support.

Fixes #9863 

### Description

This PR adds support for the optional `responseMimeType` parameter to
the `GeminiPromptExecutionSettings` class, allowing for better control
over the output response format in Gemini API calls. This change
addresses the missing ability to specify MIME types for valid JSON,
plain text, or enumerated outputs.

### Contribution Checklist

- [Y] The code builds clean without any errors or warnings
- [Y] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [Y] All unit tests pass, and I have added new tests where possible
- [Y] I didn't break anyone 😄

Co-authored-by: Adit Sheth <adsheth@microsoft.com>
@markwallace-microsoft markwallace-microsoft moved this from Sprint: In Review to Sprint: Done in Semantic Kernel Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code
Projects
Archived in project
4 participants