Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/amumu02_iceidasystem.json
T

1 line
5.7 KiB
JSON

{"repo": "amumu02/iceidasystem", "files": {"examples/lightrag_siliconcloud_track_token_demo.py": {"8fe30869ca5182f1841066dee90e7eaff4805529": {"t": 1785674135.905256, "n": 2687, "h": "7de5487749e2ef9a", "c": "import os\nimport asyncio\nfrom lightrag import LightRAG, QueryParam\nfrom lightrag.llm.openai import openai_complete_if_cache\nfrom lightrag.llm.siliconcloud import siliconcloud_embedding\nfrom lightrag.utils import EmbeddingFunc\nfrom lightrag.utils import TokenTracker\nimport numpy as np\nfrom lightrag.kg.shared_storage import initialize_pipeline_status\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\ntoken_tracker = TokenTracker()\nWORKING_DIR = \"./dickens\"\n\nif not os.path.exists(WORKING_DIR):\n os.mkdir(WORKING_DIR)\n\n\nasync def llm_model_func(\n prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs\n) -> str:\n return await openai_complete_if_cache(\n \"Qwen/Qwen2.5-7B-Instruct\",\n prompt,\n system_prompt=system_prompt,\n history_messages=history_messages,\n api_key=os.getenv(\"SILICONFLOW_API_KEY\"),\n base_url=\"https://api.siliconflow.cn/v1/\",\n token_tracker=token_tracker,\n **kwargs,\n )\n\n\nasync def embedding_func(texts: list[str]) -> np.ndarray:\n return await siliconcloud_embedding(\n texts,\n model=\"BAAI/bge-m3\",\n api_key=os.getenv(\"SILICONFLOW_API_KEY\"),\n max_token_size=512,\n )\n\n\n# function test\nasync def test_funcs():\n # Context Manager Method\n with token_tracker:\n result = await llm_model_func(\"How are you?\")\n print(\"llm_model_func: \", result)\n\n\nasyncio.run(test_funcs())\n\n\nasync def initialize_rag():\n rag = LightRAG(\n working_dir=WORKING_DIR,\n llm_model_func=llm_model_func,\n embedding_func=EmbeddingFunc(\n embedding_dim=1024, max_token_size=512, func=embedding_func\n ),\n )\n\n await rag.initialize_storages()\n await initialize_pipeline_status()\n\n return rag\n\n\ndef main():\n # Initialize RAG instance\n rag = asyncio.run(initialize_rag())\n\n # Reset tracker before processing queries\n token_tracker.reset()\n\n with open(\"./book.txt\", \"r\", encoding=\"utf-8\") as f:\n rag.insert(f.read())\n\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"naive\")\n )\n )\n\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"local\")\n )\n )\n\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"global\")\n )\n )\n\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"hybrid\")\n )\n )\n\n # Display final token usage after main query\n print(\"Token usage:\", token_tracker.get_usage())\n\n\nif __name__ == \"__main__\":\n main()\n"}}, "examples/lightrag_siliconcloud_demo.py": {"8fe30869ca5182f1841066dee90e7eaff4805529": {"t": 1785674136.3314412, "n": 2521, "h": "f26a8a50c5420d5c", "c": "import os\nimport asyncio\nfrom lightrag import LightRAG, QueryParam\nfrom lightrag.llm.openai import openai_complete_if_cache\nfrom lightrag.llm.siliconcloud import siliconcloud_embedding\nfrom lightrag.utils import EmbeddingFunc\nimport numpy as np\nfrom lightrag.kg.shared_storage import initialize_pipeline_status\n\nWORKING_DIR = \"./dickens\"\n\nif not os.path.exists(WORKING_DIR):\n os.mkdir(WORKING_DIR)\n\n\nasync def llm_model_func(\n prompt, system_prompt=None, history_messages=[], keyword_extraction=False, **kwargs\n) -> str:\n return await openai_complete_if_cache(\n \"Qwen/Qwen2.5-7B-Instruct\",\n prompt,\n system_prompt=system_prompt,\n history_messages=history_messages,\n api_key=os.getenv(\"SILICONFLOW_API_KEY\"),\n base_url=\"https://api.siliconflow.cn/v1/\",\n **kwargs,\n )\n\n\nasync def embedding_func(texts: list[str]) -> np.ndarray:\n return await siliconcloud_embedding(\n texts,\n model=\"netease-youdao/bce-embedding-base_v1\",\n api_key=os.getenv(\"SILICONFLOW_API_KEY\"),\n max_token_size=512,\n )\n\n\n# function test\nasync def test_funcs():\n result = await llm_model_func(\"How are you?\")\n print(\"llm_model_func: \", result)\n\n result = await embedding_func([\"How are you?\"])\n print(\"embedding_func: \", result)\n\n\nasyncio.run(test_funcs())\n\n\nasync def initialize_rag():\n rag = LightRAG(\n working_dir=WORKING_DIR,\n llm_model_func=llm_model_func,\n embedding_func=EmbeddingFunc(\n embedding_dim=768, max_token_size=512, func=embedding_func\n ),\n )\n\n await rag.initialize_storages()\n await initialize_pipeline_status()\n\n return rag\n\n\ndef main():\n # Initialize RAG instance\n rag = asyncio.run(initialize_rag())\n\n with open(\"./book.txt\", \"r\", encoding=\"utf-8\") as f:\n rag.insert(f.read())\n\n # Perform naive search\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"naive\")\n )\n )\n\n # Perform local search\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"local\")\n )\n )\n\n # Perform global search\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"global\")\n )\n )\n\n # Perform hybrid search\n print(\n rag.query(\n \"What are the top themes in this story?\", param=QueryParam(mode=\"hybrid\")\n )\n )\n\n\nif __name__ == \"__main__\":\n main()\n"}}}}