Code example to match actual output
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
从 python/count_tokens.py 开始,将文档中记录的预期输出与当前示例产生的输出进行比较。检查提议的 count_tokens 和 usage_metadata 展示方式是否只应应用于此处,还是也应应用于其他文档示例。示例及其显示的输出一致,并且预期范围已确认,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Description of the feature request:
Hi everyone.
Issues
On the document, the code and expected output does not much.
For example, on python/count_tokens.py explains below.
def test_tokens_text_only(self):
# [START tokens_text_only]
from google import genai
client = genai.Client()
prompt = "The quick brown fox jumps over the lazy dog."
# Count tokens using the new client method.
total_tokens = client.models.count_tokens(
model="gemini-3.5-flash", contents=prompt
)
print("total_tokens: ", total_tokens)
# ( e.g., total_tokens: 10 )
response = client.models.generate_content(
model="gemini-3.5-flash", contents=prompt
)
# The usage_metadata provides detailed token counts.
print(response.usage_metadata)
# ( e.g., prompt_token_count: 11, candidates_token_count: 73, total_token_count: 84 )
# [END tokens_text_only]
However,
print("total_tokens: ", total_tokens)
# ( e.g., total_tokens: 10 )
does not reply as ( e.g. ) says.
Question and Proposal
Are ( e.g.)s intentionally written like above on the document?
If not and if we try to nicely write the document for beginners, we should write like below code.
def test_tokens_text_only(self):
# [START tokens_text_only]
from google import genai
client = genai.Client()
prompt = "The quick brown fox jumps over the lazy dog."
# Count tokens using the new client method.
- total_tokens = client.models.count_tokens(
- model="gemini-3.5-flash", contents=prompt
- )
- print("total_tokens: ", total_tokens)
+ response = client.models.count_tokens(
+ model="gemini-3.5-flash", contents=prompt
+ )
+ print("total_tokens: ", response.total_tokens)
# ( e.g., total_tokens: 10 )
response = client.models.generate_content(
model="gemini-3.5-flash", contents=prompt
)
# The usage_metadata provides detailed token counts.
- print(response.usage_metadata)
+ metadata = response.usage_metadata
+ print(f"prompt_token_count: {metadata.prompt_token_count}, candidates_token_count: {metadata.candidates_token_count}, total_token_count: {metadata.total_token_count}")
# ( e.g., prompt_token_count: 11, candidates_token_count: 73, total_token_count: 84 )
# [END tokens_text_only]
My concern
If we conduct this change, we have to change many parts on the document. Thus, I need your advices.
Thank you.
What problem are you trying to solve with this feature?
No response
Any other information you'd like to share?
No response
- 主要语言
- Go
- 星标
- 143
- 派生
- 68
- 平均合并
- 10 小时 30 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google-gemini/api-examples 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 42/100
google-gemini/api-examples#89 · 1 条评论 ·
-
Tt未关闭
难度 5/5 一周以上 新手友好度 1/100
-
Soqce未关闭
难度 5/5 一周以上 新手友好度 10/100
查看 google-gemini/api-examples 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
google/osv-scanner#3327 ·
维护者通常 1 天内回复
-
tld-snapshot
难度 2/5 1-3 小时 新手友好度 72/100
awslabs/ferret-scan#1064 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
VictoriaMetrics/VictoriaTraces#335 ·
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 62/100
DaoCloud/DaoCloud-docs#7839 ·
维护者通常 1 天内回复