How to reduce Google Gemini AI response to less than 1000 characters without truncated its response

84 Views Asked by At

Example prompt: Make a story about turtle and pig. This could create more than 1000 character story. I tried reducing max_output_tokens with different values. I tried adding text in the prompt like Make a story about turtle and pig. Make it less than 1000 characters or ...make it short story which can't be use for general purpose. Using substring might not good option.

In OpenAI you can add instruction to do this without any problem to the story.

Output a story with less than 1000 characters., or how can I use *instruction *like OpenAI the same method to do in Gemini model

UPDATE: I already solved the problem, I just added the prompt like "... Answer should be less than 200 words"

1

There are 1 best solutions below

0
Argetlam On

Tokens are 3-4 characters each, so 1000 tokens would output 3-4 thousand characters. Try setting the token limit to something like 250. For example:

client.max_output_tokens = 250
answer = client.generate_content(query, safety_settings = safe)

Where client is your genai model.