|
|
|
@ -6,12 +6,10 @@ from lightrag import LightRAG
|
|
|
|
|
from lightrag.llm.openai import openai_complete_if_cache, openai_embed
|
|
|
|
|
from lightrag.utils import EmbeddingFunc
|
|
|
|
|
import os
|
|
|
|
|
from Config.Config import *
|
|
|
|
|
|
|
|
|
|
async def load_existing_lightrag():
|
|
|
|
|
# 设置 API 配置
|
|
|
|
|
api_key = "sk-44ae895eeb614aa1a9c6460579e322f1"
|
|
|
|
|
base_url = "https://api.deepseek.com" # Optional
|
|
|
|
|
|
|
|
|
|
async def load_existing_lightrag():
|
|
|
|
|
# 首先,创建或加载已存在的 LightRAG 实例
|
|
|
|
|
lightrag_working_dir = "./rag_storage"
|
|
|
|
|
|
|
|
|
@ -29,8 +27,8 @@ async def load_existing_lightrag():
|
|
|
|
|
prompt,
|
|
|
|
|
system_prompt=system_prompt,
|
|
|
|
|
history_messages=history_messages,
|
|
|
|
|
api_key=api_key,
|
|
|
|
|
base_url=base_url,
|
|
|
|
|
api_key=LLM_API_KEY,
|
|
|
|
|
base_url=LLM_BASE_URL,
|
|
|
|
|
**kwargs,
|
|
|
|
|
),
|
|
|
|
|
embedding_func=EmbeddingFunc(
|
|
|
|
@ -38,9 +36,9 @@ async def load_existing_lightrag():
|
|
|
|
|
max_token_size=8192,
|
|
|
|
|
func=lambda texts: openai_embed(
|
|
|
|
|
texts,
|
|
|
|
|
model="BAAI/bge-m3",
|
|
|
|
|
api_key="sk-pbqibyjwhrgmnlsmdygplahextfaclgnedetybccknxojlyl",
|
|
|
|
|
base_url="https://api.siliconflow.cn/v1",
|
|
|
|
|
model=EMBED_MODEL_NAME,
|
|
|
|
|
api_key=EMBED_API_KEY,
|
|
|
|
|
base_url=EMBED_BASE_URL,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
@ -51,11 +49,13 @@ async def load_existing_lightrag():
|
|
|
|
|
|
|
|
|
|
# 定义视觉模型函数用于图像处理
|
|
|
|
|
def vision_model_func(
|
|
|
|
|
prompt, system_prompt=None, history_messages=[], image_data=None, **kwargs
|
|
|
|
|
prompt, system_prompt=None, history_messages=None, image_data=None, **kwargs
|
|
|
|
|
):
|
|
|
|
|
if history_messages is None:
|
|
|
|
|
history_messages = []
|
|
|
|
|
if image_data:
|
|
|
|
|
return openai_complete_if_cache(
|
|
|
|
|
"GLM-4.1V-9B-Thinking",
|
|
|
|
|
VISION_MODEL_NAME,
|
|
|
|
|
"",
|
|
|
|
|
system_prompt=None,
|
|
|
|
|
history_messages=[],
|
|
|
|
@ -78,8 +78,8 @@ async def load_existing_lightrag():
|
|
|
|
|
if image_data
|
|
|
|
|
else {"role": "user", "content": prompt},
|
|
|
|
|
],
|
|
|
|
|
api_key="sk-pbqibyjwhrgmnlsmdygplahextfaclgnedetybccknxojlyl",
|
|
|
|
|
base_url="https://api.siliconflow.cn/v1/chat/completions",
|
|
|
|
|
api_key=VISION_API_KEY,
|
|
|
|
|
base_url=VISION_BASE_URL,
|
|
|
|
|
**kwargs,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
@ -106,5 +106,6 @@ async def load_existing_lightrag():
|
|
|
|
|
# output_dir="./output"
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
asyncio.run(load_existing_lightrag())
|