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

Feature/gemini structured output support #173

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dev-billy
Copy link

Hey everyone! 👋
This is my first PR to Prism, so I’m pretty excited (and a little nervous 😅). I’ve added structured output support for the Gemini provider using a prompt-based approach, similar to how it’s done for Anthropic and Deepseek Providers.

What’s in this PR?

  • Adds structured output for Gemini using prompt formatting.
  • Includes tests to make sure everything works as expected.

Why this approach?

I noticed another PR #116 exploring structured output for Gemini with a schema-based approach. My take is a little different—more in line with how it is being handled for Anthropic. The only difference with anthropic, gemini api config allows for response_mime_type which when set to application/json ensures the response is a JSON

Would love your thoughts!

Since this is my first contribution, I’d really appreciate any feedback! Let me know if this makes sense or if there’s anything I can tweak.

Thanks for taking a look! Looking forward to your thoughts. 🚀😊

@pushpak1300
Copy link
Contributor

Changes looks good.
I'll go over them once to make sure everything works perfectly.
Can you please update the docs as well ?

https://prism.echolabs.dev/providers/gemini.html
https://prism.echolabs.dev/getting-started/introduction.html

@dev-billy
Copy link
Author

Thank you, yes let me update

Copy link

kinsta bot commented Feb 9, 2025

Preview deployments for prism ⚡️

Status Branch preview Commit preview
❌ Failed to deploy N/A N/A

Commit: e0860e281370031d21d805d15244679f2b076c27

Deployment ID: 6bdbdde0-ae6e-44f3-a3ee-6724fe542949

Static site name: prism-97nz9

Copy link
Contributor

@pushpak1300 pushpak1300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Looks great.
Thank you for this. It will be great if you can do this changes.

src/Providers/Gemini/Handlers/Structured.php Outdated Show resolved Hide resolved
docs/providers/gemini.md Show resolved Hide resolved
docs/components/ProviderSupport.vue Outdated Show resolved Hide resolved
@@ -0,0 +1,101 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again i guess this is correct but can you please keep the methods of this structured output as consistent across other provider so its easier to update or refactor any thing related to provider. for eg src/Providers/Anthropic/Handlers/Structured.php
Again this optional.

@sixlive what do you think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided not to refactor the methods to be similar to the Anthropic Handler because the handle method feels bloated and might become difficult to follow through where exactly there's a failure if it does happen.

But also regarding consistency across other providers, the methods are similar to src/Providers/DeepSeek/Handlers/Structured.php and a bit similar to the OpenAI version but i guess the OpenAI case is different since it supports both JsonMode and StructuredMode for Structured Outputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants