LightRAG/examples/lightrag_openai_demo.py

34 lines
937 B
Python
Raw Normal View History

2024-10-15 19:40:08 +08:00
import os
import sys
from lightrag import LightRAG, QueryParam
from lightrag.llm import gpt_4o_mini_complete, gpt_4o_complete
from transformers import AutoModel,AutoTokenizer
2024-10-15 21:11:12 +08:00
WORKING_DIR = "/home/zrguo/code/myrag/agriculture"
2024-10-15 19:40:08 +08:00
if not os.path.exists(WORKING_DIR):
os.mkdir(WORKING_DIR)
rag = LightRAG(
working_dir=WORKING_DIR,
2024-10-15 21:11:12 +08:00
llm_model_func=gpt_4o_mini_complete
# llm_model_func=gpt_4o_complete
2024-10-15 19:40:08 +08:00
)
with open("./book.txt") as f:
rag.insert(f.read())
# Perform naive search
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="naive")))
# Perform local search
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="local")))
# Perform global search
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="global")))
# Perform hybrid search
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid")))