zrguo
commited on
Commit
·
df6ae9c
1
Parent(s):
366dd76
fix linting errors
Browse files- examples/graph_visual_with_html.py +1 -0
- lightrag/api/static/js/lightrag_api.js +2 -2
- lightrag/kg/json_kv_impl.py +0 -3
- lightrag/kg/milvus_impl.py +1 -0
- lightrag/kg/mongo_impl.py +1 -0
- lightrag/kg/nano_vector_db_impl.py +1 -0
- lightrag/kg/neo4j_impl.py +1 -0
- lightrag/kg/networkx_impl.py +1 -0
- lightrag/kg/postgres_impl.py +1 -0
- lightrag/kg/redis_impl.py +1 -0
- lightrag/kg/tidb_impl.py +3 -1
- lightrag/utils.py +11 -15
- requirements.txt +1 -1
examples/graph_visual_with_html.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import networkx as nx
|
2 |
import pipmaster as pm
|
|
|
3 |
if not pm.is_installed("pyvis"):
|
4 |
pm.install("pyvis")
|
5 |
|
|
|
1 |
import networkx as nx
|
2 |
import pipmaster as pm
|
3 |
+
|
4 |
if not pm.is_installed("pyvis"):
|
5 |
pm.install("pyvis")
|
6 |
|
lightrag/api/static/js/lightrag_api.js
CHANGED
@@ -256,7 +256,7 @@ const handlers = {
|
|
256 |
const queryInput = document.getElementById('queryInput');
|
257 |
const queryMode = document.getElementById('queryMode');
|
258 |
const queryResult = document.getElementById('queryResult');
|
259 |
-
|
260 |
let apiKey = localStorage.getItem('apiKey') || '';
|
261 |
|
262 |
queryBtn.addEventListener('click', async () => {
|
@@ -372,4 +372,4 @@ window.removeFile = (fileName) => {
|
|
372 |
</button>
|
373 |
</div>
|
374 |
`).join('');
|
375 |
-
};
|
|
|
256 |
const queryInput = document.getElementById('queryInput');
|
257 |
const queryMode = document.getElementById('queryMode');
|
258 |
const queryResult = document.getElementById('queryResult');
|
259 |
+
|
260 |
let apiKey = localStorage.getItem('apiKey') || '';
|
261 |
|
262 |
queryBtn.addEventListener('click', async () => {
|
|
|
372 |
</button>
|
373 |
</div>
|
374 |
`).join('');
|
375 |
+
};
|
lightrag/kg/json_kv_impl.py
CHANGED
@@ -48,7 +48,6 @@ Usage:
|
|
48 |
|
49 |
"""
|
50 |
|
51 |
-
|
52 |
import asyncio
|
53 |
import os
|
54 |
from dataclasses import dataclass
|
@@ -133,5 +132,3 @@ class JsonKVStorage(BaseKVStorage):
|
|
133 |
del self._data[id]
|
134 |
await self.index_done_callback()
|
135 |
logger.info(f"Successfully deleted {len(ids)} items from {self.namespace}")
|
136 |
-
|
137 |
-
|
|
|
48 |
|
49 |
"""
|
50 |
|
|
|
51 |
import asyncio
|
52 |
import os
|
53 |
from dataclasses import dataclass
|
|
|
132 |
del self._data[id]
|
133 |
await self.index_done_callback()
|
134 |
logger.info(f"Successfully deleted {len(ids)} items from {self.namespace}")
|
|
|
|
lightrag/kg/milvus_impl.py
CHANGED
@@ -7,6 +7,7 @@ from lightrag.utils import logger
|
|
7 |
from ..base import BaseVectorStorage
|
8 |
|
9 |
import pipmaster as pm
|
|
|
10 |
if not pm.is_installed("pymilvus"):
|
11 |
pm.install("pymilvus")
|
12 |
from pymilvus import MilvusClient
|
|
|
7 |
from ..base import BaseVectorStorage
|
8 |
|
9 |
import pipmaster as pm
|
10 |
+
|
11 |
if not pm.is_installed("pymilvus"):
|
12 |
pm.install("pymilvus")
|
13 |
from pymilvus import MilvusClient
|
lightrag/kg/mongo_impl.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
from tqdm.asyncio import tqdm as tqdm_async
|
3 |
from dataclasses import dataclass
|
4 |
import pipmaster as pm
|
|
|
5 |
if not pm.is_installed("pymongo"):
|
6 |
pm.install("pymongo")
|
7 |
|
|
|
2 |
from tqdm.asyncio import tqdm as tqdm_async
|
3 |
from dataclasses import dataclass
|
4 |
import pipmaster as pm
|
5 |
+
|
6 |
if not pm.is_installed("pymongo"):
|
7 |
pm.install("pymongo")
|
8 |
|
lightrag/kg/nano_vector_db_impl.py
CHANGED
@@ -47,6 +47,7 @@ Usage:
|
|
47 |
from lightrag.storage.networkx_storage import NetworkXStorage
|
48 |
|
49 |
"""
|
|
|
50 |
import asyncio
|
51 |
import os
|
52 |
from tqdm.asyncio import tqdm as tqdm_async
|
|
|
47 |
from lightrag.storage.networkx_storage import NetworkXStorage
|
48 |
|
49 |
"""
|
50 |
+
|
51 |
import asyncio
|
52 |
import os
|
53 |
from tqdm.asyncio import tqdm as tqdm_async
|
lightrag/kg/neo4j_impl.py
CHANGED
@@ -4,6 +4,7 @@ import os
|
|
4 |
from dataclasses import dataclass
|
5 |
from typing import Any, Union, Tuple, List, Dict
|
6 |
import pipmaster as pm
|
|
|
7 |
if not pm.is_installed("neo4j"):
|
8 |
pm.install("neo4j")
|
9 |
|
|
|
4 |
from dataclasses import dataclass
|
5 |
from typing import Any, Union, Tuple, List, Dict
|
6 |
import pipmaster as pm
|
7 |
+
|
8 |
if not pm.is_installed("neo4j"):
|
9 |
pm.install("neo4j")
|
10 |
|
lightrag/kg/networkx_impl.py
CHANGED
@@ -47,6 +47,7 @@ Usage:
|
|
47 |
from lightrag.storage.networkx_storage import NetworkXStorage
|
48 |
|
49 |
"""
|
|
|
50 |
import html
|
51 |
import os
|
52 |
from dataclasses import dataclass
|
|
|
47 |
from lightrag.storage.networkx_storage import NetworkXStorage
|
48 |
|
49 |
"""
|
50 |
+
|
51 |
import html
|
52 |
import os
|
53 |
from dataclasses import dataclass
|
lightrag/kg/postgres_impl.py
CHANGED
@@ -8,6 +8,7 @@ from typing import Union, List, Dict, Set, Any, Tuple
|
|
8 |
import numpy as np
|
9 |
|
10 |
import pipmaster as pm
|
|
|
11 |
if not pm.is_installed("asyncpg"):
|
12 |
pm.install("asyncpg")
|
13 |
|
|
|
8 |
import numpy as np
|
9 |
|
10 |
import pipmaster as pm
|
11 |
+
|
12 |
if not pm.is_installed("asyncpg"):
|
13 |
pm.install("asyncpg")
|
14 |
|
lightrag/kg/redis_impl.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
from tqdm.asyncio import tqdm as tqdm_async
|
3 |
from dataclasses import dataclass
|
4 |
import pipmaster as pm
|
|
|
5 |
if not pm.is_installed("redis"):
|
6 |
pm.install("redis")
|
7 |
|
|
|
2 |
from tqdm.asyncio import tqdm as tqdm_async
|
3 |
from dataclasses import dataclass
|
4 |
import pipmaster as pm
|
5 |
+
|
6 |
if not pm.is_installed("redis"):
|
7 |
pm.install("redis")
|
8 |
|
lightrag/kg/tidb_impl.py
CHANGED
@@ -5,17 +5,19 @@ from typing import Union
|
|
5 |
|
6 |
import numpy as np
|
7 |
import pipmaster as pm
|
|
|
8 |
if not pm.is_installed("pymysql"):
|
9 |
pm.install("pymysql")
|
10 |
if not pm.is_installed("sqlalchemy"):
|
11 |
pm.install("sqlalchemy")
|
12 |
-
|
13 |
from sqlalchemy import create_engine, text
|
14 |
from tqdm import tqdm
|
15 |
|
16 |
from lightrag.base import BaseVectorStorage, BaseKVStorage, BaseGraphStorage
|
17 |
from lightrag.utils import logger
|
18 |
|
|
|
19 |
class TiDB(object):
|
20 |
def __init__(self, config, **kwargs):
|
21 |
self.host = config.get("host", None)
|
|
|
5 |
|
6 |
import numpy as np
|
7 |
import pipmaster as pm
|
8 |
+
|
9 |
if not pm.is_installed("pymysql"):
|
10 |
pm.install("pymysql")
|
11 |
if not pm.is_installed("sqlalchemy"):
|
12 |
pm.install("sqlalchemy")
|
13 |
+
|
14 |
from sqlalchemy import create_engine, text
|
15 |
from tqdm import tqdm
|
16 |
|
17 |
from lightrag.base import BaseVectorStorage, BaseKVStorage, BaseGraphStorage
|
18 |
from lightrag.utils import logger
|
19 |
|
20 |
+
|
21 |
class TiDB(object):
|
22 |
def __init__(self, config, **kwargs):
|
23 |
self.host = config.get("host", None)
|
lightrag/utils.py
CHANGED
@@ -16,9 +16,7 @@ import numpy as np
|
|
16 |
import tiktoken
|
17 |
|
18 |
from lightrag.prompt import PROMPTS
|
19 |
-
|
20 |
-
import csv
|
21 |
-
import io
|
22 |
|
23 |
class UnlimitedSemaphore:
|
24 |
"""A context manager that allows unlimited access."""
|
@@ -237,16 +235,14 @@ def truncate_list_by_token_size(list_data: list, key: callable, max_token_size:
|
|
237 |
return list_data
|
238 |
|
239 |
|
240 |
-
|
241 |
-
|
242 |
def list_of_list_to_csv(data: List[List[str]]) -> str:
|
243 |
output = io.StringIO()
|
244 |
writer = csv.writer(
|
245 |
output,
|
246 |
-
quoting=csv.QUOTE_ALL,
|
247 |
-
escapechar=
|
248 |
-
quotechar='"',
|
249 |
-
lineterminator=
|
250 |
)
|
251 |
writer.writerows(data)
|
252 |
return output.getvalue()
|
@@ -254,16 +250,16 @@ def list_of_list_to_csv(data: List[List[str]]) -> str:
|
|
254 |
|
255 |
def csv_string_to_list(csv_string: str) -> List[List[str]]:
|
256 |
# Clean the string by removing NUL characters
|
257 |
-
cleaned_string = csv_string.replace(
|
258 |
-
|
259 |
output = io.StringIO(cleaned_string)
|
260 |
reader = csv.reader(
|
261 |
output,
|
262 |
-
quoting=csv.QUOTE_ALL,
|
263 |
-
escapechar=
|
264 |
-
quotechar='"',
|
265 |
)
|
266 |
-
|
267 |
try:
|
268 |
return [row for row in reader]
|
269 |
except csv.Error as e:
|
|
|
16 |
import tiktoken
|
17 |
|
18 |
from lightrag.prompt import PROMPTS
|
19 |
+
|
|
|
|
|
20 |
|
21 |
class UnlimitedSemaphore:
|
22 |
"""A context manager that allows unlimited access."""
|
|
|
235 |
return list_data
|
236 |
|
237 |
|
|
|
|
|
238 |
def list_of_list_to_csv(data: List[List[str]]) -> str:
|
239 |
output = io.StringIO()
|
240 |
writer = csv.writer(
|
241 |
output,
|
242 |
+
quoting=csv.QUOTE_ALL, # Quote all fields
|
243 |
+
escapechar="\\", # Use backslash as escape character
|
244 |
+
quotechar='"', # Use double quotes
|
245 |
+
lineterminator="\n", # Explicit line terminator
|
246 |
)
|
247 |
writer.writerows(data)
|
248 |
return output.getvalue()
|
|
|
250 |
|
251 |
def csv_string_to_list(csv_string: str) -> List[List[str]]:
|
252 |
# Clean the string by removing NUL characters
|
253 |
+
cleaned_string = csv_string.replace("\0", "")
|
254 |
+
|
255 |
output = io.StringIO(cleaned_string)
|
256 |
reader = csv.reader(
|
257 |
output,
|
258 |
+
quoting=csv.QUOTE_ALL, # Match the writer configuration
|
259 |
+
escapechar="\\", # Use backslash as escape character
|
260 |
+
quotechar='"', # Use double quotes
|
261 |
)
|
262 |
+
|
263 |
try:
|
264 |
return [row for row in reader]
|
265 |
except csv.Error as e:
|
requirements.txt
CHANGED
@@ -2,10 +2,10 @@ accelerate
|
|
2 |
aiofiles
|
3 |
aiohttp
|
4 |
configparser
|
|
|
5 |
|
6 |
# database packages
|
7 |
networkx
|
8 |
-
graspologic
|
9 |
|
10 |
# Basic modules
|
11 |
numpy
|
|
|
2 |
aiofiles
|
3 |
aiohttp
|
4 |
configparser
|
5 |
+
graspologic
|
6 |
|
7 |
# database packages
|
8 |
networkx
|
|
|
9 |
|
10 |
# Basic modules
|
11 |
numpy
|