Skip to content
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

AgentOps Implementation Examples #86

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
env/
4 changes: 3 additions & 1 deletion instagram_post/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SERPER_API_KEY=KEY # https://serper.dev/ (free tier)
BROWSERLESS_API_KEY=KEY # https://www.browserless.io/ (free tier)
MODEL='openhermes'
MODEL='openhermes'
AGENTOPS_API_KEY=KEY
AGENTOPS_PARENT_KEY=8e6301f7-bfae-4852-b30e-ab0f6d0b7253
2 changes: 1 addition & 1 deletion instagram_post/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class MarketingAnalysisAgents:
def __init__(self):
self.llm = Ollama(model=os.environ['MODEL'])
self.llm = Ollama(model=os.environ.get('MODEL'))

def product_competitor_agent(self):
return Agent(
Expand Down
57 changes: 28 additions & 29 deletions instagram_post/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dotenv import load_dotenv
load_dotenv()

from textwrap import dedent
from crewai import Agent, Crew

from crewai import Crew
from tasks import MarketingAnalysisTasks
from agents import MarketingAnalysisAgents
import agentops

load_dotenv()
agentops.init()

tasks = MarketingAnalysisTasks()
agents = MarketingAnalysisAgents()
Expand All @@ -15,7 +15,6 @@
product_website = input("What is the product website you want a marketing strategy for?\n")
product_details = input("Any extra details about the product and or the instagram post you want?\n")


# Create Agents
product_competitor_agent = agents.product_competitor_agent()
strategy_planner_agent = agents.strategy_planner_agent()
Expand All @@ -28,39 +27,39 @@

# Create Crew responsible for Copy
copy_crew = Crew(
agents=[
product_competitor_agent,
strategy_planner_agent,
creative_agent
],
tasks=[
website_analysis,
market_analysis,
campaign_development,
write_copy
],
verbose=True
agents=[
product_competitor_agent,
strategy_planner_agent,
creative_agent
],
tasks=[
website_analysis,
market_analysis,
campaign_development,
write_copy
],
verbose=True
)

ad_copy = copy_crew.kickoff()

# Create Crew responsible for Image
senior_photographer = agents.senior_photographer_agent()
chief_creative_diretor = agents.chief_creative_diretor_agent()
chief_creative_director = agents.chief_creative_diretor_agent()
# Create Tasks for Image
take_photo = tasks.take_photograph_task(senior_photographer, ad_copy, product_website, product_details)
approve_photo = tasks.review_photo(chief_creative_diretor, product_website, product_details)
approve_photo = tasks.review_photo(chief_creative_director, product_website, product_details)

image_crew = Crew(
agents=[
senior_photographer,
chief_creative_diretor
],
tasks=[
take_photo,
approve_photo
],
verbose=True
agents=[
senior_photographer,
chief_creative_director
],
tasks=[
take_photo,
approve_photo
],
verbose=True
)

image = image_crew.kickoff()
Expand Down
2 changes: 2 additions & 0 deletions instagram_post/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ crewai = "^0.11.0"
python-dotenv = "1.0.0"
opencv-python = "4.8.1.78"
google-search-results = "2.4.2"
agentops = "0.1.0"
unstructured = "0.12.6"

[tool.pyright]
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md
Expand Down
18 changes: 12 additions & 6 deletions instagram_post/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def product_analysis(self, agent, product_website, product_details):
Keep in mind, attention to detail is crucial for
a comprehensive analysis. It's currenlty 2024.
"""),
agent=agent
agent=agent,
expected_output="output"
)

def competitor_analysis(self, agent, product_website, product_details):
Expand All @@ -32,7 +33,8 @@ def competitor_analysis(self, agent, product_website, product_details):
Your final report MUST include BOTH all context about {product_website}
and a detailed comparison to whatever competitor they have competitors.
"""),
agent=agent
agent=agent,
expected_output="output"
)

def campaign_development(self, agent, product_website, product_details):
Expand All @@ -49,7 +51,8 @@ def campaign_development(self, agent, product_website, product_details):
Your final answer MUST be ideas that will resonate with the audience and
also include ALL context you have about the product and the customer.
"""),
agent=agent
agent=agent,
expected_output="output"
)

def instagram_ad_copy(self, agent):
Expand All @@ -70,7 +73,8 @@ def instagram_ad_copy(self, agent):
Your final answer MUST be 3 options for an ad copy for instagram that
not only informs but also excites and persuades the audience.
"""),
agent=agent
agent=agent,
expected_output="output"
)

def take_photograph_task(self, agent, copy, product_website, product_details):
Expand All @@ -95,7 +99,8 @@ def take_photograph_task(self, agent, copy, product_website, product_details):
Your final answer must be 3 options of photographs, each with 1 paragraph
describing the photograph exactly like the examples provided above.
"""),
agent=agent
agent=agent,
expected_output="output"
)

def review_photo(self, agent, product_website, product_details):
Expand All @@ -117,5 +122,6 @@ def review_photo(self, agent, product_website, product_details):
Your final answer must be 3 reviewed options of photographs,
each with 1 paragraph description following the examples provided above.
"""),
agent=agent
agent=agent,
expected_output="output"
)
6 changes: 4 additions & 2 deletions job-posting/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
SERPER_API_KEY=key_here
OPENAI_API_KEY=key_here
SERPER_API_KEY=KEY # https://serper.dev/ (free tier)
OPENAI_API_KEY=KEY
AGENTOPS_API_KEY=KEY
AGENTOPS_PARENT_KEY=8e6301f7-bfae-4852-b30e-ab0f6d0b7253
9 changes: 5 additions & 4 deletions job-posting/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from dotenv import load_dotenv
load_dotenv()

