Apologies - this is the link for the notebook github.com/NVIDIA/GenerativeAIExamples/blob/main/community/llm_video_series/video_1_llamaindex_basic_RAG.ipynb
I'm currently encountering a problem. I followed the reference program, but the message "ModuleNotFoundError: No module named 'milvus_lite'" will appear. I'm running it using the Windows operating system. Is there any way to solve it?
import os import gradio as gr from llama_index.core import SimpleDirectoryReader, VectorStoreIndex,StorageContext, load_index_from_storage from llama_index.vector_stores.milvus import MilvusVectorStore from llama_index.embeddings.nvidia import NVIDIAEmbedding from llama_index.llms.nvidia import NVIDIA from llama_index.core.node_parser import SentenceSplitter from llama_index.core import Settings Settings.test.splitter = SentenceSplitter(chunk_size=500) Settings.embed_model = NVIDIAEmbedding(model="NV-Embed-QA",truncate="END") Settings.llm = NVIDIA(model="meta/llama3-70b-instruct") if os.getenv("NVIDIA_API_KEY") is None: raise ValueError("NVIDIA_API_KEY is not set") index = None query_engine = None def get_files_from_input(file_object): if not file_object: return [] return [file_obj.name for file_obj in file_object] def load_documents(file_objs): global index,query_engine try: if not file_objs: return "Error no file selected." file_paths = get_files_from_input(file_objs) documents = [] for file_path in file_paths: directory = os.path.dirname(file_path) documents.extend(SimpleDirectoryReader(input_files=(file_path)).load_data()) if not documents: return f"No documents found in the selected files" vector_store = MilvusVectorStore(url="./milvus_demo.db",dim=1024,overwrite = True) storage_context = StorageContext.from_defaults(vector_store=vector_store) index = VectorStoreIndex.from_documents(documents,storage_context=storage_context) query_engine = index.as_query_engine(similarity_top_k = 20,streaming=True) except Exception as e: return f"Error loading documents: {str(e)}" def chat(message,history): global query_engine if query_engine is None: return history + [("Please load document first.",None)] try: response = query_engine.query(message) return history+[(message,response)] except Exception as e: return history+[(message,f"Error processing query: {str(e)} ")] def stream_response(message,history): global query_engine if query_engine is None: yield history+[("Please load the document first.",None)] return try: response = query_engine.query(message) partial_response = "" for text in response.response_gen: partial_response+=text yield history + [(message,partial_response)] except Exception as e: yield history + [(message,f"Error processing query: {str(e)}")] with gr.Blocks() as demo: gr.Markdown("Optimistic chat application") with gr.Row(): file_input = gr.File(label="Select files to load",file_count="multiple") load_btn = gr.Button("load documents") load_output = gr.Textbox(label="load status") chatbot = gr.Chatbot() msg = gr.Textbox(label="Enter your question",interactive=True) clear = gr.Button("clear") load_btn.click(load_documents,inputs=[file_input],outputs=[load_output]) msg.submit(stream_response,inputs=[msg,chatbot],outputs=[chatbot]) msg.submit(lambda:"",outputs=[msg]) clear.click(lambda :None,None,chatbot,queue=False) if __name__== "__main__": demo.launch()
But where do we get the requirement.txt file??
works nicely the sample notebook, gracias
Notebook link is broken. Perhaps on a diff branch?
Apologies - this is the link for the notebook github.com/NVIDIA/GenerativeAIExamples/blob/main/community/llm_video_series/video_1_llamaindex_basic_RAG.ipynb
I'm currently encountering a problem. I followed the reference program, but the message "ModuleNotFoundError: No module named 'milvus_lite'" will appear. I'm running it using the Windows operating system. Is there any way to solve it?
Do i need an NVIDIA credit to reference the NIM API?
Excelente, gracias.
worked nicely great video, too.
Where do we find the code for this specific example?
I rewrote the code from the video onto my notebook. Works well
import os
import gradio as gr
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex,StorageContext, load_index_from_storage
from llama_index.vector_stores.milvus import MilvusVectorStore
from llama_index.embeddings.nvidia import NVIDIAEmbedding
from llama_index.llms.nvidia import NVIDIA
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core import Settings
Settings.test.splitter = SentenceSplitter(chunk_size=500)
Settings.embed_model = NVIDIAEmbedding(model="NV-Embed-QA",truncate="END")
Settings.llm = NVIDIA(model="meta/llama3-70b-instruct")
if os.getenv("NVIDIA_API_KEY") is None:
raise ValueError("NVIDIA_API_KEY is not set")
index = None
query_engine = None
def get_files_from_input(file_object):
if not file_object:
return []
return [file_obj.name for file_obj in file_object]
def load_documents(file_objs):
global index,query_engine
try:
if not file_objs:
return "Error no file selected."
file_paths = get_files_from_input(file_objs)
documents = []
for file_path in file_paths:
directory = os.path.dirname(file_path)
documents.extend(SimpleDirectoryReader(input_files=(file_path)).load_data())
if not documents:
return f"No documents found in the selected files"
vector_store = MilvusVectorStore(url="./milvus_demo.db",dim=1024,overwrite = True)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents,storage_context=storage_context)
query_engine = index.as_query_engine(similarity_top_k = 20,streaming=True)
except Exception as e:
return f"Error loading documents: {str(e)}"
def chat(message,history):
global query_engine
if query_engine is None:
return history + [("Please load document first.",None)]
try:
response = query_engine.query(message)
return history+[(message,response)]
except Exception as e:
return history+[(message,f"Error processing query: {str(e)} ")]
def stream_response(message,history):
global query_engine
if query_engine is None:
yield history+[("Please load the document first.",None)]
return
try:
response = query_engine.query(message)
partial_response = ""
for text in response.response_gen:
partial_response+=text
yield history + [(message,partial_response)]
except Exception as e:
yield history + [(message,f"Error processing query: {str(e)}")]
with gr.Blocks() as demo:
gr.Markdown("Optimistic chat application")
with gr.Row():
file_input = gr.File(label="Select files to load",file_count="multiple")
load_btn = gr.Button("load documents")
load_output = gr.Textbox(label="load status")
chatbot = gr.Chatbot()
msg = gr.Textbox(label="Enter your question",interactive=True)
clear = gr.Button("clear")
load_btn.click(load_documents,inputs=[file_input],outputs=[load_output])
msg.submit(stream_response,inputs=[msg,chatbot],outputs=[chatbot])
msg.submit(lambda:"",outputs=[msg])
clear.click(lambda :None,None,chatbot,queue=False)
if __name__== "__main__":
demo.launch()
Nice 👍🏻
🍁🍁🍁🍁🍁