type
Post
status
Published
date
Nov 20, 2025
slug
summary
tags
人工智能
category
技术分享
icon
password
当 token_counter=llm 时,LangChain 会调用模型对象的 get_num_tokens_from_messages() 方法。由于你使用的是 ChatOpenAI 包装的 DeepSeek,LangChain 的底层代码会尝试用 OpenAI 的 tiktoken 库来计算 Token。但因为模型名称是 deepseek-chat 而不是 gpt-3.5-turbo 等标准名称,tiktoken 无法识别,从而抛出“未实现”的错误。
LangChain 的 trim_messages 对 token_counter 的字符串支持比较有限(通常只支持 "approximate",即简单粗暴地按字符数估算)。# 在生产环境下,为了精确适配 DeepSeek,必须传递一个可执行的函数作为计数器。解决办法
- Author:guderain
- URL:https://wangguanxi.space/article/2e02b727-a3a3-80cf-b87e-c41507646104
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts


.webp?table=collection&id=92be88af-5f71-4631-9d3e-ee3bd53dcced&t=92be88af-5f71-4631-9d3e-ee3bd53dcced&width=1080&cache=v2)