Menu
CoddyTech

回顾:商店客服

本课属于 Coddy AI Engineering 学习旅程的“在代码中调用模型”单元。第 5 课,共 22 课。

challenge icon

挑战

中等

构建 Brightside Books 的帮助台。初始代码读取客户的姓名和他们的问题;SHOP_FACTS 包含商店的信息。

  1. 编写系统提示词:You are Juno, the help desk of Brightside Books.、一个空格、SHOP_FACTS、一个空格以及 End every reply with "Happy reading!"
  2. 发送三条消息:用户说 My name is <name>.,助手回复 Hello <name>, how can I help?,然后用户提出问题。使用 model="claude-opus-5-5" 和 max_tokens=200。
  3. 打印 Answer: 以及文本块的文本(通过其类型查找)。
  4. 打印 Stop: 和停止原因。
  5. 打印 Tokens: <input> in, <output> out。

例如,对于输入 Lena 和 When does the shop open?,程序输出:

Answer: The shop opens at 10 am and closes at 7 pm. Happy reading!
Stop: end_turn
Tokens: 97 in, 16 out

亲手试试

import coddy_ai as anthropic  # 在生产环境中:import anthropic

client = anthropic.Anthropic()

SHOP_FACTS = (
    "The shop opens at 10 am and closes at 7 pm. "
    "Delivery is free on orders over 30 dollars. "
    "Gift cards never expire. "
    "Returns are accepted within 14 days with a receipt."
)

name = input()
question = input()

# 在下方编写你的代码

在代码中调用模型中的所有课

自己练习: Python 在线编译器