generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

google.generativeai.chat does not support max_output_tokens

Open chrbsg opened this issue 1 year ago • 3 comments

We want to limit the reply length of chat responses, but google.generativeai.chat does not appear to support the max_output_tokens parameter. I'm not sure whether this is just not implemented yet, or an API limitation, or something else, but the vertexai Python SDK Chat model appears to support it (see Vertex AI Chat model parameters) and so does the google.generativeai.generate_text function.

I had thought that perhaps max_output_tokens wasn't supported in chat, just text generation, but this doc clearly shows it being used in a chat:

chat = chat_model.start_chat(
    context="My name is Ned. You are my personal assistant. My favorite movies are Lord of the Rings and Hobbit.",
    examples=[
        InputOutputTextPair(
            input_text="Who do you work for?",
            output_text="I work for Ned.",
        ),
        InputOutputTextPair(
            input_text="What do I like?",
            output_text="Ned likes watching movies.",
        ),
    ],
    temperature=0.3,
    max_output_tokens=200,
    top_p=0.8,
    top_k=40,
)
print(chat.send_message("Are my favorite movies based on a book series?"))

(It's a bit confusing that Google seems to have two different Python SDKs, this google-generativeai one and google-cloud-aiplatform. Is there any difference if all a developer wants to do is send chat to a model and get responses back?)

chrbsg avatar Jul 06 '23 17:07 chrbsg

Ack - thanks for the report. It's not strictly the Python library, as the API itself is missing the functionality, but I'll bring it up with the team nonetheless. (Googlers: b/292466007)

markmcd avatar Jul 24 '23 08:07 markmcd

+1 to this, also having this issue

liamdugan avatar Oct 20 '23 19:10 liamdugan

I found that a PaLM Chat model in Vertex AI SDK supports max_output_tokens.: https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text-chat

ryuryukke avatar Nov 27 '23 08:11 ryuryukke

The palm based interface has stopped develoipment. Closing.

MarkDaoust avatar May 17 '24 22:05 MarkDaoust