-
Notifications
You must be signed in to change notification settings - Fork 3k
Refactor AI News Generator to use CrewAI Flows #178
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
Open
xpander-ai-coding-agent
wants to merge
1
commit into
patchy631:main
Choose a base branch
from
xpander-ai-coding-agent:crewai-flows-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Main entry point for the AI News Generator using CrewAI Flows. | ||
|
||
This script provides a command-line interface to generate news content | ||
using the NewsGeneratorFlow implementation. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
from typing import Optional | ||
from news_flow import NewsGeneratorFlow | ||
|
||
|
||
def main(): | ||
""" | ||
Main function to run the AI News Generator Flow from command line. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
description="Generate AI news content using CrewAI Flows", | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
epilog=""" | ||
Examples: | ||
python main.py --topic "Latest developments in artificial intelligence" | ||
python main.py --topic "Climate change solutions" --output article.md | ||
""" | ||
) | ||
|
||
parser.add_argument( | ||
"--topic", | ||
type=str, | ||
required=True, | ||
help="Topic to research and write about" | ||
) | ||
|
||
parser.add_argument( | ||
"--output", | ||
type=str, | ||
help="Output file to save the generated content (optional)" | ||
) | ||
|
||
parser.add_argument( | ||
"--verbose", | ||
action="store_true", | ||
help="Enable verbose logging" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if not args.topic.strip(): | ||
print("Error: Topic cannot be empty", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
try: | ||
print(f"🚀 Starting AI News Generator Flow for topic: '{args.topic}'") | ||
print("📊 Initializing research phase...") | ||
|
||
# Create and run the flow | ||
flow = NewsGeneratorFlow() | ||
result = flow.kickoff(inputs={"topic": args.topic}) | ||
|
||
# Convert result to string if it's not already | ||
content = str(result) | ||
|
||
print("✅ Content generation completed!") | ||
|
||
# Save to file if specified | ||
if args.output: | ||
try: | ||
with open(args.output, 'w', encoding='utf-8') as f: | ||
f.write(content) | ||
print(f"💾 Content saved to: {args.output}") | ||
except IOError as e: | ||
print(f"Error saving file: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
else: | ||
# Print to stdout | ||
print("\n" + "="*80) | ||
print("GENERATED CONTENT:") | ||
print("="*80) | ||
print(content) | ||
print("="*80) | ||
|
||
return 0 | ||
|
||
except KeyboardInterrupt: | ||
print("\n⚠️ Operation cancelled by user", file=sys.stderr) | ||
return 1 | ||
except Exception as e: | ||
print(f"❌ Error: {e}", file=sys.stderr) | ||
if args.verbose: | ||
import traceback | ||
traceback.print_exc() | ||
return 1 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import
The
Optional
type fromtyping
is imported but never used in the code.-from typing import Optional
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.12.2)
11-11:
typing.Optional
imported but unusedRemove unused import:
typing.Optional
(F401)
🤖 Prompt for AI Agents