from crewai import Crew

from tasks import Tasks
from agents import Agents
import agentops
load_dotenv()

agentops.init(tags=['job-posting'])

tasks = Tasks()
agents = Agents()
Expand Down Expand Up @@ -43,4 +44,4 @@

print("Job Posting Creation Process Completed.")
print("Final Job Posting:")
print(result)
print(result)
6 changes: 4 additions & 2 deletions job-posting/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
python-dotenv=1.0.1
crewai=0.14.3
crewai==0.28.8
agentops==0.1.9
crewai-tools==0.1.1
python-dotenv==1.0.0
2 changes: 2 additions & 0 deletions landing_page_generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from tools.file_tools import FileTools
from tools.search_tools import SearchTools
from tools.template_tools import TemplateTools
import agentops

from dotenv import load_dotenv
load_dotenv()
agentops.init()

class LandingPageCrew():
def __init__(self, idea):
Expand Down
1 change: 1 addition & 0 deletions markdown_validator/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Using OpenAI's API
OPENAI_API_KEY="sk-..."
AGENTOPS_API_KEY=KEY
MODEL_NAME="gpt-3.5-turbo"

# Using LLM Studio's API
Expand Down
9 changes: 4 additions & 5 deletions markdown_validator/MarkdownTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from langchain.tools import tool
from pymarkdown.api import PyMarkdownApi, PyMarkdownApiException


@tool("markdown_validation_tool")
def markdown_validation_tool(file_path: str) -> str:
"""
Expand All @@ -15,18 +16,16 @@ def markdown_validation_tool(file_path: str) -> str:
- validation_results: A list of validation results
and suggestions on how to fix them.
"""

print("\n\nValidating Markdown syntax...\n\n" + file_path)

scan_result = None
try:
if not (os.path.exists(file_path)):
return "Could not validate file. The provided file path does not exist."
return "Could not validate file. The provided file path does not exist."

scan_result = PyMarkdownApi().scan_path(file_path.rstrip().lstrip())
results = str(scan_result)
results = str(scan_result)
return results # Return the reviewed document
except PyMarkdownApiException as this_exception:
print(f"API Exception: {this_exception}", file=sys.stderr)
return f"API Exception: {str(this_exception)}"

17 changes: 11 additions & 6 deletions markdown_validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
from crewai import Agent, Task
import os
from dotenv import load_dotenv
from langchain.tools import tool
from langchain.chat_models.openai import ChatOpenAI
from pymarkdown.api import PyMarkdownApi, PyMarkdownApiException
from langchain_openai import ChatOpenAI
from MarkdownTools import markdown_validation_tool
import agentops

load_dotenv()
agentops.init(tags=['markdown_validator'])

defalut_llm = ChatOpenAI(openai_api_base=os.environ.get("OPENAI_API_BASE_URL", "https://api.openai.com/v1"),
openai_api_key=os.environ.get("OPENAI_API_KEY"),
temperature=0.1,
model_name=os.environ.get("MODEL_NAME", "gpt-3.5-turbo"),
top_p=0.3)
model_name=os.environ.get("MODEL_NAME", "gpt-3.5-turbo"))



Expand Down Expand Up @@ -70,7 +69,8 @@ def process_markdown_document(filename):

If you already know the answer or if you do not need
to use a tool, return it as your Final Answer.""",
agent=general_agent)
agent=general_agent,
expected_output="")

updated_markdown = syntax_review_task.execute()

Expand All @@ -84,3 +84,8 @@ def process_markdown_document(filename):
processed_document = process_markdown_document(filename)
print(processed_document)

else:
filename = "README.md"
processed_document = process_markdown_document(filename)
print(processed_document)

2 changes: 2 additions & 0 deletions markdown_validator/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ crewai = "^0.11.0"
python-dotenv = "1.0.0"
markdown = "3.4.3"
pymarkdownlnt = "0.9.15"
langchain_openai = "0.1.1"
agentops = "0.1.9"

[tool.pyright]
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md
Expand Down
4 changes: 2 additions & 2 deletions starter_template/.env_example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OPENAI_API_KEY = 'OPENAI_API_KEY'

OPENAI_ORGANIZATION_ID = 'OPENAI_ORGANIZATION_ID'
OPENAI_ORGANIZATION_ID = 'OPENAI_ORGANIZATION_ID'
AGENTOPS_API_KEY=KEY
3 changes: 2 additions & 1 deletion trip_planner/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SERPER_API_KEY=KEY # https://serper.dev/ (free tier)
BROWSERLESS_API_KEY=KEY # https://www.browserless.io/ (free tier)
OPENAI_API_KEY=KEY
OPENAI_API_KEY=KEY
AGENTOPS_API_KEY=KEY