Refactor: reformat all code for lefthook using ruff and gofmt (#16585)

This commit is contained in:
Wang Qi
2026-07-03 12:53:39 +08:00
committed by GitHub
parent 19fcb4a981
commit 6a4b9be426
588 changed files with 11123 additions and 15412 deletions

View File

@@ -15,7 +15,7 @@
#
"""
The example demonstrates how to create a chat assistant, manage sessions,
The example demonstrates how to create a chat assistant, manage sessions,
and perform both standard and streaming chat.
"""
@@ -39,7 +39,7 @@ try:
name="Test Assistant",
dataset_ids=[dataset.id],
llm_id="deepseek-chat", # Example LLM ID, replace with your actual model ID
prompt_config={"system": "You are a helpful assistant."}
prompt_config={"system": "You are a helpful assistant."},
)
print(f"Assistant created: {assistant.name} (ID: {assistant.id})")
@@ -52,12 +52,12 @@ try:
print("\n--- Standard Chat ---")
question = "What is RAGFlow?"
print(f"User: {question}")
# ask returns a generator of Message objects
# for stream=False, it yields once with the full answer
for message in session.ask(question=question, stream=False):
print(f"Assistant: {message.content}")
if hasattr(message, 'reference') and message.reference:
if hasattr(message, "reference") and message.reference:
print(f"References used: {len(message.reference)} chunks")
# 5. Streaming chat
@@ -65,10 +65,10 @@ try:
question = "Tell me more about its features."
print(f"User: {question}")
print("Assistant: ", end="", flush=True)
for message in session.ask(question=question, stream=True):
# In streaming mode, each message.content usually contains the incremental part
# or the full content so far depending on the SDK implementation.
# or the full content so far depending on the SDK implementation.
# Based on RAGFlow SDK, it typically yields incremental parts.
print(message.content, end="", flush=True)
print("\n")

View File

@@ -38,21 +38,21 @@ try:
print("Uploading document...")
# Using a simple text content for example
content = "RAGFlow is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document understanding."
docs = dataset.upload_documents([{"display_name": "sample.txt", "blob": content.encode('utf-8')}])
docs = dataset.upload_documents([{"display_name": "sample.txt", "blob": content.encode("utf-8")}])
doc = docs[0]
# 3. Parse the document (required before manual chunk operations if you want it to be processed)
print("Parsing document...")
dataset.async_parse_documents([doc.id])
# Wait for parsing to complete with timeout
MAX_WAIT = 120 # seconds
elapsed = 0
while elapsed < MAX_WAIT:
doc_status = dataset.list_documents(id=doc.id)[0]
if doc_status.run == "1" and doc_status.progress >= 1.0:
print("Parsing completed.")
break
print("Parsing completed.")
break
print(f"Parsing progress: {doc_status.progress:.2f}")
time.sleep(2)
elapsed += 2
@@ -75,7 +75,7 @@ try:
# 6. Update a chunk
print("Updating chunk...")
chunk.update({"content": "RAGFlow features a streamlined and powerful RAG workflow."})
# 7. Delete the chunk
print("Deleting chunk...")
doc.delete_chunks([chunk.id])
@@ -83,7 +83,7 @@ try:
# Cleanup
print("Cleaning up dataset...")
rag.delete_datasets(ids=[dataset.id])
print("Chunk example done.")
sys.exit(0)

View File

@@ -32,7 +32,7 @@ try:
dataset_instance = ragflow_instance.create_dataset(name="dataset_instance")
# update the dataset instance
updated_message = {"name":"updated_dataset"}
updated_message = {"name": "updated_dataset"}
updated_dataset = dataset_instance.update(updated_message)
# get the dataset (list datasets)
@@ -49,5 +49,3 @@ try:
except Exception as e:
print(str(e))
sys.exit(-1)

View File

@@ -37,9 +37,9 @@ try:
# 2. Upload and parse a document to have content for retrieval
print("Uploading and parsing document...")
content = "RAGFlow is an open-source RAG engine based on deep document understanding. It features a streamlined RAG workflow for businesses of any size."
docs = dataset.upload_documents([{"display_name": "ragflow_info.txt", "blob": content.encode('utf-8')}])
docs = dataset.upload_documents([{"display_name": "ragflow_info.txt", "blob": content.encode("utf-8")}])
doc = docs[0]
# Wait for parsing to complete with timeout
print("Parsing document...")
dataset.async_parse_documents([doc.id])
@@ -48,7 +48,7 @@ try:
while elapsed < MAX_WAIT:
doc_status = dataset.list_documents(id=doc.id)[0]
if doc_status.run == "1" and doc_status.progress >= 1.0:
break
break
print(f"Parsing progress: {doc_status.progress:.2f}")
time.sleep(2)
elapsed += 2
@@ -61,18 +61,13 @@ try:
print("\n--- Performing Retrieval ---")
question = "What is RAGFlow?"
print(f"Question: {question}")
# Retrieve relevant chunks from one or more datasets
chunks = rag.retrieve(
dataset_ids=[dataset.id],
question=question,
top_k=5,
similarity_threshold=0.1
)
chunks = rag.retrieve(dataset_ids=[dataset.id], question=question, top_k=5, similarity_threshold=0.1)
print(f"Found {len(chunks)} relevant chunks:")
for i, chunk in enumerate(chunks):
print(f"\nChunk {i+1}:")
print(f"\nChunk {i + 1}:")
print(f"Content: {chunk.content[:200]}...")
print(f"Similarity Score: {chunk.similarity:.4f}")
print(f"Source Document: {chunk.document_name}")
@@ -83,10 +78,10 @@ try:
dataset_ids=[dataset.id],
question="workflow for businesses",
top_k=3,
keyword=True # Enable keyword search in addition to semantic search
keyword=True, # Enable keyword search in addition to semantic search
)
for i, chunk in enumerate(chunks):
print(f"Chunk {i+1}: {chunk.content[:100]}... (Score: {chunk.similarity:.4f})")
print(f"Chunk {i + 1}: {chunk.content[:100]}... (Score: {chunk.similarity:.4f})")
# Cleanup
print("\nCleaning up...")