逐日AI

面试题库

共 328 题,当前筛选 1 题。

30 天从前端工程师到 Agent 工程师

D1 LLM API 基础:messages/roles、token、流式、temperature;Agent 到底是什么

  • temperature 和 top_p 分别控制什么?什么场景用 0,什么场景用 0.7?What do temperature and top_p control, and when would you use 0 versus 0.7?
    海外高频基础#llm-basics#sampling

    分析过程 · 先想清楚再作答

    1. 先说清两者作用在同一个地方——模型算出的下一个 token 概率分布——但作用方式不同,这是区分度所在。
    2. temperature 是缩放整个分布:越低越尖锐、越确定;top_p 是截断——只保留累计概率达到 p 的那一小圈候选再采样。
    3. 由此推出实践建议:一般只调其中一个,两个同时调会互相干扰,出了问题分不清是谁造成的。
    4. 选值不按「创意程度」凭感觉,按「这一步的输出要不要可复现」来定:工具参数、分类判断、结构化输出必须可复现,用 0。
    5. 补一句 Agent 视角:Agent 的规划与工具调用环节几乎都用低温,只有最终面向用户的自然语言回复才考虑调高。

    How to reason about it · think before answering

    1. Establish that both act on the same next-token distribution but in different ways — that is the discriminator.
    2. temperature rescales the whole distribution; top_p truncates it to the smallest set reaching cumulative probability p.
    3. Hence the practical rule: tune one, not both, or you cannot attribute a regression.
    4. Choose by reproducibility, not by vibes: tool arguments, classification and structured output must be reproducible, so use 0.
    5. Add the agent angle: planning and tool-calling steps stay cold; only the final user-facing prose warrants higher values.

    答题要点

    • temperature 缩放下一个 token 的概率分布:越低越确定,越高越随机
    • top_p 只从累计概率达到 p 的候选里采样,是另一种截断随机性的方式;一般只调其中一个
    • 结构化输出、工具参数、分类判断用 0 或接近 0,保证可复现
    • 创意写作、头脑风暴用 0.7–1.0;生产 Agent 的规划步骤通常也偏低温

    Key points

    • temperature rescales the next-token distribution: lower is more deterministic, higher more random
    • top_p samples only from the smallest set whose cumulative probability reaches p; tune one, not both
    • Use ~0 for structured output, tool arguments and classification to keep results reproducible
    • Use 0.7–1.0 for creative writing; planning steps in production agents usually stay low