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,必须传递一个可执行的函数作为计数器。
 
解决办法
redis/postgre 持久化存储memory方法ConversationChain(已废弃)与现代写法RunnableWithMessageHistory
Loading...