langchain icon indicating copy to clipboard operation
langchain copied to clipboard

TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'

Open ciaran-regan-ie opened this issue 1 year ago • 7 comments

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.

ciaran-regan-ie avatar May 17 '23 02:05 ciaran-regan-ie

same issue

zhyjiong avatar May 17 '23 16:05 zhyjiong

Same issue

bear96 avatar May 17 '23 18:05 bear96

Same issue

LouisSilva avatar May 17 '23 21:05 LouisSilva

Same issue

vanakema avatar May 18 '23 03:05 vanakema

same issue

arttukataja avatar May 18 '23 11:05 arttukataja

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()

alfred-liu96 avatar May 20 '23 11:05 alfred-liu96

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()

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..

bear96 avatar May 20 '23 18:05 bear96