Skip to content

Messages、内容块与多模态:练习答案 ​

练习解答 ​

python
blocks=[{'type':'tool_use','id':'t1','name':'stock','input':{'sku':'A'}}]
text=''.join(b['text'] for b in blocks if b['type']=='text')
calls=[b for b in blocks if b['type']=='tool_use']
assert text=='' and len(calls)==1
print('await tool',calls[0]['id'])

失败应结合请求异常与 stop_reason 判断,而不是把文本是否为空作为唯一成功信号。

用心记录每一步成长