Skip to content

can't ask for JSON data when using fine-tuned model #578

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

Open
hedihadi opened this issue Sep 30, 2024 · 3 comments
Open

can't ask for JSON data when using fine-tuned model #578

hedihadi opened this issue Sep 30, 2024 · 3 comments
Assignees
Labels
component:api Issues related to the API, not the SDK. type:feature request New feature request/enhancement

Comments

@hedihadi
Copy link

Description of the bug:

when i use gemini-1.5-flash or gemini-1.5-pro i have no problem asking for json return like so

model = genai.GenerativeModel("gemini-1.5-flash",system_instruction="you're a bot that answers questions by referencing Quran verses or Hadith or Quotes from notable islamic scholars.")

response_schema = """"
{
  "type": "object",
  "properties": {
    "answers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "quran",
              "hadith",
              "quote"
            ]
          },
          "text": {
            "type": "string"
          },
          "chapter_number": {
            "type": "integer"
          },
          "verse_number": {
            "type": "string"
          }
        },
        "required": [
          "type",
          "text"
        ]
      }
    },
    "conclusion": {
      "type": "string"
    }
  },
  "required": [
    "answers",
    "conclusion"
  ]
}
"""

response = model.generate_content(
    "my mom is sad, what should i do?",
   generation_config = {
  "temperature": 1,
  "max_output_tokens": 8192,
        'response_mime_type':"application/json",
        "response_schema":response_schema

}
)

this sometimes doesn't respect the response_schema structure, so i decided to fine-tune a model to get more predictable data. i did that and basically replaced the model name like so

model = genai.GenerativeModel("tunedModels/quranchat-q68kkpnh5aad",system_instruction="""
you're a bot that answers questions by referencing Quran verses or Hadith or Quotes from notable islamic scholars.
""")

also dealing with the oauth from this documentation https://ai.google.dev/gemini-api/docs/oauth as i'm now using a fine-tuned model.

but now, when i run the same code i get this error
400 Developer instruction is not enabled for tunedModels/quranchat-q68kkpnh5aad and after some horrendous hours trying to see what this means, i realized it's because i have system_instruction variable, so i deleted that and ended up with this code

model = genai.GenerativeModel("tunedModels/quranchat-q68kkpnh5aad")

and ran the file again, now i get this error
400 Json mode is not enabled for tunedModels/quranchat-q68kkpnh5aad
which this one is also happening because i have 'response_mime_type':"application/json" in my generation_config variable.

Actual vs expected behavior:

so i basically realized i can't use system instruction nor ask for json response when using fine-tuned data, is this a library restriction or gemini?

Any other information you'd like to share?

let me know if there's anything more i can share

@Gunand3043 Gunand3043 added status:triaged Issue/PR triaged to the corresponding sub-team component:python sdk Issue/PR related to Python SDK type:question Support-related issues labels Oct 1, 2024
@Gunand3043 Gunand3043 self-assigned this Oct 1, 2024
@Gunand3043
Copy link

@hedihadi

For a tuned model, JSON mode is not supported, and also you cannot pass the system instruction.

Please refer the link for the current limitations of tuned model.

@Gunand3043 Gunand3043 added status:awaiting user response Awaiting a response from the author and removed status:triaged Issue/PR triaged to the corresponding sub-team labels Oct 1, 2024
@MarkDaoust MarkDaoust added type:feature request New feature request/enhancement and removed status:awaiting user response Awaiting a response from the author type:question Support-related issues labels Oct 2, 2024
@MarkDaoust
Copy link
Collaborator

This is a valid feature request.

@Gunand3043, that's a good resource. Thanks for the link.

this sometimes doesn't respect the response_schema structure

That shouldn't be possible, it uses constrained decoding. Can you explain more? Is it just that it leaves out fields sometimes?

@aaryanbrahm
Copy link

Hey Guys, do we have any update on this feature, do we know if its being built or in the pipeline?
Would be great to know this.
Thanks

@MarkDaoust MarkDaoust added component:api Issues related to the API, not the SDK. and removed component:python sdk Issue/PR related to Python SDK labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:api Issues related to the API, not the SDK. type:feature request New feature request/enhancement
Projects
None yet
Development

No branches or pull requests

4 participants