testing_20240105_2251.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import os
  2. from crewai import Agent, Task, Crew, Process
  3. from langchain.llms import Ollama
  4. ollama_hermes = Ollama(model="openhermes")
  5. # Define your tools, custom or not.
  6. # Install duckduckgo-search for this example:
  7. #
  8. # !pip install -U duckduckgo-search
  9. from langchain.tools import DuckDuckGoSearchRun
  10. search_tool = DuckDuckGoSearchRun()
  11. # Define your agents with roles and goals
  12. researcher = Agent(
  13. role='Game Researcher',
  14. goal='Explore innovative developments in the gaming industry, focusing on',
  15. backstory="""You are a Game Researcher at a renowned gaming think tank.
  16. Your expertise lies in identifying emerging trends and technologies in the gaming world.
  17. You have a passion for dissecting complex game mechanics and presenting actionable insights."""
  18. role='Senior Research Analyst',
  19. goal='Uncover cutting-edge developments in AI and data science in',
  20. backstory="""You are a Senior Research Analyst at a leading tech think tank.
  21. Your expertise lies in identifying emerging trends and technologies in AI and
  22. data science. You have a knack for dissecting complex data and presenting
  23. actionable insights.""",
  24. verbose=True,
  25. allow_delegation=False,
  26. tools=[search_tool],
  27. llm=ollama_hermes,
  28. # llm=OpenAI(temperature=0.7, model_name="gpt-4"). It uses langchain.chat_models, default is GPT4
  29. )
  30. writer = Agent(
  31. role='Tech Content Strategist',
  32. goal='Craft compelling content on tech advancements',
  33. backstory="""You are a renowned Tech Content Strategist, known for your insightful
  34. and engaging articles on technology and innovation. With a deep understanding of
  35. the tech industry, you transform complex concepts into compelling narratives.""",
  36. verbose=True,
  37. allow_delegation=True,
  38. llm=ollama_hermes,
  39. )
  40. # Create tasks for your agents
  41. task1 = Task(
  42. description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
  43. Identify key trends, breakthrough technologies, and potential industry impacts.
  44. Compile your findings in a detailed report. Your final answer MUST be a full analysis report""",
  45. agent=researcher
  46. )
  47. task2 = Task(
  48. description="""Using the insights from the researcher's report, develop an engaging blog
  49. post that highlights the most significant AI advancements.
  50. Your post should be informative yet accessible, catering to a tech-savvy audience.
  51. Aim for a narrative that captures the essence of these breakthroughs and their
  52. implications for the future. Your final answer MUST be the full blog post of at least 3 paragraphs.""",
  53. agent=writer
  54. )
  55. # Instantiate your crew with a sequential process
  56. crew = Crew(
  57. agents=[researcher, writer],
  58. tasks=[task1, task2],
  59. llm=ollama_hermes,
  60. verbose=2, # Crew verbose more will let you know what tasks are being worked on, you can set it to 1 or 2 to different logging levels
  61. process=Process.sequential # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
  62. )
  63. # Get your crew to work!
  64. result = crew.kickoff()
  65. print("######################")
  66. print(result)