Commit
·
0e9f364
1
Parent(s):
78e9f46
Refactor code formatting in lightrag_api_openai_compatible_demo.py
Browse files- lightrag/lightrag.py +1 -3
- lightrag/llm.py +3 -1
- setup.py +24 -7
lightrag/lightrag.py
CHANGED
@@ -85,9 +85,7 @@ class LightRAG:
|
|
85 |
|
86 |
# LLM
|
87 |
llm_model_func: callable = gpt_4o_mini_complete # hf_model_complete#
|
88 |
-
llm_model_name: str =
|
89 |
-
"meta-llama/Llama-3.2-1B-Instruct" #'meta-llama/Llama-3.2-1B'#'google/gemma-2-2b-it'
|
90 |
-
)
|
91 |
llm_model_max_token_size: int = 32768
|
92 |
llm_model_max_async: int = 16
|
93 |
|
|
|
85 |
|
86 |
# LLM
|
87 |
llm_model_func: callable = gpt_4o_mini_complete # hf_model_complete#
|
88 |
+
llm_model_name: str = "meta-llama/Llama-3.2-1B-Instruct" #'meta-llama/Llama-3.2-1B'#'google/gemma-2-2b-it'
|
|
|
|
|
89 |
llm_model_max_token_size: int = 32768
|
90 |
llm_model_max_async: int = 16
|
91 |
|
lightrag/llm.py
CHANGED
@@ -286,7 +286,9 @@ async def hf_model_if_cache(
|
|
286 |
output = hf_model.generate(
|
287 |
**input_ids, max_new_tokens=512, num_return_sequences=1, early_stopping=True
|
288 |
)
|
289 |
-
response_text = hf_tokenizer.decode(
|
|
|
|
|
290 |
if hashing_kv is not None:
|
291 |
await hashing_kv.upsert({args_hash: {"return": response_text, "model": model}})
|
292 |
return response_text
|
|
|
286 |
output = hf_model.generate(
|
287 |
**input_ids, max_new_tokens=512, num_return_sequences=1, early_stopping=True
|
288 |
)
|
289 |
+
response_text = hf_tokenizer.decode(
|
290 |
+
output[0][len(inputs["input_ids"][0]) :], skip_special_tokens=True
|
291 |
+
)
|
292 |
if hashing_kv is not None:
|
293 |
await hashing_kv.upsert({args_hash: {"return": response_text, "model": model}})
|
294 |
return response_text
|
setup.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import setuptools
|
2 |
from pathlib import Path
|
3 |
|
|
|
4 |
# Reading the long description from README.md
|
5 |
def read_long_description():
|
6 |
try:
|
@@ -8,6 +9,7 @@ def read_long_description():
|
|
8 |
except FileNotFoundError:
|
9 |
return "A description of LightRAG is currently unavailable."
|
10 |
|
|
|
11 |
# Retrieving metadata from __init__.py
|
12 |
def retrieve_metadata():
|
13 |
vars2find = ["__author__", "__version__", "__url__"]
|
@@ -17,18 +19,26 @@ def retrieve_metadata():
|
|
17 |
for line in f.readlines():
|
18 |
for v in vars2find:
|
19 |
if line.startswith(v):
|
20 |
-
line =
|
|
|
|
|
|
|
|
|
|
|
21 |
vars2readme[v] = line.split("=")[1]
|
22 |
except FileNotFoundError:
|
23 |
raise FileNotFoundError("Metadata file './lightrag/__init__.py' not found.")
|
24 |
-
|
25 |
# Checking if all required variables are found
|
26 |
missing_vars = [v for v in vars2find if v not in vars2readme]
|
27 |
if missing_vars:
|
28 |
-
raise ValueError(
|
29 |
-
|
|
|
|
|
30 |
return vars2readme
|
31 |
|
|
|
32 |
# Reading dependencies from requirements.txt
|
33 |
def read_requirements():
|
34 |
deps = []
|
@@ -36,9 +46,12 @@ def read_requirements():
|
|
36 |
with open("./requirements.txt") as f:
|
37 |
deps = [line.strip() for line in f if line.strip()]
|
38 |
except FileNotFoundError:
|
39 |
-
print(
|
|
|
|
|
40 |
return deps
|
41 |
|
|
|
42 |
metadata = retrieve_metadata()
|
43 |
long_description = read_long_description()
|
44 |
requirements = read_requirements()
|
@@ -51,7 +64,9 @@ setuptools.setup(
|
|
51 |
description="LightRAG: Simple and Fast Retrieval-Augmented Generation",
|
52 |
long_description=long_description,
|
53 |
long_description_content_type="text/markdown",
|
54 |
-
packages=setuptools.find_packages(
|
|
|
|
|
55 |
classifiers=[
|
56 |
"Development Status :: 4 - Beta",
|
57 |
"Programming Language :: Python :: 3",
|
@@ -66,6 +81,8 @@ setuptools.setup(
|
|
66 |
project_urls={ # Additional project metadata
|
67 |
"Documentation": metadata.get("__url__", ""),
|
68 |
"Source": metadata.get("__url__", ""),
|
69 |
-
"Tracker": f"{metadata.get('__url__', '')}/issues"
|
|
|
|
|
70 |
},
|
71 |
)
|
|
|
1 |
import setuptools
|
2 |
from pathlib import Path
|
3 |
|
4 |
+
|
5 |
# Reading the long description from README.md
|
6 |
def read_long_description():
|
7 |
try:
|
|
|
9 |
except FileNotFoundError:
|
10 |
return "A description of LightRAG is currently unavailable."
|
11 |
|
12 |
+
|
13 |
# Retrieving metadata from __init__.py
|
14 |
def retrieve_metadata():
|
15 |
vars2find = ["__author__", "__version__", "__url__"]
|
|
|
19 |
for line in f.readlines():
|
20 |
for v in vars2find:
|
21 |
if line.startswith(v):
|
22 |
+
line = (
|
23 |
+
line.replace(" ", "")
|
24 |
+
.replace('"', "")
|
25 |
+
.replace("'", "")
|
26 |
+
.strip()
|
27 |
+
)
|
28 |
vars2readme[v] = line.split("=")[1]
|
29 |
except FileNotFoundError:
|
30 |
raise FileNotFoundError("Metadata file './lightrag/__init__.py' not found.")
|
31 |
+
|
32 |
# Checking if all required variables are found
|
33 |
missing_vars = [v for v in vars2find if v not in vars2readme]
|
34 |
if missing_vars:
|
35 |
+
raise ValueError(
|
36 |
+
f"Missing required metadata variables in __init__.py: {missing_vars}"
|
37 |
+
)
|
38 |
+
|
39 |
return vars2readme
|
40 |
|
41 |
+
|
42 |
# Reading dependencies from requirements.txt
|
43 |
def read_requirements():
|
44 |
deps = []
|
|
|
46 |
with open("./requirements.txt") as f:
|
47 |
deps = [line.strip() for line in f if line.strip()]
|
48 |
except FileNotFoundError:
|
49 |
+
print(
|
50 |
+
"Warning: 'requirements.txt' not found. No dependencies will be installed."
|
51 |
+
)
|
52 |
return deps
|
53 |
|
54 |
+
|
55 |
metadata = retrieve_metadata()
|
56 |
long_description = read_long_description()
|
57 |
requirements = read_requirements()
|
|
|
64 |
description="LightRAG: Simple and Fast Retrieval-Augmented Generation",
|
65 |
long_description=long_description,
|
66 |
long_description_content_type="text/markdown",
|
67 |
+
packages=setuptools.find_packages(
|
68 |
+
exclude=("tests*", "docs*")
|
69 |
+
), # Automatically find packages
|
70 |
classifiers=[
|
71 |
"Development Status :: 4 - Beta",
|
72 |
"Programming Language :: Python :: 3",
|
|
|
81 |
project_urls={ # Additional project metadata
|
82 |
"Documentation": metadata.get("__url__", ""),
|
83 |
"Source": metadata.get("__url__", ""),
|
84 |
+
"Tracker": f"{metadata.get('__url__', '')}/issues"
|
85 |
+
if metadata.get("__url__")
|
86 |
+
else "",
|
87 |
},
|
88 |
)
|