Skip to content

Commit

Permalink
v2.5.32
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Nov 14, 2024
1 parent 3cf86a9 commit 0122904
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cookbook/workflows/blog_post_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def run(self, topic: str, use_cache: bool = True) -> Iterator[RunResponse]:
# The topic to generate a blog post on
topic = "US Elections 2024"

# Create the workflow
# Instantiate the workflow
generate_blog_post = BlogPostGenerator(
session_id=f"generate-blog-post-on-{topic}",
storage=SqlWorkflowStorage(
Expand Down
9 changes: 6 additions & 3 deletions cookbook/workflows/news_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,12 @@ def run(
return writer_response


# Create the workflow
# The topic to generate a report on
topic = "IBM Hashicorp Acquisition"

# Instantiate the workflow
generate_news_report = GenerateNewsReport(
session_id="generate-report-ibm-hashicorp-acquisition",
session_id=f"generate-report-on-{topic}",
storage=SqlWorkflowStorage(
table_name="generate_news_report_workflows",
db_file="tmp/workflows.db",
Expand All @@ -238,7 +241,7 @@ def run(

# Run workflow
report: RunResponse = generate_news_report.run(
topic="IBM Hashicorp Acquisition", use_search_cache=True, use_scrape_cache=True, use_cached_report=False
topic=topic, use_search_cache=True, use_scrape_cache=True, use_cached_report=False
)

# Print the response
Expand Down
21 changes: 9 additions & 12 deletions cookbook/workflows/news_article_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,20 @@ def run(
"topic": topic,
"articles": [v.model_dump() for v in scraped_articles.values()],
}
writer_response_stream: Iterator[RunResponse] = self.writer.run(json.dumps(writer_input, indent=4), stream=True)

# 3.2: Yield and save the writer_response in the session state
writer_response = ""
for writer_response_chunk in writer_response_stream:
if writer_response_chunk.content is not None:
writer_response += writer_response_chunk.content
yield writer_response_chunk
yield from self.writer.run(json.dumps(writer_input, indent=4), stream=True)

# 3.2: Save the writer_response in the session state
if "reports" not in self.session_state:
self.session_state["reports"] = []
self.session_state["reports"].append({"topic": topic, "report": writer_response})
self.session_state["reports"].append({"topic": topic, "report": self.writer.run_response.content})


# The topic to generate a report on
topic = "IBM Hashicorp Acquisition"

# Create the workflow
# Instantiate the workflow
generate_news_report = GenerateNewsReport(
session_id="generate-report-ibm-hashicorp-acquisition",
session_id=f"generate-report-on-{topic}",
storage=SqlWorkflowStorage(
table_name="generate_news_report_workflows",
db_file="tmp/workflows.db",
Expand All @@ -243,7 +240,7 @@ def run(

# Run workflow
report_stream: Iterator[RunResponse] = generate_news_report.run(
topic="IBM Hashicorp Acquisition", use_search_cache=True, use_scrape_cache=True, use_cached_report=False
topic=topic, use_search_cache=True, use_scrape_cache=True, use_cached_report=False
)

# Print the response
Expand Down

0 comments on commit 0122904

Please sign in to comment.