Output Length field (max_output_tokens parameter) does not affect response, setting it causes empty or missing outputs
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu với lệnh gọi Python của google.genai đến client_gemini.models.generate_content và so sánh hành vi của GenerateContentConfig khi có và không có max_output_tokens. Tái hiện trường hợp prompt ngắn bằng các giá trị được hiển thị, sau đó kiểm tra candidate được trả về, finish reason và usage metadata. Hoàn tất khi các yêu cầu giới hạn đầu ra trả về văn bản thay vì phản hồi content.parts trống hoặc bị thiếu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description of the bug:
When using the official Python Gemini SDK, setting the max_output_tokens (called “Output Length” in UI) parameter in the GenerateContentConfig object does not work as expected.
If I provide a value for max_output_tokens (e.g., 400 or 1024), the model response is empty or contains no text, and response.candidates[0].content.parts is either empty or missing.
This happens even for very short or simple prompts and regardless of the output length requested.
CODE:
from google.genai import types
from google import genai
response = client_gemini.models.generate_content(
model=gemini_model,
contents='hi, is sky blue?',
config=types.GenerateContentConfig(
max_output_tokens=MAX_OUTPUT_TOKENS,
temperature=TEMPERATURE,
),
)
print(response)
OUTPUT:
sdk_http_response=HttpResponse(
headers=<dict len=11>
) candidates=[Candidate(
content=Content(
role='model'
),
finish_reason=<FinishReason.MAX_TOKENS: 'MAX_TOKENS'>,
index=0
)] create_time=None response_id=None model_version='gemini-2.5-pro' prompt_feedback=None usage_metadata=GenerateContentResponseUsageMetadata(
prompt_token_count=7,
prompt_tokens_details=[
ModalityTokenCount(
modality=<MediaModality.TEXT: 'TEXT'>,
token_count=7
),
],
thoughts_token_count=399,
total_token_count=406
) automatic_function_calling_history=[] parsed=None
Actual vs expected behavior:
If I leave max_output_tokens unset (i.e., use the default), responses are returned normally.
CODE:
from google.genai import types
from google import genai
response = client_gemini.models.generate_content(
model=gemini_model,
contents='hi, is sky blue?',
config=types.GenerateContentConfig(
temperature=TEMPERATURE,
),
)
print(response)
OUTPUT
sdk_http_response=HttpResponse(
headers=<dict len=11>
) candidates=[Candidate(
content=Content(
parts=[
Part(
text="""Yes, on a clear day, the sky is blue.
The reason for this is a fascinating bit of physics! Here's a simple breakdown:
1. **Sunlight is White Light:** Sunlight may look yellow or white, but it's actually made up of all the colors of the rainbow (red, orange, yellow, green, blue, violet).
2. **Earth Has an Atmosphere:** Our planet is wrapped in a blanket of gases and tiny particles.
3. **Light Scatters:** When sunlight enters the atmosphere, it bumps into the tiny gas molecules. This causes the light to scatter in all directions.
4. **Blue Scatters Best:** Shorter wavelengths of light (blue and violet) are scattered much more easily and widely by these gas molecules than the longer wavelengths (like red and orange). This effect is called **Rayleigh scattering**.
Because this blue light is scattered all over the sky, that's the color we see when we look up.
### So, why isn't the sky violet?
That's a great question! Violet light has an even shorter wavelength and is scattered even more than blue. However, two things are happening:
* The sun emits less violet light than blue light.
* Our eyes are much more sensitive to blue light than they are to violet.
The combination of these two factors means our eyes and brain perceive the sky as blue.
### When is the sky NOT blue?
* **At Sunrise and Sunset:** The sky often looks red, orange, or pink. This is because the sun is low on the horizon, and its light has to travel through much more of the atmosphere to reach you. By the time it gets to your eyes, most of the blue light has been scattered away, leaving the longer, reddish wavelengths to come straight through.
* **On a Cloudy Day:** The sky looks white or gray. Clouds are made of water droplets, which are much larger than gas molecules. They scatter all colors of light about equally. When all the colors mix back together, we see white."""
),
],
role='model'
),
finish_reason=<FinishReason.STOP: 'STOP'>,
index=0
)] create_time=None response_id=None model_version='gemini-2.5-pro' prompt_feedback=None usage_metadata=GenerateContentResponseUsageMetadata(
candidates_token_count=435,
prompt_token_count=7,
prompt_tokens_details=[
ModalityTokenCount(
modality=<MediaModality.TEXT: 'TEXT'>,
token_count=7
),
],
thoughts_token_count=1392,
total_token_count=1834
) automatic_function_calling_history=[] parsed=None
- Ngôn ngữ chính
- Go
- Star
- 143
- Fork
- 68
- Merge trung bình
- 10 giờ 30 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google-gemini/api-examples
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
google-gemini/api-examples#104 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
TtĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 1/100
-
SoqceĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
Tất cả issue của google-gemini/api-examples
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
google/osv-scanner#3327 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tld-snapshot
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
awslabs/ferret-scan#1064 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
VictoriaMetrics/VictoriaTraces#335 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
【文档错误】创建镜像空间步骤中的截图标注与文字描述不一致Đang mởenhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainer thường phản hồi trong vòng 1 ngày