Skip to content

客户端、Parts 与多模态输入:练习答案 ​

练习解答 ​

python
def classify(candidates):
    if not candidates:return 'no_candidate'
    first=candidates[0]
    return 'text' if first['finish_reason']=='STOP' and first.get('text') else 'inspect'
assert classify([])=='no_candidate'
assert classify([{'finish_reason':'MAX_TOKENS','text':'partial'}])=='inspect'
assert classify([{'finish_reason':'STOP','text':'ok'}])=='text'
print('candidate checks passed')

这只验证应用分支;SDK 使用枚举时需按其值或枚举成员比较。STOP 也不替代事实正确性检查。

用心记录每一步成长