testing_20240105_2301.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. verbose=True,
  19. allow_delegation=False,
  20. tools=[search_tool],
  21. llm=ollama_hermes,
  22. # llm=OpenAI(temperature=0.7, model_name="gpt-4"). It uses langchain.chat_models, default is GPT4
  23. )
  24. writer = Agent(
  25. role='Game Content Strategist',
  26. goal='Craft compelling content on game advancements',
  27. backstory="""You are a renowned Game Content Strategist, known for your insightful
  28. and engaging articles on technology and innovation in games. With a deep understanding of
  29. the tech industry, you transform complex concepts into compelling narratives.""",
  30. verbose=True,
  31. allow_delegation=True,
  32. llm=ollama_hermes,
  33. )
  34. # Create tasks for your agents
  35. task1 = Task(
  36. description="""Conduct a comprehensive analysis of the latest role playing game Starfield from Bethesda.
  37. Identify quest lines, amount of hours it takes to complete, breakthrough technologies, the positive and negative responses it got and potential future DLC.
  38. Compile your findings in a detailed report. Your final answer MUST be a full analysis report""",
  39. agent=researcher
  40. )
  41. task2 = Task(
  42. description="""Using the insights from the researcher's report, develop an engaging blog
  43. post that highlights of the game Startfield.
  44. Your post should be informative yet accessible, catering to a tech-savvy audience.
  45. Aim for a narrative that captures the essence of these game.
  46. Your final answer MUST be the full blog post of at least 3 paragraphs.""",
  47. agent=writer
  48. )
  49. # Instantiate your crew with a sequential process
  50. crew = Crew(
  51. agents=[researcher, writer],
  52. tasks=[task1, task2],
  53. llm=ollama_hermes,
  54. 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
  55. 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.
  56. )
  57. # Get your crew to work!
  58. result = crew.kickoff()
  59. print("######################")
  60. print(result)