Closed yuntong613 closed 2 months ago
Hey @yuntong613! I'm here to help you with any bugs, questions, or contributions you may have. Let's work together to solve this issue!
To resolve "Request timed out" errors when using the DynamicLLMPathExtractor
from the llama_index
library, you can try the following steps:
Increase Timeout Settings: Ensure that the timeout settings for the language model (LLM) are sufficiently high to handle the requests. This might involve modifying the LLM's configuration if it supports timeout settings.
Reduce Load: Decrease the number of workers or the maximum number of paths per chunk to reduce the load on the LLM. This can be done by adjusting the num_workers
and max_triplets_per_chunk
parameters in the DynamicLLMPathExtractor
initialization.
Retry Mechanism: Implement a retry mechanism to handle transient network issues or temporary unavailability of the LLM service.
Here is an example of how you can adjust the num_workers
and max_triplets_per_chunk
parameters:
kg_extractor = DynamicLLMPathExtractor(
llm=llm_local,
extract_prompt=MY_DEFAULT_DYNAMIC_EXTRACT_PROMPT,
max_triplets_per_chunk=5, # Reduce the number of triplets per chunk
num_workers=2, # Reduce the number of workers
allowed_entity_types=None,
allowed_relation_types=None,
allowed_relation_props=[],
allowed_entity_props=[],
)
Additionally, you can wrap the LLM call in a retry mechanism:
import asyncio
import aiohttp
from tenacity import retry, wait_fixed, stop_after_attempt
class DynamicLLMPathExtractor(TransformComponent):
# ... existing code ...
@retry(wait=wait_fixed(2), stop=stop_after_attempt(3))
async def _aextract(self, node: BaseNode) -> BaseNode:
"""Extract triples from a node."""
assert hasattr(node, "text")
text = node.get_content(metadata_mode="llm")
try:
llm_response = await self.llm.apredict(
self.extract_prompt,
text=text,
max_knowledge_triplets=self.max_triplets_per_chunk,
)
triples = self.parse_fn(llm_response)
except (ValueError, aiohttp.ClientError) as e:
print(f"Error: {e}, retrying...")
raise
except asyncio.TimeoutError:
print("Request timed out, retrying...")
raise
# ... existing code to process triples ...
return node
By implementing these changes, you can mitigate the "Request timed out" errors and improve the reliability of the DynamicLLMPathExtractor
[1][2][3].
To continue talking to Dosu, mention @dosu.
Question Validation
Question