检查其他资源
- 我为这个问题添加了一个非常描述性的标题。
- 我使用集成搜索在LangChain文档中进行了搜索。
- 我使用GitHub搜索查找了一个类似的问题,但没有找到。
- 我确信这是LangChain中的一个bug,而不是我的代码。
- 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此bug。
示例代码
代码基本上是:https://python.langchain.com/docs/use_cases/question_answering/chat_history/,但使用AzureSearch的异步API。
from langchain_community.vectorstores.azuresearch import AzureSearch
retriver = AzureSearch().as_retriever()
#...
astream = pipeline.astream({"input": user_question})
async for chunk in astream:
print(chunk)
结果是 NotImplementedError: AzureSearchVectorStoreRetriever does not support async
,但在之前的版本中运行得很好。
错误信息和堆栈跟踪(如果适用)
2024-04-23 11:58:15,788 ERROR Exception inside application: 'async_generator' object is not iterable
Traceback (most recent call last):
File "/app/gpt_exploration/chat.py", line 132, in run_async_query
async for chunk in astream:
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4704, in astream
async for item in self.bound.astream(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4704, in astream
async for item in self.bound.astream(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2900, in astream
async for chunk in self.atransform(input_aiter(), config, **kwargs):
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2883, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2853, in _atransform
async for output in final_pipeline:
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4740, in atransform
async for item in self.bound.atransform(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2883, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2853, in _atransform
async for output in final_pipeline:
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/passthrough.py", line 587, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/passthrough.py", line 577, in _atransform
yield await first_map_chunk_task
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 62, in anext_impl
return await __anext__(iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3317, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3304, in _atransform
chunk = AddableDict({step_name: task.result()})
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3287, in get_next_chunk
return await py_anext(generator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4740, in atransform
async for item in self.bound.atransform(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2883, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2853, in _atransform
async for output in final_pipeline:
File "/usr/local/lib/python3.12/site-packages/langchain_core/output_parsers/transform.py", line 60, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1943, in _atransform_stream_with_config
final_input: Optional[Input] = await py_anext(input_for_tracing, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 62, in anext_impl
return await __anext__(iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 97, in tee_peer
item = await iterator.__anext__()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1316, in atransform
async for chunk in input:
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1316, in atransform
async for chunk in input:
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4740, in atransform
async for item in self.bound.atransform(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/passthrough.py", line 587, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/passthrough.py", line 577, in _atransform
yield await first_map_chunk_task
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 62, in anext_impl
return await __anext__(iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3317, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3304, in _atransform
chunk = AddableDict({step_name: task.result()})
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3287, in get_next_chunk
return await py_anext(generator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4172, in atransform
async for output in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4086, in _atransform
async for ichunk in input:
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 97, in tee_peer
item = await iterator.__anext__()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 97, in tee_peer
item = await iterator.__anext__()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 97, in tee_peer
item = await iterator.__anext__()
^^^^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 7 more times]
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/passthrough.py", line 587, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/passthrough.py", line 577, in _atransform
yield await first_map_chunk_task
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/utils/aiter.py", line 62, in anext_impl
return await __anext__(iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3317, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3304, in _atransform
chunk = AddableDict({step_name: task.result()})
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3287, in get_next_chunk
return await py_anext(generator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 4740, in atransform
async for item in self.bound.atransform(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1333, in atransform
async for output in self.astream(final, config, **kwargs):
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/branch.py", line 380, in astream
async for chunk in runnable.astream(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2900, in astream
async for chunk in self.atransform(input_aiter(), config, **kwargs):
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2883, in atransform
async for chunk in self._atransform_stream_with_config(
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1979, in _atransform_stream_with_config
chunk: Output = await asyncio.create_task( # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2853, in _atransform
async for output in final_pipeline:
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1333, in atransform
async for output in self.astream(final, config, **kwargs):
File "/usr/local/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 820, in astream
yield await self.ainvoke(input, config, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/retrievers.py", line 227, in ainvoke
return await self.aget_relevant_documents(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_core/retrievers.py", line 384, in aget_relevant_documents
raise e
File "/usr/local/lib/python3.12/site-packages/langchain_core/retrievers.py", line 377, in aget_relevant_documents
result = await self._aget_relevant_documents(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/langchain_community/vectorstores/azuresearch.py", line 735, in _aget_relevant_documents
raise NotImplementedError(
NotImplementedError: AzureSearchVectorStoreRetriever does not support async
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/asgiref/sync.py", line 518, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.12/site-packages/django/http/response.py", line 514, in __aiter__
async for part in self.streaming_content:
File "/usr/local/lib/python3.12/site-packages/django/http/response.py", line 471, in awrapper
async for part in _iterator:
File "/app/gpt_exploration/chat.py", line 152, in run_async_query
store_data(session_id, answer_id, user_question, answer, answer_time, doc_context['context'], configuration_id)
~~~~~~~~~~~^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 170, in __call__
await self.handle(scope, receive, send)
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 209, in handle
task.result()
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 193, in process_request
await self.send_response(response, send)
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 325, in send_response
async for part in content:
File "/usr/local/lib/python3.12/site-packages/django/http/response.py", line 524, in __aiter__
for part in await sync_to_async(list)(self.streaming_content):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/asgiref/sync.py", line 468, in __call__
ret = await asyncio.shield(exec_coro)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/asgiref/sync.py", line 520, in thread_handler
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: 'async_generator' object is not iterable
描述
这是一个回归,安装langchain-community==0.0.33
可以解决问题,安装langchain-community==0.0.34
会破坏。
系统信息
langchain==0.1.8
0.0.33 可以工作
langchain-community==0.0.34
langchain-core==0.1.44
langchain-openai==0.0.6
1条答案
按热度按时间tkclm6bt1#
这在0.0.33版本中有效,因为
as_retriever
返回的是VectorStore
。但在0.0.34版本中,它现在返回的是AzureSearchVectorStoreRetriever
,该类并未实现异步操作。