Llama_index利用本地大模型工具ollama(CPU)

Llama_index利用本地大模型工具ollama(CPU)

    正在检查是否收录...

基于ollama的本地大模型的LlamaIndex示例代码

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings from llama_index.core.embeddings import resolve_embed_model from llama_index.llms.ollama import Ollama import logging import sys logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout)) documents = SimpleDirectoryReader("data").load_data() # bge embedding model Settings.embed_model = resolve_embed_model("local:/Users/leicq/ai_pychat/BAAI_bge-base-zh-v1.5") # ollama Settings.llm = Ollama(model="llama2-chinese", request_timeout=30.0) import os.path from llama_index.core import ( VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage, ) # check if storage already exists PERSIST_DIR = "./storage" if not os.path.exists(PERSIST_DIR): # load the documents and create the index documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents) # store it for later index.storage_context.persist(persist_dir=PERSIST_DIR) else: # load the existing index storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR) index = load_index_from_storage(storage_context) # Either way we can now query the index query_engine = index.as_query_engine() response = query_engine.query("What did the author do growing up?") print(response) 

llamaragctodocstorellm大模型chatllmslmsllamaindexdebugcreatellama2etl
  • 本文作者:李琛
  • 本文链接: https://wapzz.net/post-17348.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
本站部分内容来源于网络转载,仅供学习交流使用。如涉及版权问题,请及时联系我们,我们将第一时间处理。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
2.3W+
5
0
1
WAP站长官方

AI日报:谷歌发布最强开源语言模型Gemma2;讯飞星火V4炸场;Glif作者创建meme梗图生成器风靡推特

上一篇

InsCode Stable Diffusion使用教程(非常详细)从零基础入门到精通,看完这一篇就够了_outpainting 模型下载(3)

下一篇
  • 复制图片
按住ctrl可打开默认菜单