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

Support for "gemini-exp-1206" (Getting None in response.text) #67

Closed
krossloopml opened this issue Jan 2, 2025 · 6 comments
Closed
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@krossloopml
Copy link

krossloopml commented Jan 2, 2025

Whenever trying to use "gemini-exp-1206", i am getting None in response.text (Even after taking 2 minutes, which it usually does for my requests)
But using the same code for "gemini-2.0-flash-exp", i am getting proper expected text in response

Code to reproduce the issue

from google import genai
from google.genai import types

def generate(file_path):
    # Only run this block for Google AI API
    client = genai.Client(api_key = <API_KEY>)

    file = client.files.upload(path = file_path)
    file_obj = types.Part.from_uri(
        file_uri = file.uri,
        mime_type = "application/pdf",
    )
    SYSTEM_PROMPT_obj = types.Part.from_text(SYSTEM_PROMPT)

    contents = [
        types.Content(
            role = "user",
            parts = [
                file_obj,
                SYSTEM_PROMPT_obj,
            ]
        )
    ]

    generate_content_config = types.GenerateContentConfig(
        temperature = 0,
        top_p = 0.0,
        top_k = 1,
        seed = 50,
        max_output_tokens = 8192,
        response_modalities = ["TEXT"],
        safety_settings = [types.SafetySetting(
            category = "HARM_CATEGORY_HATE_SPEECH",
            threshold = "OFF"
        ),types.SafetySetting(
            category = "HARM_CATEGORY_DANGEROUS_CONTENT",
            threshold = "OFF"
        ),types.SafetySetting(
            category = "HARM_CATEGORY_SEXUALLY_EXPLICIT",
            threshold = "OFF"
        ),types.SafetySetting(
            category = "HARM_CATEGORY_HARASSMENT",
            threshold = "OFF"
        )]
    )

    response = client.models.generate_content(
        # model = "gemini-2.0-flash-exp",
        model = "gemini-exp-1206",
        contents = contents,
        config = generate_content_config,
    )

    client.files.delete(name = file.name)

    return response

file_path = "sample.pdf"
response = generate(file_path)
@krossloopml krossloopml added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 2, 2025
@Giom-V
Copy link

Giom-V commented Jan 8, 2025

Have you tried without the pdf?

@Zheka17
Copy link

Zheka17 commented Jan 9, 2025

I tried with pdf and it does work for me (at least in v0.4).

What DOESNT work, however:

  • uploading/ using "application/json" files --- why?? (i always thought that structured data (xml, json) are better for prompting)

  • adding several files to content (which is simple in the prior api) --> getting 'error': {'code': 400, 'message': 'Request contains an invalid argument.',..}......this seems to be supported but there isn't a single example in the docs/cookbook for python-genai

Also, couldn't find an example of adding files to content without uploading. This is seemingly possible in the prior/current api (via media/....)....

@krossloopml
Copy link
Author

krossloopml commented Jan 10, 2025

Have you tried without the pdf?

yes I did, still getting None

I tried with pdf and it does work for me (at least in v0.4).

What DOESNT work, however:

  • uploading/ using "application/json" files --- why?? (i always thought that structured data (xml, json) are better for prompting)
  • adding several files to content (which is simple in the prior api) --> getting 'error': {'code': 400, 'message': 'Request contains an invalid argument.',..}......this seems to be supported but there isn't a single example in the docs/cookbook for python-genai

Also, couldn't find an example of adding files to content without uploading. This is seemingly possible in the prior/current api (via media/....)....

I upgraded to v0.4, still doesn't work for me, getting None

@krossloopml
Copy link
Author

krossloopml commented Jan 11, 2025

from google import genai
from google.genai import types

def generate():
    # Only run this block for Google AI API
    client = genai.Client(api_key = 'API_KEY')

    contents = [
        types.Content(
            role = "user",
            parts = [
                types.Part.from_text("WHO ARE YOU?"),
            ]
        )
    ]

    generate_content_config = types.GenerateContentConfig(
        temperature = 0.5,
        top_p = 0.95,
        top_k = 40,
        seed = 50,
        max_output_tokens = 8192,
        response_modalities = ["TEXT"],
        safety_settings = [types.SafetySetting(
            category = "HARM_CATEGORY_HATE_SPEECH",
            threshold = "OFF"
        ),types.SafetySetting(
            category = "HARM_CATEGORY_DANGEROUS_CONTENT",
            threshold = "OFF"
        ),types.SafetySetting(
            category = "HARM_CATEGORY_SEXUALLY_EXPLICIT",
            threshold = "OFF"
        ),types.SafetySetting(
            category = "HARM_CATEGORY_HARASSMENT",
            threshold = "OFF"
        )]
    )

    response = client.models.generate_content(
        model = "gemini-exp-1206",
        contents = contents,
        config = generate_content_config,
    )

    # print(response)
    return response.text

# Example usage
response = generate()

print(response)

Even this gives None

but using gemini-2.0-flash-exp gives this using the same code block
-> I am a large language model, trained by Google.

@Giom-V

@krossloopml
Copy link
Author

Apparently removing the safety_settings explicitly mentioned in the generate_content_config solved the issue

But why?

@Giom-V
Copy link

Giom-V commented Jan 13, 2025

@krossloopml I might be wrong (can't find anything in the model settings) but I think since the model is experimental, it has different safety settings regulations and they can't be switched off.

@sasha-gitg sasha-gitg added type: question Request for information or clarification. Not an issue. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants