run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
35.38k stars 4.98k forks source link

[Bug]: AttributeError: 'Anthropic' object has no attribute 'beta' #14103

Closed clstaudt closed 3 months ago

clstaudt commented 3 months ago

Bug Description

from llama_index.llms.anthropic import Anthropic

llm = Anthropic(
    model="claude-3-opus-20240229",
    api_key=secrets.get_secret("key_anthropic.txt"),
)

response = llm.complete("Colorless green ideas...")
print(response.text)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[17], [line 1](vscode-notebook-cell:?execution_count=17&line=1)
----> [1](vscode-notebook-cell:?execution_count=17&line=1) response = llm.complete("Colorless green ideas...")
      [2](vscode-notebook-cell:?execution_count=17&line=2) show.text(response.text)

File ~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:223, in Dispatcher.span.<locals>.wrapper(func, instance, args, kwargs)
    [219](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:219) self.span_enter(
    [220](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:220)     id_=id_, bound_args=bound_args, instance=instance, parent_id=parent_id
    [221](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:221) )
    [222](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:222) try:
--> [223](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:223)     result = func(*args, **kwargs)
    [224](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:224) except BaseException as e:
    [225](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py:225)     self.event(SpanDropEvent(span_id=id_, err_str=str(e)))

File ~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:389, in llm_completion_callback.<locals>.wrap.<locals>.wrapped_llm_predict(_self, *args, **kwargs)
    [380](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:380) event_id = callback_manager.on_event_start(
    [381](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:381)     CBEventType.LLM,
    [382](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:382)     payload={
   (...)
    [386](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:386)     },
    [387](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:387) )
    [388](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:388) try:
--> [389](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:389)     f_return_val = f(_self, *args, **kwargs)
    [390](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:390) except BaseException as e:
...
   (...)
    [226](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:226)     raw=dict(response),
    [227](https://file+.vscode-resource.vscode-cdn.net/Users/cls/Documents/Work/Training/AIDojo/ai-dojo/notebooks/language-models/~/miniforge3/envs/ai-dojo/lib/python3.11/site-packages/llama_index/llms/anthropic/base.py:227) )

AttributeError: 'Anthropic' object has no attribute 'beta'

Version

0.10.43, 0.10.44

Steps to Reproduce

See code above

Relevant Logs/Tracbacks

No response

dosubot[bot] commented 3 months ago

The AttributeError: 'Anthropic' object has no attribute 'beta' suggests that the Anthropic class is being accessed in a way that expects an attribute named beta, which does not exist in the class definition.

The Anthropic class in the llama_index.llms.anthropic module defines the following attributes and methods, but beta is not one of them [1][2]:

Attributes:

Methods:

To resolve this issue, ensure that your code does not reference a non-existent attribute beta. If you need further assistance, please provide more context or check if there are any custom modifications or extensions to the Anthropic class in your environment.

To continue talking to Dosu, mention @dosu.

rinmy23 commented 3 months ago

I have the same problem. My code can run correctly before yesterday and i didn't change my code, but now it have the same AttributeError: 'Anthropic' object has no attribute 'beta'

clstaudt commented 3 months ago

The dosu bot isn't even smart enough to recognize that it's not my code triggering the error.

logan-markewich commented 3 months ago

@rinmy23 @clstaudt anthropic recently moved their tools api from beta to GA, and updated their latest client SDK

Downgrade the client SDK if you need it to work right now, but will have a new version published in 30 mins or so

clstaudt commented 3 months ago

@logan-markewich How to install the fix?

clstaudt commented 3 months ago

Downgrade the client SDK if you need it to work right now,

@logan-markewich What is the client SDK here? I am a bit confused about the many sub-packages and how they relate to the main llama_index package.