Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: AttributeError: 'NoneType' object has no attribute 'clear' #528

Closed
younes-io opened this issue Mar 2, 2024 · 3 comments
Closed

Bug: AttributeError: 'NoneType' object has no attribute 'clear' #528

younes-io opened this issue Mar 2, 2024 · 3 comments

Comments

@younes-io
Copy link

I got this simple code:

question = "What is the capital of Japan?"

rag_with_assertions(question=question)

which throws this error AttributeError: 'NoneType' object has no attribute 'clear' because of this line:

dsp.settings.trace.clear()

{
	"name": "AttributeError",
	"message": "'NoneType' object has no attribute 'clear'",
	"stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 3
      1 question = \"What is the capital of Japan?\"
----> 3 rag_with_assertions(question=question)

File /workspaces/aider_repos/.venv/lib/python3.12/site-packages/dspy/primitives/program.py:29, in Module.__call__(self, *args, **kwargs)
     28 def __call__(self, *args, **kwargs):
---> 29     return self.forward(*args, **kwargs)

File /workspaces/aider_repos/.venv/lib/python3.12/site-packages/dspy/primitives/assertions.py:317, in handle_assert_forward.<locals>.forward(self, *args, **kwargs)
    314     dspy.settings.configure(bypass_assert=args_to_vals[\"bypass_assert\"])
    316 wrapped_forward = assertion_handler(self._forward, **handler_args)
--> 317 return wrapped_forward(*args, **kwargs)

File /workspaces/aider_repos/.venv/lib/python3.12/site-packages/dspy/primitives/assertions.py:240, in backtrack_handler.<locals>.wrapper(*args, **kwargs)
    238 else:
    239     try:
--> 240         dsp.settings.trace.clear()
    241         result = func(*args, **kwargs)
    242         break

AttributeError: 'NoneType' object has no attribute 'clear'"
}
@okhat
Copy link
Collaborator

okhat commented Mar 2, 2024

I believe assertions currently ask you to add a line at the top of your file.

dspy.configure(trace=[])

or something like that?

@sleeper
Copy link
Contributor

sleeper commented Mar 29, 2024

I had the same problem, and initializing the traces to an empty array as advised by @okhat worked. This bug can probably be closed.

@fireking77
Copy link

@okhat your sollution worked for me too Thanks!
;), but may I ask where can I check this in doc or somewhere. Can u please point me into the right direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants