自学内容网 自学内容网

解决llama_index中使用Ollama出现timed out 问题

现象:

  File "~/anaconda3/envs/leo_py38/lib/python3.8/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: timed out

代码:

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.ollama import Ollama

###定义使用的llm,embedding 模型
llm = Ollama(model="yi:34b")
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-large-zh-v1.5")
Settings.llm = llm
Settings.embed_model = embed_model

## 加载文档
documents = SimpleDirectoryReader("../../data").load_data()
print("documents: ", len(documents))

## 构建index
index = VectorStoreIndex.from_documents(documents, show_progress=True)

## 构建query engine
query_engine = index.as_query_engine()
query = "身长九尺,髯长二尺的人是谁?"

## query
response = query_engine.query(query)
print(f"query:{query}")
print(f"查询结果:{response}")

解决办法是增加timeout时长

llm = Ollama(model="yi:34b", request_timeout=500)

原文地址:https://blog.csdn.net/leo0308/article/details/140620295

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!