llama-index,uncharted and llama2:7b run locally to generate Index

一给  金牌会员 | 2024-7-22 00:59:05 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 649|帖子 649|积分 1947

题意:本地运行 llama-index、uncharted 以及 llama2:7b 来生成索引


题目配景:

I wanted to use llama-index locally with ollama and llama3:8b to index utf-8 json file. I dont have a gpu. I use uncharted to convert docs into json. Now If it is not possible to use llama-index locally without GPU I wanted to use hugging face inference API. But I am not certain if it is free. Can anyone suggest a way?
This is my python code:
  1. from llama_index.core import Document, SimpleDirectoryReader, VectorStoreIndex
  2.     from llama_index.llms.ollama import Ollama
  3.     import json
  4.     from llama_index.core import Settings
  5.    
  6.    
  7.     # Convert the JSON document into LlamaIndex Document objects
  8.     with open('data/UBER_2019.json', 'r',encoding='utf-8') as f:
  9.         json_doc = json.load(f)
  10.     documents = [Document(text=str(doc)) for doc in json_doc]
  11.    
  12.     # Initialize Ollama with the local LLM
  13.     ollama_llm = Ollama(model="llama3:8b")
  14.     Settings.llm = ollama_llm
  15.    
  16.     # Create the index using the local LLM
  17.     index = VectorStoreIndex.from_documents(documents)#, llm=ollama_llm)
复制代码
But i keep getting error that there is no OPENAI key. I wanted to use llama2 so that i dont require OPENAI key
Can anyone suggest what i am doing wrong? Also can i use huggingfaceinference API to do indexing of a local json file for free?

题目办理:

You are not setting the embedding model, so I think Llama Index is defaulting to OpenAI.
You must specify an embedding model that does not require an API key.
You can use Ollama:
  1. from llama_index.embeddings.ollama import OllamaEmbedding
  2. # Using Nomic
  3. Settings.embed_model = OllamaEmbedding(model_name="nomic-embed-text")
  4. # Using Llama
  5. Settings.embed_model = OllamaEmbedding(model_name="llama2")
复制代码
But there are many options in the documentation like this, this, this



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

一给

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表