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

fix: bad response type in /anthropic/claude.py #1127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

husainsyed
Copy link

Bug: Running Anthropic with search_knowledge=True yields:

Traceback (most recent call last):
  File "C:\Users\hassa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\phi\llm\anthropic\claude.py", line 405, in response_stream
    yield from self.response(messages=messages)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hassa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\phi\llm\anthropic\claude.py", line 168, in response
    response_content: TextBlock = response.content[0].text  # type: ignore
                                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\hassa\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pydantic\main.py", line 853, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'ToolUseBlock' object has no attribute 'text'

Steps to reproduce:
Run on a knowledge base with search_knowledge=True for 5-10 times - you will run into this error.

Fix:
Added type checking for both TextBlock & ToolUseBlock.

Copy link
Contributor

@jacobweiss2305 jacobweiss2305 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and approved

@jacobweiss2305 jacobweiss2305 self-assigned this Sep 15, 2024
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

Successfully merging this pull request may close these issues.

2 participants