langchain
langchain copied to clipboard
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'
System Info
langchain version 0.0.171 python version 3.9.13
macos
Who can help?
No response
Information
- [X] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [X] Memory
- [X] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
This is a problem with the generative agents.
To reproduce please follow the tutorial outlines here: https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html
When you get to the following line of code you will get an error:
print(tommie.get_summary(force_refresh=True))
File ~/.pyenv/versions/3.9.13/lib/python3.9/site-packages/langchain/retrievers/time_weighted_retriever.py:14, in _get_hours_passed(time, ref_time)
12 def _get_hours_passed(time: datetime.datetime, ref_time: datetime.datetime) -> float:
13 """Get the hours passed between two datetime objects."""
---> 14 return (time - ref_time).total_seconds() / 3600
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'
Expected behavior
The ref time should be a datetime and tommies summary should be printed.
same issue
Same issue
Same issue
Same issue
same issue
It was caused by the parameter now
.
There are sevaral functions in the GenerativeAgent
and GenerativeAgentMemory
class that are needed to fill in the parameter now
, such as add_memory
, generate_dialogue_response
or generate_reaction
. It is optional but without filling it, errors like above will occur.
I think it shoud be changed to required or default to be datatime.datetime.now()
It was caused by the parameter
now
.
There are sevaral functions in the
GenerativeAgent
andGenerativeAgentMemory
class that are needed to fill in the parameternow
, such asadd_memory
,generate_dialogue_response
orgenerate_reaction
. It is optional but without filling it, errors like above will occur.I think it shoud be changed to required or default to be
datatime.datetime.now()
I agree. I found that this now is an optional parameter which takes the value of None if not specified. Every time I add a memory, the creation time becomes none. So it wasn't working..