-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue about custom LLM. The example file dosn't work! #15
Comments
Hello there! |
Hello! Thanks for your reply! But is remind me And load_dotenv() return TRUE |
Set .env file with below format. see https://pypi.org/project/python-dotenv/
|
It still return error.
And
return
|
Hello, I am unable to replicate your issue, would you mind sharing the full code you're using? you can use generic values for api_keys as real ones are not necessary to initialise the model. |
I think i am hitting the same problem, with Ollama: from typing import List
from dotenv import load_dotenv
from fast_graphrag import GraphRAG
from fast_graphrag._llm import OpenAIEmbeddingService, OpenAILLMService
load_dotenv()
DOMAIN = "Analyze this story and identify the characters. Focus on how they interact with each other, the locations they explore, and their relationships."
EXAMPLE_QUERIES = [
"What is the significance of shoes in Caledonian Road?",
"How does the setting of London contribute to the story's themes?",
"Describe the chain of events that leads to Bykov's demise.",
"What does Capmbell's Mother represent in this story?",
]
ENTITY_TYPES = ["Character", "Animal", "Place", "Object", "Activity", "Event"]
api_key = "ollama"
working_dir = "./examples/"
grag = GraphRAG(
working_dir=working_dir,
domain=DOMAIN,
example_queries="\n".join(EXAMPLE_QUERIES),
entity_types=ENTITY_TYPES,
config=GraphRAG.Config(
llm_service=OpenAILLMService(
model="llama3.2:latest",
base_url="http://localhost:11434/v1",
api_key=api_key,
),
embedding_service=OpenAIEmbeddingService(
model="nomic-embed-text",
base_url="http://localhost:11434/api/embeddings/",
api_key=api_key,
embedding_dim=512, # the output embedding dim of the chosen model
),
),
)
with open("./Caledonian Road_ From the award-winning au - Andrew O'Hagan.txt") as f:
grag.insert(f.read())
print(grag.query("Who is Campbell?").response) Giving error:
|
So i got around the above error, by I now have further errors with embedding, and am wondering given the status of embedding on ollama - has anyone actually got this to work? |
Just to be sure, are you using the pip version or this cloned repo? It may be a bug that we fixed but didn't push to pypi. |
Mmmh, looking here it seems it is supported ollama/ollama#2416 ? But indeed we should clarify this better. |
Ah, yes i am using the pip installed version |
Let me know if using the repo directly fixes the problem |
I am experiencing a similar issue with Azure. But it's throwing resource not found. I have installed fast-graphrag with pip. Linux mint 22 from fast_graphrag import GraphRAG
from fast_graphrag._llm import OpenAILLMService, OpenAIEmbeddingService
DOMAIN = "Analyze this story and identify the characters. Focus on how they interact with each other, the locations they explore, and their relationships."
EXAMPLE_QUERIES = [
"What is the significance of Christmas Eve in A Christmas Carol?",
"How does the setting of Victorian London contribute to the story's themes?",
"Describe the chain of events that leads to Scrooge's transformation.",
"How does Dickens use the different spirits (Past, Present, and Future) to guide Scrooge?",
"Why does Dickens choose to divide the story into \"staves\" rather than chapters?"
]
ENTITY_TYPES = ["Character", "Animal", "Place", "Object", "Activity", "Event"]
model = "gpt-4o"
base_url = "https://<resource>.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview"
api_key = "5xxxxxxxx"
working_dir="./book_example"
grag = GraphRAG(
working_dir=working_dir,
domain=DOMAIN,
example_queries="\n".join(EXAMPLE_QUERIES),
entity_types=ENTITY_TYPES,
config=GraphRAG.Config(
llm_service=OpenAILLMService(model=model, base_url=base_url, api_key=api_key),
embedding_service=OpenAIEmbeddingService(
model=model,
base_url=base_url,
api_key=api_key,
embedding_dim=512, # the output embedding dim of the chosen model
),
),
)
with open("./book.txt") as f:
grag.insert(f.read())
print(grag.query("Who is Scrooge?").response) Extracting data: 0%| | 0/1 [00:00<?, ?it/s]Error during information extraction from document: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
Extracting data: 100%|████████████████████████████| 1/1 [00:09<00:00, 9.48s/it]
Error during query: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
Traceback (most recent call last):
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/retry.py", line 222, in retry_async
response: ChatCompletion = await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/resources/chat/completions.py", line 1633, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/_base_client.py", line 1838, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/_base_client.py", line 1532, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/_base_client.py", line 1633, in _request
raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/retry.py", line 217, in retry_async
async for attempt in max_retries:
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/asyncio/__init__.py", line 166, in __anext__
do = await self.iter(retry_state=self._retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/asyncio/__init__.py", line 153, in iter
result = await action(retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/_utils.py", line 99, in inner
return call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/__init__.py", line 419, in exc_check
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x715107d72c50 state=finished raised NotFoundError>]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jontorres/Documents/development/loro/fast_graphrag/graphrag_test.py", line 47, in <module>
print(grag.query("Who is Scrooge?").response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 150, in query
return get_event_loop().run_until_complete(_query())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 146, in _query
raise e
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 142, in _query
answer = await self.async_query(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 168, in async_query
extracted_entities = await self.information_extraction_service.extract_entities_from_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_services/_information_extraction.py", line 46, in extract_entities_from_query
entities, _ = await format_and_send_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_llm/_base.py", line 40, in format_and_send_prompt
return await llm.send_message(prompt=formatted_prompt, response_model=response_model, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_utils.py", line 45, in wait_func
result = await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_llm/_llm_openai.py", line 80, in send_message
llm_response: GTResponseModel = await self.llm_async_client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/client.py", line 387, in create
return await self.create_fn(
^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/patch.py", line 161, in new_create_async
response = await retry_async(
^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/retry.py", line 248, in retry_async
raise InstructorRetryException(
instructor.exceptions.InstructorRetryException: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}} |
From your example it looks like you're using the same model and base_url for both LLM and Embedder, I'm not sure that's supported by Azure, I would doulbe check that. Specifically, the 404 is telling you that the LLM base_url is invalid. |
Hey, I appreciate the answer. Is the OpenAIEmbeddingService needed? I was trying to replicate the example in the main README.md but using this custom.py because from what I understand it's needed to explicit pass the endpoint API if you are not using openAI directly, right? |
Yes, both llm and embedder are necessary, but normally they have different models and urls. I will also clarify this in the example. |
Thank you for making it clear, but the error seems to persist even with a different deploy for the embedder. code: from fast_graphrag import GraphRAG
from fast_graphrag._llm import OpenAILLMService, OpenAIEmbeddingService
DOMAIN = "Analyze this story and identify the characters. Focus on how they interact with each other, the locations they explore, and their relationships."
EXAMPLE_QUERIES = [
"What is the significance of Christmas Eve in A Christmas Carol?",
"How does the setting of Victorian London contribute to the story's themes?",
"Describe the chain of events that leads to Scrooge's transformation.",
"How does Dickens use the different spirits (Past, Present, and Future) to guide Scrooge?",
"Why does Dickens choose to divide the story into \"staves\" rather than chapters?"
]
ENTITY_TYPES = ["Character", "Animal", "Place", "Object", "Activity", "Event"]
emb_model = "text-embedding-3-small"
emb_url = "https://<DEPLOYNAME>.openai.azure.com/openai/deployments/text-embedding-3-small/embeddings?api-version=2023-05-15"
emb_key = "5xxxx"
model = "gpt-4o"
base_url = "https://<DEPLOYNAME>.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview"
api_key = "5xxxx"
working_dir="./book_example"
grag = GraphRAG(
working_dir=working_dir,
domain=DOMAIN,
example_queries="\n".join(EXAMPLE_QUERIES),
entity_types=ENTITY_TYPES,
config=GraphRAG.Config(
llm_service=OpenAILLMService(model=model, base_url=base_url, api_key=api_key),
embedding_service=OpenAIEmbeddingService(
model=emb_model,
base_url=emb_url,
api_key=emb_key,
embedding_dim=512, # the output embedding dim of the chosen model
),
),
)
with open("./book.txt") as f:
grag.insert(f.read())
print(grag.query("Who is Scrooge?").response) Extracting data: 0%| | 0/1 [00:00<?, ?it/s]Error during information extraction from document: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
Extracting data: 100%|████████████████████████████| 1/1 [00:09<00:00, 9.38s/it]
Error during query: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
Traceback (most recent call last):
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/retry.py", line 222, in retry_async
response: ChatCompletion = await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/resources/chat/completions.py", line 1633, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/_base_client.py", line 1838, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/_base_client.py", line 1532, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/openai/_base_client.py", line 1633, in _request
raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/retry.py", line 217, in retry_async
async for attempt in max_retries:
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/asyncio/__init__.py", line 166, in __anext__
do = await self.iter(retry_state=self._retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/asyncio/__init__.py", line 153, in iter
result = await action(retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/_utils.py", line 99, in inner
return call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/tenacity/__init__.py", line 419, in exc_check
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x73ce66217a10 state=finished raised NotFoundError>]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/jontorres/Documents/development/loro/fast_graphrag/graphrag_test.py", line 44, in <module>
print(grag.query("Who is Scrooge?").response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 150, in query
return get_event_loop().run_until_complete(_query())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 146, in _query
raise e
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 142, in _query
answer = await self.async_query(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_graphrag.py", line 168, in async_query
extracted_entities = await self.information_extraction_service.extract_entities_from_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_services/_information_extraction.py", line 46, in extract_entities_from_query
entities, _ = await format_and_send_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_llm/_base.py", line 40, in format_and_send_prompt
return await llm.send_message(prompt=formatted_prompt, response_model=response_model, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_utils.py", line 45, in wait_func
result = await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/fast_graphrag/_llm/_llm_openai.py", line 80, in send_message
llm_response: GTResponseModel = await self.llm_async_client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/client.py", line 387, in create
return await self.create_fn(
^^^^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/patch.py", line 161, in new_create_async
response = await retry_async(
^^^^^^^^^^^^^^^^^^
File "/home/jontorres/anaconda3/envs/loro/lib/python3.11/site-packages/instructor/retry.py", line 248, in retry_async
raise InstructorRetryException(
instructor.exceptions.InstructorRetryException: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}} |
Hello, for both errors it looks like the url you're using doesn't point to a valid model. Can you try to instantiate the OpenAILLMService and use it directly? it provides a method "send_message". |
this is how i run it with ollama: import instructor
grag = GraphRAG(
working_dir=working_dir,
domain=DOMAIN,
example_queries="\n".join(QUERIES),
entity_types=ENTITY_TYPES,
config=GraphRAG.Config(
llm_service=OpenAILLMService(
model="llama3", base_url="http://localhost:11434/v1", api_key="ollama", mode=instructor.Mode.JSON
),
embedding_service=OpenAIEmbeddingService(
model="nomic-embed-text",
base_url="http://localhost:11434/v1",
api_key="ollama",
embedding_dim=768,
),
),
) |
While using Azure, you have to exactly specify the base_url of your model base_url_llm = https://<resource>.openai.azure.com/openai/deployments/gpt-4o And for the embed model, specify it like base_url_embed = https://<resource>.openai.azure.com/openai/deployments/text-embedding-3-large Make sure that these models are correctly deployed on Azure |
This commit can solve your problem:#62 |
When I use the official example to use my own LLM, such as GLM-4-Plus, it prompts an error
The text was updated successfully, but these errors were encountered: