Open Dormiveglia-elf opened 1 week ago
Hello, we have added an example folder. Let me know if that solves the issue :)
Hello, we have added an example folder. Let me know if that solves the issue :)
Not working, I guess some libraries may still require the environment variable OPENAI_API_KEY
to be set, even if the API key is already provided in the code.
Error below:
Traceback (most recent call last):
File "/root/fast-graphrag/examples/custom_llm.py", line 32, in
@liukidar
Can you try to use the last commit and see if it works? On my machine, the example in custom_llm.py works both by either setting OPEN_API_KEY as an env variable or by passing api_key to the constructor of OpenAILLMService and OpenAIEmbeddingService
If it doesn't, can you share the code you're using (you can just put a random api key since it is just necessary to start the code).
Can you try to use the last commit and see if it works? On my machine, the example in custom_llm.py works both by either setting OPEN_API_KEY as an env variable or by passing api_key to the constructor of OpenAILLMService and OpenAIEmbeddingService
If it doesn't, can you share the code you're using (you can just put a random api key since it is just necessary to start the code).
Still not working, below is my code and error is the same as my above comment.
"""Example usage of GraphRAG with custom LLM and Embedding services compatible with the OpenAI API."""
from typing import List
from dotenv import load_dotenv
from fast_graphrag import GraphRAG
from fast_graphrag._llm import OpenAIEmbeddingService, OpenAILLMService
load_dotenv()
DOMAIN = "Bitcoin and Cryptocurrency"
QUERIES: List[str] = [
"What is the double-spending problem, and how does Bitcoin address it?",
"How does Bitcoin ensure transaction security without a central authority?",
"Explain the role of proof-of-work in Bitcoin’s network.",
"How does Bitcoin's timestamp server contribute to transaction verification?",
"What are the steps involved in the Bitcoin network’s transaction process?",
"Describe the incentive mechanism for Bitcoin miners.",
"How does Bitcoin's blockchain use the Merkle Tree structure?",
"What is simplified payment verification in Bitcoin, and how does it work?",
"How does Bitcoin maintain privacy for its users?",
"What is the probability of a successful attack on the Bitcoin network, and how is it calculated?"
]
ENTITY_TYPES: List[str] = ["Bitcoin", "Cryptocurrency", "Blockchain", "Event", "Technology", "Person", "Organization", "Time", "Location", "Contract"]
working_dir = "./test_bitcoin"
grag = GraphRAG(
working_dir=working_dir,
domain=DOMAIN,
example_queries="\n".join(QUERIES),
entity_types=ENTITY_TYPES,
config=GraphRAG.Config(
llm_service=OpenAILLMService(model="deepseek-chat", base_url="https://api.deepseek.com/", api_key=""),
embedding_service=OpenAIEmbeddingService(
model="text-embedding-3-small",
base_url="",
api_key="",
embedding_dim=1536, # the output embedding dim, the embedding dim of vector storage must match this value
),
),
)
with open("./bitcoin.txt") as f:
grag.insert(f.read())
print(grag.query("Introduce Bitcoin briefly").response)
I'm sorry but I'm really unable to replicate your issue, the code you sent works perfectly fine on my machine. Can you check you're using the last commit of this repo?
I think it is necessary to add an example to illustrate how to use openai-compatible api like deepseek to use fast-graphrag, since the official openai api is too expensive.
For example, in Lightrag, they provide this https://github.com/HKUDS/LightRAG/blob/main/examples/lightrag_openai_compatible_demo.py