langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications

Home Page:https://python.langchain.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChatZhipuAI httpcore.ReadTimeout: The read operation timed out

share1001 opened this issue · comments

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

def chat_01():
# 创建内存
memory = ConversationBufferMemory(
memory_key="chat_history",
return_messages=True,)
embeddings = HuggingFaceEmbeddings(model_name = 'm3e-base')
vector_store_milvus = Milvus(embedding_function=embeddings, connection_args={"host": "114.132.240.183", "port": 19530}, collection_name="ikbCollection")
# 创建链
chain = ConversationalRetrievalChain.from_llm(
llm=ChatZhipuAI(temperature=0.01,
api_key=ZHIPUAI_API_KEY,
# api_base=ZHIPUAI_API_BASE,
model="glm-4"),
memory=memory,
# verbose=True,
retriever = vector_store_milvus.as_retriever(),
# chain_type="stuff",
# return_source_documents=True,
)
result = chain({"question": "**名校"})
print(result)

if name == "main":
chat_01()

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
File "F:\python3.11\Lib\site-packages\httpx_transports\default.py", line 67, in map_httpcore_exceptions
yield
File "F:\python3.11\Lib\site-packages\httpx_transports\default.py", line 231, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpcore_sync\connection_pool.py", line 216, in handle_request
raise exc from None
File "F:\python3.11\Lib\site-packages\httpcore_sync\connection_pool.py", line 196, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpcore_sync\http_proxy.py", line 344, in handle_request
return self._connection.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpcore_sync\http11.py", line 132, in handle_request
raise exc
File "F:\python3.11\Lib\site-packages\httpcore_sync\http11.py", line 110, in handle_request
) = self._receive_response_headers(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpcore_sync\http11.py", line 175, in _receive_response_headers
event = self._receive_event(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpcore_sync\http11.py", line 211, in _receive_event
data = self._network_stream.read(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpcore_backends\sync.py", line 124, in read
with map_exceptions(exc_map):
File "f:\python3.11\Lib\contextlib.py", line 155, in exit
self.gen.throw(typ, value, traceback)
File "F:\python3.11\Lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ReadTimeout: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "f:\python3.11\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "f:\python3.11\Lib\runpy.py", line 88, in run_code
exec(code, run_globals)
File "c:\Users\Administrator.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy_main
.py", line 39, in
cli.main()
File "c:\Users\Administrator.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\Administrator.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="main")
File "c:\Users\Administrator.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Administrator.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\Administrator.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "D:\python_code\demo\chat_bot_demo.py", line 38, in
chat_01()
File "D:\python_code\demo\chat_bot_demo.py", line 34, in chat_01
result = chain({"question": "武汉有什么旅游政策"})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_core_api\deprecation.py", line 148, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 378, in call
return self.invoke(
^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 163, in invoke
raise e
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 153, in invoke
self._call(inputs, run_manager=run_manager)
File "F:\python3.11\Lib\site-packages\langchain\chains\conversational_retrieval\base.py", line 166, in _call
answer = self.combine_docs_chain.run(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_core_api\deprecation.py", line 148, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 574, in run
return self(kwargs, callbacks=callbacks, tags=tags, metadata=metadata)[
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_core_api\deprecation.py", line 148, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 378, in call
return self.invoke(
^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 163, in invoke
raise e
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 153, in invoke
self._call(inputs, run_manager=run_manager)
File "F:\python3.11\Lib\site-packages\langchain\chains\combine_documents\base.py", line 137, in _call
output, extra_return_dict = self.combine_docs(
^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\combine_documents\stuff.py", line 244, in combine_docs
return self.llm_chain.predict(callbacks=callbacks, **inputs), {}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\llm.py", line 293, in predict
return self(kwargs, callbacks=callbacks)[self.output_key]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_core_api\deprecation.py", line 148, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 378, in call
return self.invoke(
^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 163, in invoke
raise e
File "F:\python3.11\Lib\site-packages\langchain\chains\base.py", line 153, in invoke
self._call(inputs, run_manager=run_manager)
File "F:\python3.11\Lib\site-packages\langchain\chains\llm.py", line 103, in _call
response = self.generate([inputs], run_manager=run_manager)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain\chains\llm.py", line 115, in generate
return self.llm.generate_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_core\language_models\chat_models.py", line 560, in generate_prompt
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_core\language_models\chat_models.py", line 421, in generate
raise e
File "F:\python3.11\Lib\site-packages\langchain_core\language_models\chat_models.py", line 411, in generate
self._generate_with_cache(
File "F:\python3.11\Lib\site-packages\langchain_core\language_models\chat_models.py", line 632, in _generate_with_cache
result = self._generate(
^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\langchain_community\chat_models\zhipuai.py", line 319, in _generate
response = client.post(self.zhipuai_api_base, json=payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_client.py", line 1146, in post
return self.request(
^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_client.py", line 828, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_client.py", line 915, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_client.py", line 943, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_client.py", line 980, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_client.py", line 1016, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\python3.11\Lib\site-packages\httpx_transports\default.py", line 230, in handle_request
with map_httpcore_exceptions():
File "f:\python3.11\Lib\contextlib.py", line 155, in exit
self.gen.throw(typ, value, traceback)
File "F:\python3.11\Lib\site-packages\httpx_transports\default.py", line 84, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ReadTimeout: The read operation timed out

Description

def zhiput_chat():
    llm = ChatOpenAI(
        temperature=0.01,
        model="glm-4",
        openai_api_key=ZHIPUAI_API_KEY,
        openai_api_base="https://open.bigmodel.cn/api/paas/v4/"
    )
    prompt = ChatPromptTemplate(
        messages=[
            SystemMessagePromptTemplate.from_template(
                "你是一个能对话的机器人."
            ),
            MessagesPlaceholder(variable_name="chat_history"),
            HumanMessagePromptTemplate.from_template("{question}")
        ]
    )
 
    memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
    conversation = LLMChain(
        llm=llm,
        prompt=prompt,
        verbose=True,
        memory=memory
    )
    print(conversation.invoke({"question": "讲一个笑话"}))

使用ChatOpenAI能够正常调用,ChatZhipuAI就不行,希望修复问题后测试一下

System Info

pip install langchain==0.1.16
platform window10
python version 3.11