Skip to content

Commit b7a2d33

Browse files
committed
Update __version__
1 parent 9cac3b0 commit b7a2d33

5 files changed

Lines changed: 29 additions & 39 deletions

File tree

examples/lightrag_zhipu_demo.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import asyncio
21
import os
3-
import inspect
42
import logging
53

6-
from dotenv import load_dotenv
74

85
from lightrag import LightRAG, QueryParam
96
from lightrag.llm import zhipu_complete, zhipu_embedding
@@ -21,7 +18,6 @@
2118
raise Exception("Please set ZHIPU_API_KEY in your environment")
2219

2320

24-
2521
rag = LightRAG(
2622
working_dir=WORKING_DIR,
2723
llm_model_func=zhipu_complete,
@@ -31,9 +27,7 @@
3127
embedding_func=EmbeddingFunc(
3228
embedding_dim=2048, # Zhipu embedding-3 dimension
3329
max_token_size=8192,
34-
func=lambda texts: zhipu_embedding(
35-
texts
36-
),
30+
func=lambda texts: zhipu_embedding(texts),
3731
),
3832
)
3933

@@ -58,4 +52,4 @@
5852
# Perform hybrid search
5953
print(
6054
rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid"))
61-
)
55+
)

lightrag/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam
22

3-
__version__ = "1.0.5"
3+
__version__ = "1.0.6"
44
__author__ = "Zirui Guo"
55
__url__ = "https://github.com/HKUDS/LightRAG"

lightrag/kg/milvus_impl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ async def wrapped_task(batch):
6363
return result
6464

6565
embedding_tasks = [wrapped_task(batch) for batch in batches]
66-
pbar = tqdm_async(total=len(embedding_tasks), desc="Generating embeddings", unit="batch")
66+
pbar = tqdm_async(
67+
total=len(embedding_tasks), desc="Generating embeddings", unit="batch"
68+
)
6769
embeddings_list = await asyncio.gather(*embedding_tasks)
6870

6971
embeddings = np.concatenate(embeddings_list)

lightrag/llm.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,11 @@ async def ollama_model_complete(
604604
)
605605
async def zhipu_complete_if_cache(
606606
prompt: Union[str, List[Dict[str, str]]],
607-
model: str = "glm-4-flashx", # The most cost/performance balance model in glm-4 series
607+
model: str = "glm-4-flashx", # The most cost/performance balance model in glm-4 series
608608
api_key: Optional[str] = None,
609609
system_prompt: Optional[str] = None,
610610
history_messages: List[Dict[str, str]] = [],
611-
**kwargs
611+
**kwargs,
612612
) -> str:
613613
# dynamically load ZhipuAI
614614
try:
@@ -640,13 +640,11 @@ async def zhipu_complete_if_cache(
640640
logger.debug(f"System prompt: {system_prompt}")
641641

642642
# Remove unsupported kwargs
643-
kwargs = {k: v for k, v in kwargs.items() if k not in ['hashing_kv', 'keyword_extraction']}
643+
kwargs = {
644+
k: v for k, v in kwargs.items() if k not in ["hashing_kv", "keyword_extraction"]
645+
}
644646

645-
response = client.chat.completions.create(
646-
model=model,
647-
messages=messages,
648-
**kwargs
649-
)
647+
response = client.chat.completions.create(model=model, messages=messages, **kwargs)
650648

651649
return response.choices[0].message.content
652650

@@ -663,13 +661,13 @@ async def zhipu_complete(
663661
Please analyze the content and extract two types of keywords:
664662
1. High-level keywords: Important concepts and main themes
665663
2. Low-level keywords: Specific details and supporting elements
666-
664+
667665
Return your response in this exact JSON format:
668666
{
669667
"high_level_keywords": ["keyword1", "keyword2"],
670668
"low_level_keywords": ["keyword1", "keyword2", "keyword3"]
671669
}
672-
670+
673671
Only return the JSON, no other text."""
674672

675673
# Combine with existing system prompt if any
@@ -683,15 +681,15 @@ async def zhipu_complete(
683681
prompt=prompt,
684682
system_prompt=system_prompt,
685683
history_messages=history_messages,
686-
**kwargs
684+
**kwargs,
687685
)
688-
686+
689687
# Try to parse as JSON
690688
try:
691689
data = json.loads(response)
692690
return GPTKeywordExtractionFormat(
693691
high_level_keywords=data.get("high_level_keywords", []),
694-
low_level_keywords=data.get("low_level_keywords", [])
692+
low_level_keywords=data.get("low_level_keywords", []),
695693
)
696694
except json.JSONDecodeError:
697695
# If direct JSON parsing fails, try to extract JSON from text
@@ -701,13 +699,15 @@ async def zhipu_complete(
701699
data = json.loads(match.group())
702700
return GPTKeywordExtractionFormat(
703701
high_level_keywords=data.get("high_level_keywords", []),
704-
low_level_keywords=data.get("low_level_keywords", [])
702+
low_level_keywords=data.get("low_level_keywords", []),
705703
)
706704
except json.JSONDecodeError:
707705
pass
708-
706+
709707
# If all parsing fails, log warning and return empty format
710-
logger.warning(f"Failed to parse keyword extraction response: {response}")
708+
logger.warning(
709+
f"Failed to parse keyword extraction response: {response}"
710+
)
711711
return GPTKeywordExtractionFormat(
712712
high_level_keywords=[], low_level_keywords=[]
713713
)
@@ -722,7 +722,7 @@ async def zhipu_complete(
722722
prompt=prompt,
723723
system_prompt=system_prompt,
724724
history_messages=history_messages,
725-
**kwargs
725+
**kwargs,
726726
)
727727

728728

@@ -733,13 +733,9 @@ async def zhipu_complete(
733733
retry=retry_if_exception_type((RateLimitError, APIConnectionError, Timeout)),
734734
)
735735
async def zhipu_embedding(
736-
texts: list[str],
737-
model: str = "embedding-3",
738-
api_key: str = None,
739-
**kwargs
736+
texts: list[str], model: str = "embedding-3", api_key: str = None, **kwargs
740737
) -> np.ndarray:
741-
742-
# dynamically load ZhipuAI
738+
# dynamically load ZhipuAI
743739
try:
744740
from zhipuai import ZhipuAI
745741
except ImportError:
@@ -758,11 +754,7 @@ async def zhipu_embedding(
758754
embeddings = []
759755
for text in texts:
760756
try:
761-
response = client.embeddings.create(
762-
model=model,
763-
input=[text],
764-
**kwargs
765-
)
757+
response = client.embeddings.create(model=model, input=[text], **kwargs)
766758
embeddings.append(response.data[0].embedding)
767759
except Exception as e:
768760
raise Exception(f"Error calling ChatGLM Embedding API: {str(e)}")

lightrag/storage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ async def wrapped_task(batch):
103103
return result
104104

105105
embedding_tasks = [wrapped_task(batch) for batch in batches]
106-
pbar = tqdm_async(total=len(embedding_tasks), desc="Generating embeddings", unit="batch")
106+
pbar = tqdm_async(
107+
total=len(embedding_tasks), desc="Generating embeddings", unit="batch"
108+
)
107109
embeddings_list = await asyncio.gather(*embedding_tasks)
108110

109111
embeddings = np.concatenate(embeddings_list)

0 commit comments

Comments
 (0)