当前行为
当我尝试将gptcache用作langchan缓存时,发现了以下错误信息:
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 361, in acall
raise e
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 355, in acall
await self._acall(inputs, run_manager=run_manager)
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/agents/agent.py", line 1088, in _acall
next_step_output = await self._atake_next_step(
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/agents/agent.py", line 932, in _atake_next_step
output = await self.agent.aplan(
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/agents/agent.py", line 477, in aplan
full_output = await self.llm_chain.apredict(callbacks=callbacks, **full_inputs)
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/llm.py", line 272, in apredict
return (await self.acall(kwargs, callbacks=callbacks))[self.output_key]
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 361, in acall
raise e
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 355, in acall
await self._acall(inputs, run_manager=run_manager)
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/llm.py", line 237, in _acall
response = await self.agenerate([inputs], run_manager=run_manager)
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chains/llm.py", line 115, in agenerate
return await self.llm.agenerate_prompt(
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chat_models/base.py", line 424, in agenerate_prompt
return await self.agenerate(
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chat_models/base.py", line 384, in agenerate
raise exceptions[0]
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/chat_models/base.py", line 495, in _agenerate_with_cache
return ChatResult(generations=cache_val)
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 1076, in pydantic.main.validate_model
File "pydantic/fields.py", line 895, in pydantic.fields.ModelField.validate
File "pydantic/fields.py", line 928, in pydantic.fields.ModelField._validate_sequence_like
File "pydantic/fields.py", line 1094, in pydantic.fields.ModelField._validate_singleton
File "pydantic/fields.py", line 884, in pydantic.fields.ModelField.validate
File "pydantic/fields.py", line 1101, in pydantic.fields.ModelField._validate_singleton
File "pydantic/fields.py", line 1157, in pydantic.fields.ModelField._apply_validators
File "pydantic/class_validators.py", line 337, in pydantic.class_validators._generic_validator_basic.lambda13
File "pydantic/main.py", line 719, in pydantic.main.BaseModel.validate
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/load/serializable.py", line 75, in __init__
super().__init__(**kwargs)
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 1102, in pydantic.main.validate_model
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/langchain/schema/output.py", line 61, in set_text
values["text"] = values["message"].content
KeyError: 'message'
似乎当前的gptcache不支持聊天生成相关的API。我想确认如何处理和修复它?
环境
gptcache==0.1.39.1
langchain==0.0.281
- CacheBase --> postgresql
- VectorBase --> pgvector
- Azure OpenAI模型 --> gpt-35-turbo-16k
初始化缓存示例代码
from langchain.cache import GPTCache
from gptcache.adapter.api import init_similar_cache
init_similar_cache(
cache_obj=cache_obj,
data_dir=f"similar_cache_{hashed_llm}",
embedding=openai_embedding,
data_manager=data_manager,
)
langchain.llm_cache = GPTCache(init_llm_cache)
预期行为
- 无响应*
重现步骤
- 无响应*
环境
- 无响应*
其他事项?
- 无响应*
4条答案
按热度按时间jhdbpxl91#
It seems that langchain is incompatible with gptcache
wj8zmpe12#
根据 this question in Microsoft ,当前的
GPT 3.5 turbo
和GPT 3.5 turbo 16k
只支持聊天补全 API,因此我们只能使用基于聊天的模型作为 LLM 来开发相关链和代理。但是 gptcache this issue 有一些讨论表明它不支持聊天生成。然而,我也跟踪了错误信息,实际上该模型正在使用聊天补全 API 来打包消息,而当前的 gptcache 无法解析这种格式。我认为这可能是导致不兼容性的一个可能原因。yduiuuwa3#
@hueiyuan 你能给我展示一个关于这个案例的完整演示代码吗?
a0zr77ik4#
这是我的示例演示代码,供您参考,您需要替换与配置相关的字典变量: