添加初始文件和功能,包括数据集和文档类的定义,以及添加文档块的用户界面

This commit is contained in:
2025-07-04 18:26:36 +08:00
parent db6f3b865f
commit 587305f070
7 changed files with 133 additions and 0 deletions

45
src/add_chunk.py Normal file
View File

@@ -0,0 +1,45 @@
from tkinter import Tk, StringVar, Label, OptionMenu, Button, filedialog
from ragflow_sdk import RAGFlow
api_key = "ragflow-I5ZDNjMWNhNTdlMjExZjBiOTEwMzI0ZT"
base_url = "http://192.168.107.165:8099"
rag_object = RAGFlow(api_key=api_key, base_url=base_url)
def add_chunk_to_document():
dataset_id = dataset_var.get()
document_id = document_var.get()
file_path = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])
if file_path:
with open(file_path, 'r') as file:
content = file.read()
rag_object.add_chunk(dataset_id, document_id, content)
def update_documents(*args):
dataset_name = dataset_var.get()
dataset = rag_object.list_datasets(name=dataset_name)
dataset = dataset[0]
documents = dataset.list_documents()
document_menu['menu'].delete(0, 'end')
for doc in documents:
document_menu['menu'].add_command(label=doc.name, command=lambda value=doc.name: document_var.set(value))
root = Tk()
root.title("Add Chunk to Document")
dataset_var = StringVar(root)
document_var = StringVar(root)
datasets = rag_object.list_datasets()
dataset_menu = OptionMenu(root, dataset_var, *[ds.name for ds in datasets], command=update_documents)
dataset_menu.pack()
document_menu = OptionMenu(root, document_var, "")
document_menu.pack()
add_chunk_button = Button(root, text="Add Chunk", command=add_chunk_to_document)
add_chunk_button.pack()
root.mainloop()