Fix rate limits by adding time.sleep delays between pipeline steps
Browse files- pipeline.py +10 -0
pipeline.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from agents import build_reader_agent, build_search_agent, writer_chain, critic_chain
|
|
|
|
| 2 |
|
| 3 |
def extract_text(content) -> str:
|
| 4 |
if isinstance(content, str):
|
|
@@ -25,6 +26,9 @@ def run_research_pipeline(topic: str) -> dict:
|
|
| 25 |
state["search_results"]= extract_text(search_result['messages'][-1].content)
|
| 26 |
print("\n search result", state['search_results'])
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
#Step 2 - reader agent
|
| 29 |
print("\n" + "="*50)
|
| 30 |
print("step 2- reader agent is scrapping top respurces ...")
|
|
@@ -42,6 +46,9 @@ def run_research_pipeline(topic: str) -> dict:
|
|
| 42 |
state['scraped_content']= extract_text(reader_result['messages'][-1].content)
|
| 43 |
print("\nScraped content\n", state['scraped_content'])
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
#Step 3- writer chain
|
| 46 |
|
| 47 |
print("\n" + "="*50)
|
|
@@ -66,6 +73,9 @@ def run_research_pipeline(topic: str) -> dict:
|
|
| 66 |
print("step 3- Critic is reviewing the report ...")
|
| 67 |
print("="*50)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
state['feedback']=critic_chain.invoke({
|
| 70 |
"report": state['report']
|
| 71 |
})
|
|
|
|
| 1 |
from agents import build_reader_agent, build_search_agent, writer_chain, critic_chain
|
| 2 |
+
import time
|
| 3 |
|
| 4 |
def extract_text(content) -> str:
|
| 5 |
if isinstance(content, str):
|
|
|
|
| 26 |
state["search_results"]= extract_text(search_result['messages'][-1].content)
|
| 27 |
print("\n search result", state['search_results'])
|
| 28 |
|
| 29 |
+
# Introduce delay to prevent rate limits
|
| 30 |
+
time.sleep(5)
|
| 31 |
+
|
| 32 |
#Step 2 - reader agent
|
| 33 |
print("\n" + "="*50)
|
| 34 |
print("step 2- reader agent is scrapping top respurces ...")
|
|
|
|
| 46 |
state['scraped_content']= extract_text(reader_result['messages'][-1].content)
|
| 47 |
print("\nScraped content\n", state['scraped_content'])
|
| 48 |
|
| 49 |
+
# Introduce delay to prevent rate limits
|
| 50 |
+
time.sleep(5)
|
| 51 |
+
|
| 52 |
#Step 3- writer chain
|
| 53 |
|
| 54 |
print("\n" + "="*50)
|
|
|
|
| 73 |
print("step 3- Critic is reviewing the report ...")
|
| 74 |
print("="*50)
|
| 75 |
|
| 76 |
+
# Introduce delay to prevent rate limits
|
| 77 |
+
time.sleep(5)
|
| 78 |
+
|
| 79 |
state['feedback']=critic_chain.invoke({
|
| 80 |
"report": state['report']
|
| 81 |
})
|