Skip to content

Commit 9a5559e

Browse files
committed
Merge branch 'development' of github.com:Scale3-Labs/langtrace-python-sdk into refactor-hasttr-logic
2 parents 12d9bdb + 38ba1c5 commit 9a5559e

File tree

23 files changed

+910
-172
lines changed

23 files changed

+910
-172
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
21
{
32
"[python]": {
43
"editor.defaultFormatter": "ms-python.black-formatter",
54
},
65
"editor.formatOnSave": true,
6+
"python.testing.pytestArgs": [
7+
"src"
8+
],
9+
"python.testing.unittestEnabled": false,
10+
"python.testing.pytestEnabled": true,
711
}

mypy.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[mypy]
2+
strict = True
3+
disable_error_code = import-untyped
4+
disallow_untyped_calls = True # Disallow function calls without type annotations
5+
disallow_untyped_defs = True # Disallow defining functions without type annotations
6+
disallow_any_explicit = True # Disallow explicit use of `Any`
7+
disallow_any_generics = True # Disallow generic types without specific type parameters
8+
disallow_incomplete_defs = True # Disallow defining incomplete function signatures
9+
no_implicit_optional = True # Disallow implicitly Optional types
10+
warn_unused_configs = True # Warn about unused configurations
11+
warn_redundant_casts = True # Warn about unnecessary type casts
12+
warn_return_any = True # Warn if a function returns `Any`
13+
warn_unreachable = True # Warn about unreachable code
14+
# Ignore external modules or allow specific imports
15+
follow_imports = skip
16+
ignore_missing_imports = True

src/examples/anthropic_example/completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
_ = load_dotenv(find_dotenv())
99

10-
langtrace.init()
10+
langtrace.init(write_spans_to_console=True)
1111

1212

1313
@with_langtrace_root_span("messages_create")

src/examples/crewai_example/instagram_post/__init__.py

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from crewai import Agent
2+
from tools.browser_tools import scrape_and_summarize_website
3+
from langchain_openai import ChatOpenAI
4+
# from langchain.llms import Ollama
5+
6+
7+
class MarketingAnalysisAgents:
8+
def __init__(self):
9+
# self.llm = Ollama(model=os.environ["MODEL"])
10+
self.llm = ChatOpenAI(model_name="gpt-4", temperature=0.7)
11+
12+
def product_competitor_agent(self):
13+
return Agent(
14+
role="Lead Market Analyst",
15+
goal="""\
16+
Conduct amazing analysis of the products and
17+
competitors, providing in-depth insights to guide
18+
marketing strategies.""",
19+
backstory="""\
20+
As the Lead Market Analyst at a premier
21+
digital marketing firm, you specialize in dissecting
22+
online business landscapes.""",
23+
tools=[scrape_and_summarize_website],
24+
allow_delegation=False,
25+
llm=self.llm,
26+
verbose=True,
27+
)
28+
29+
def strategy_planner_agent(self):
30+
return Agent(
31+
role="Chief Marketing Strategist",
32+
goal="""\
33+
Synthesize amazing insights from product analysis
34+
to formulate incredible marketing strategies.""",
35+
backstory="""\
36+
You are the Chief Marketing Strategist at
37+
a leading digital marketing agency, known for crafting
38+
bespoke strategies that drive success.""",
39+
tools=[scrape_and_summarize_website],
40+
llm=self.llm,
41+
verbose=True,
42+
)
43+
44+
def creative_content_creator_agent(self):
45+
return Agent(
46+
role="Creative Content Creator",
47+
goal="""\
48+
Develop compelling and innovative content
49+
for social media campaigns, with a focus on creating
50+
high-impact Instagram ad copies.""",
51+
backstory="""\
52+
As a Creative Content Creator at a top-tier
53+
digital marketing agency, you excel in crafting narratives
54+
that resonate with audiences on social media.
55+
Your expertise lies in turning marketing strategies
56+
into engaging stories and visual content that capture
57+
attention and inspire action.""",
58+
tools=[scrape_and_summarize_website],
59+
llm=self.llm,
60+
verbose=True,
61+
)
62+
63+
def senior_photographer_agent(self):
64+
return Agent(
65+
role="Senior Photographer",
66+
goal="""\
67+
Take the most amazing photographs for instagram ads that
68+
capture emotions and convey a compelling message.""",
69+
backstory="""\
70+
As a Senior Photographer at a leading digital marketing
71+
agency, you are an expert at taking amazing photographs that
72+
inspire and engage, you're now working on a new campaign for a super
73+
important customer and you need to take the most amazing photograph.""",
74+
tools=[scrape_and_summarize_website],
75+
llm=self.llm,
76+
allow_delegation=False,
77+
verbose=True,
78+
)
79+
80+
def chief_creative_diretor_agent(self):
81+
return Agent(
82+
role="Chief Creative Director",
83+
goal="""\
84+
Oversee the work done by your team to make sure it's the best
85+
possible and aligned with the product's goals, review, approve,
86+
ask clarifying question or delegate follow up work if necessary to make
87+
decisions""",
88+
backstory="""\
89+
You're the Chief Content Officer of leading digital
90+
marketing specialized in product branding. You're working on a new
91+
customer, trying to make sure your team is crafting the best possible
92+
content for the customer.""",
93+
tools=[scrape_and_summarize_website],
94+
llm=self.llm,
95+
verbose=True,
96+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
from dotenv import load_dotenv
3+
4+
load_dotenv()
5+
6+
7+
from langtrace_python_sdk import langtrace
8+
9+
langtrace.init()
10+
11+
from crewai import Crew
12+
from agents import MarketingAnalysisAgents
13+
from tasks import MarketingAnalysisTasks
14+
15+
tasks = MarketingAnalysisTasks()
16+
agents = MarketingAnalysisAgents()
17+
18+
print("## Welcome to the marketing Crew")
19+
print('-------------------------------')
20+
product_website = "https://langtrace.ai"
21+
product_details = "LLM App monitoring"
22+
23+
24+
# Create Agents
25+
product_competitor_agent = agents.product_competitor_agent()
26+
# strategy_planner_agent = agents.strategy_planner_agent()
27+
# creative_agent = agents.creative_content_creator_agent()
28+
# # Create Tasks
29+
website_analysis = tasks.product_analysis(product_competitor_agent, product_website, product_details)
30+
# market_analysis = tasks.competitor_analysis(product_competitor_agent, product_website, product_details)
31+
# campaign_development = tasks.campaign_development(strategy_planner_agent, product_website, product_details)
32+
# write_copy = tasks.instagram_ad_copy(creative_agent)
33+
34+
# Create Crew responsible for Copy
35+
copy_crew = Crew(
36+
agents=[
37+
product_competitor_agent,
38+
# strategy_planner_agent,
39+
# creative_agent
40+
],
41+
tasks=[
42+
website_analysis,
43+
# market_analysis,
44+
# campaign_development,
45+
# write_copy
46+
],
47+
verbose=True
48+
)
49+
50+
ad_copy = copy_crew.kickoff()
51+
52+
# Create Crew responsible for Image
53+
# senior_photographer = agents.senior_photographer_agent()
54+
# chief_creative_diretor = agents.chief_creative_diretor_agent()
55+
# # Create Tasks for Image
56+
# take_photo = tasks.take_photograph_task(senior_photographer, ad_copy, product_website, product_details)
57+
# approve_photo = tasks.review_photo(chief_creative_diretor, product_website, product_details)
58+
59+
# image_crew = Crew(
60+
# agents=[
61+
# senior_photographer,
62+
# chief_creative_diretor
63+
# ],
64+
# tasks=[
65+
# take_photo,
66+
# approve_photo
67+
# ],
68+
# verbose=True
69+
# )
70+
71+
# image = image_crew.kickoff()
72+
73+
# Print results
74+
print("\n\n########################")
75+
print("## Here is the result")
76+
print("########################\n")
77+
print("Your post copy:")
78+
print(ad_copy)
79+
# print("'\n\nYour midjourney description:")
80+
# print(image)
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
from crewai import Task
2+
from textwrap import dedent
3+
4+
5+
class MarketingAnalysisTasks:
6+
def product_analysis(self, agent, product_website, product_details):
7+
return Task(
8+
description=dedent(
9+
f"""\
10+
Analyze the given product website: {product_website}.
11+
Extra details provided by the customer: {product_details}.
12+
13+
Focus on identifying unique features, benefits,
14+
and the overall narrative presented.
15+
16+
Your final report should clearly articulate the
17+
product's key selling points, its market appeal,
18+
and suggestions for enhancement or positioning.
19+
Emphasize the aspects that make the product stand out.
20+
21+
Keep in mind, attention to detail is crucial for
22+
a comprehensive analysis. It's currenlty 2024.
23+
"""
24+
),
25+
agent=agent,
26+
expected_output="A detailed analysis of the product website, highlighting key features, benefits, and market positioning.",
27+
)
28+
29+
def competitor_analysis(self, agent, product_website, product_details):
30+
return Task(
31+
description=dedent(
32+
f"""\
33+
Explore competitor of: {product_website}.
34+
Extra details provided by the customer: {product_details}.
35+
36+
Identify the top 3 competitors and analyze their
37+
strategies, market positioning, and customer perception.
38+
39+
Your final report MUST include BOTH all context about {product_website}
40+
and a detailed comparison to whatever competitor they have competitors.
41+
"""
42+
),
43+
agent=agent,
44+
expected_output="A comprehensive analysis of the top 3 competitors, including their strategies, market positioning, and customer perception.",
45+
)
46+
47+
def campaign_development(self, agent, product_website, product_details):
48+
return Task(
49+
description=dedent(
50+
f"""\
51+
You're creating a targeted marketing campaign for: {product_website}.
52+
Extra details provided by the customer: {product_details}.
53+
54+
To start this campaing we will need a strategy and creative content ideas.
55+
It should be meticulously designed to captivate and engage
56+
the product's target audience.
57+
58+
Based on your ideas your co-workers will create the content for the campaign.
59+
60+
Your final answer MUST be ideas that will resonate with the audience and
61+
also include ALL context you have about the product and the customer.
62+
"""
63+
),
64+
agent=agent,
65+
expected_output="A detailed marketing campaign strategy, including creative content ideas and target audience analysis.",
66+
)
67+
68+
def instagram_ad_copy(self, agent):
69+
return Task(
70+
description=dedent(
71+
"""\
72+
Craft an engaging Instagram post copy.
73+
The copy should be punchy, captivating, concise,
74+
and aligned with the product marketing strategy.
75+
76+
Focus on creating a message that resonates with
77+
the target audience and highlights the product's
78+
unique selling points.
79+
80+
Your ad copy must be attention-grabbing and should
81+
encourage viewers to take action, whether it's
82+
visiting the website, making a purchase, or learning
83+
more about the product.
84+
85+
Your final answer MUST be 3 options for an ad copy for instagram that
86+
not only informs but also excites and persuades the audience.
87+
"""
88+
),
89+
agent=agent,
90+
expected_output="Three engaging Instagram ad copies that align with the product marketing strategy.",
91+
)
92+
93+
def take_photograph_task(self, agent, copy, product_website, product_details):
94+
return Task(
95+
description=dedent(
96+
f"""\
97+
You are working on a new campaign for a super important customer,
98+
and you MUST take the most amazing photo ever for an instagram post
99+
regarding the product, you have the following copy:
100+
{copy}
101+
102+
This is the product you are working with: {product_website}.
103+
Extra details provided by the customer: {product_details}.
104+
105+
Imagine what the photo you wanna take describe it in a paragraph.
106+
Here are some examples for you follow:
107+
- high tech airplaine in a beautiful blue sky in a beautiful sunset super cripsy beautiful 4k, professional wide shot
108+
- the last supper, with Jesus and his disciples, breaking bread, close shot, soft lighting, 4k, crisp
109+
- an bearded old man in the snows, using very warm clothing, with mountains full of snow behind him, soft lighting, 4k, crisp, close up to the camera
110+
111+
Think creatively and focus on how the image can capture the audience's
112+
attention. Don't show the actual product on the photo.
113+
114+
Your final answer must be 3 options of photographs, each with 1 paragraph
115+
describing the photograph exactly like the examples provided above.
116+
"""
117+
),
118+
agent=agent,
119+
expected_output="Three high-quality photographs that creatively capture the essence of the product and engage the audience.",
120+
)
121+
122+
def review_photo(self, agent, product_website, product_details):
123+
return Task(
124+
description=dedent(
125+
f"""\
126+
Review the photos you got from the senior photographer.
127+
Make sure it's the best possible and aligned with the product's goals,
128+
review, approve, ask clarifying question or delegate follow up work if
129+
necessary to make decisions. When delegating work send the full draft
130+
as part of the information.
131+
132+
This is the product you are working with: {product_website}.
133+
Extra details provided by the customer: {product_details}.
134+
135+
Here are some examples on how the final photographs should look like:
136+
- high tech airplaine in a beautiful blue sky in a beautiful sunset super cripsy beautiful 4k, professional wide shot
137+
- the last supper, with Jesus and his disciples, breaking bread, close shot, soft lighting, 4k, crisp
138+
- an bearded old man in the snows, using very warm clothing, with mountains full of snow behind him, soft lighting, 4k, crisp, close up to the camera
139+
140+
Your final answer must be 3 reviewed options of photographs,
141+
each with 1 paragraph description following the examples provided above.
142+
"""
143+
),
144+
agent=agent,
145+
expected_output="Three reviewed photographs that align with the product's goals and meet the required standards.",
146+
)

src/examples/crewai_example/instagram_post/tools/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)