-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
AttributeError: 'AIMessageChunk' object has no attribute 'text' #18024
Comments
confirmed |
Fix merged. Closing issue -- will be available in next release. @FloTeu we recommend transitioning into the partner package for open ai rather than using the community version. |
@eyurtsev This is the code causing the issue:
|
Downgraded LangChain until issue below is resolved: langchain-ai/langchain#18024 resolves #6
Checked other resources
Example Code
install the following dependencies
pip install openai pip install google-search-results pip install langchain # version 0.1.9 pip install numexpr
Run the following python code (and add the openai api key):
Error Message and Stack Trace (if applicable)
AttributeError: 'AIMessageChunk' object has no attribute 'text'
Trace
Traceback (most recent call last):
File "/Users/fteutsch/Desktop/PythonProjects/private/digiprod-gen/bug_report.py", line 31, in
agent_executor.invoke({"input": input_prompt})
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 163, in invoke
raise e
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 153, in invoke
self._call(inputs, run_manager=run_manager)
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1391, in _call
next_step_output = self._take_next_step(
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1097, in _take_next_step
[
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1097, in
[
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1125, in _iter_next_step
output = self.agent.plan(
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 387, in plan
for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}):
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 2427, in stream
yield from self.transform(iter([input]), config, **kwargs)
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 2414, in transform
yield from self._transform_stream_with_config(
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1494, in _transform_stream_with_config
chunk: Output = context.run(next, iterator) # type: ignore
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 2378, in _transform
for output in final_pipeline:
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1032, in transform
for chunk in input:
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 4167, in transform
yield from self.bound.transform(
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 1042, in transform
yield from self.stream(final, config, **kwargs)
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 250, in stream
raise e
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 234, in stream
for chunk in self._stream(
File "/Users/fteutsch/Library/Caches/pypoetry/virtualenvs/digiprod-gen-qSAcCc-Q-py3.10/lib/python3.10/site-packages/langchain_community/chat_models/openai.py", line 418, in _stream
run_manager.on_llm_new_token(chunk.text, chunk=cg_chunk)
AttributeError: 'AIMessageChunk' object has no attribute 'text'
Description
Since i updated langchain from 0.1.7 to latest version 0.1.9 i got the exception mentioned above.
I already found the issue and maybe the solution as well.
libs/community/langchain_community/chat_models/openai.py
lines 414-418
chunk has the type AIMessageChunk which does not contain the attribute text, whereas cg_chunk has the type ChatGenerationChunk which contains text as attribute (and in version 0.1.7 the same class was used).
The fix probably would be:
line 510 in the same file contains the same issue.
System Info
langchain==0.1.9
langchain-community==0.0.22
langchain-core==0.1.26
langchainhub==0.1.14
macOs
python 3.10
The text was updated successfully, but these errors were encountered: