Skip to content

Commit 6876f92

Browse files
committed
Merge branch 'main' of github.com:Scale3-Labs/langtrace-python-sdk into release
2 parents ad168b3 + e011881 commit 6876f92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+202155
-496
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Langtrace automatically captures traces from the following vendors:
246246
| Groq | LLM | :x: | :white_check_mark: |
247247
| Perplexity | LLM | :white_check_mark: | :white_check_mark: |
248248
| Gemini | LLM | :x: | :white_check_mark: |
249+
| Mistral | LLM | :x: | :white_check_mark: |
249250
| Langchain | Framework | :x: | :white_check_mark: |
250251
| LlamaIndex | Framework | :white_check_mark: | :white_check_mark: |
251252
| Langgraph | Framework | :x: | :white_check_mark: |

pyproject.toml

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ description = "Python SDK for LangTrace"
1212
readme = "README.md"
1313
authors = [{ name = "Scale3 Labs", email = "[email protected]" }]
1414
license = "Apache-2.0"
15-
classifiers=[
16-
"Programming Language :: Python :: 3",
17-
"License :: OSI Approved :: Apache Software License",
18-
"Operating System :: OS Independent",
15+
classifiers = [
16+
"Programming Language :: Python :: 3",
17+
"License :: OSI Approved :: Apache Software License",
18+
"Operating System :: OS Independent",
1919
]
2020
dependencies = [
21-
'trace-attributes==7.0.1',
21+
'trace-attributes==7.0.4',
2222
'opentelemetry-api>=1.25.0',
2323
'opentelemetry-sdk>=1.25.0',
2424
'opentelemetry-instrumentation>=0.47b0',
@@ -28,39 +28,36 @@ dependencies = [
2828
'tiktoken>=0.1.1',
2929
'colorama>=0.4.6',
3030
'sqlalchemy',
31-
'fsspec>=2024.6.0'
31+
'fsspec>=2024.6.0',
32+
"transformers>=4.11.3",
3233
]
3334

3435
requires-python = ">=3.9"
3536

3637
[project.optional-dependencies]
3738
dev = [
38-
"openai",
39-
"anthropic",
40-
"chromadb",
41-
"qdrant-client",
42-
"python-dotenv",
43-
"pinecone-client",
44-
"langchain",
45-
"langchain-community",
46-
"langchain-openai",
47-
"langchain-openai",
48-
"chromadb",
49-
"cohere",
50-
"qdrant_client",
51-
"weaviate-client",
52-
"ollama",
53-
"groq",
54-
"google-generativeai",
55-
"google-cloud-aiplatform"
56-
]
57-
58-
test = [
59-
"pytest",
60-
"pytest-vcr",
61-
"pytest-asyncio",
39+
"openai==1.30.1",
40+
"anthropic",
41+
"chromadb",
42+
"qdrant-client",
43+
"python-dotenv",
44+
"pinecone-client",
45+
"langchain",
46+
"langchain-community",
47+
"langchain-openai",
48+
"langchain-openai",
49+
"chromadb",
50+
"cohere",
51+
"qdrant_client",
52+
"weaviate-client",
53+
"ollama",
54+
"groq",
55+
"google-generativeai",
56+
"google-cloud-aiplatform",
57+
"mistralai",
6258
]
6359

60+
test = ["pytest", "pytest-vcr", "pytest-asyncio"]
6461

6562

6663
[project.urls]
@@ -71,9 +68,7 @@ Homepage = "https://github.com/Scale3-Labs/langtrace-python-sdk"
7168
path = "src/langtrace_python_sdk/version.py"
7269

7370
[tool.hatch.build.targets.sdist]
74-
include = [
75-
"/src",
76-
]
71+
include = ["/src"]
7772

7873
[tool.hatch.build.targets.wheel]
7974
packages = ["src/langtrace_python_sdk", "src/examples", "src/tests"]

src/examples/crewai_example/__init__.py

Whitespace-only changes.

src/examples/crewai_example/simple_agent/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from crewai import Agent
2+
from langchain_openai import ChatOpenAI
3+
from langchain_anthropic import ChatAnthropic
4+
from langchain_cohere import ChatCohere
5+
from langchain_ollama import ChatOllama
6+
7+
8+
class PoetryAgents:
9+
def __init__(self):
10+
self.open_ai = ChatOpenAI(
11+
model_name="gpt-4", temperature=0.7, stream_usage=True
12+
)
13+
self.anthropic = ChatAnthropic(
14+
model_name="claude-3-5-sonnet-20240620", temperature=0.7
15+
)
16+
17+
self.cohere = ChatCohere(model="command-r", temperature=0.7)
18+
self.ollama = ChatOllama(model="llama3", temperature=0.7)
19+
20+
def create_poet_agent(self):
21+
return Agent(
22+
role="Expert Poetry Writer",
23+
backstory="""
24+
I am an Expert in poetry writing and creative expression.
25+
I have been writing poetry for over 10 years and have published several collections.
26+
I have a deep understanding of various poetic forms, styles, and themes. I am here to help you create beautiful and meaningful poetry that resonates with your emotions and experiences.
27+
""",
28+
goal="""Create a poem that captures the essence of a given theme or emotion""",
29+
allow_delegation=False,
30+
verbose=True,
31+
llm=self.open_ai,
32+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from crewai import Crew
2+
from .agents import PoetryAgents
3+
from .tasks import PoetryTasks
4+
from langtrace_python_sdk import langtrace
5+
from dotenv import load_dotenv
6+
7+
load_dotenv()
8+
langtrace.init()
9+
10+
11+
class PoetryCrew:
12+
def __init__(self, topic) -> None:
13+
self.topic = topic
14+
15+
def run(self):
16+
agents = PoetryAgents()
17+
tasks = PoetryTasks()
18+
19+
poetry_agent = agents.create_poet_agent()
20+
21+
create_poem = tasks.create_poem(poetry_agent, self.topic)
22+
23+
crew = Crew(agents=[poetry_agent], tasks=[create_poem], verbose=True)
24+
res = crew.kickoff()
25+
return res
26+
27+
28+
# This is the main function that you will use to run your custom crew.
29+
# You can run this file using `python -m src.examples.crewai_example.simple_agent.main`
30+
if __name__ == "__main__":
31+
print("## Welcome to Poetry Crew")
32+
print("-------------------------------")
33+
poetry_crew = PoetryCrew(topic="cold")
34+
result = poetry_crew.run()
35+
print("\n\n########################")
36+
print("## Here is you poem")
37+
print("########################\n")
38+
print(result)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from crewai import Task
2+
from textwrap import dedent
3+
4+
5+
class PoetryTasks:
6+
def create_poem(self, agent, topic):
7+
return Task(
8+
description=dedent(
9+
f"""
10+
**Task**: Create a Poem on {topic}
11+
**Description**: Write a poem on the given topic that captures the essence of the theme or emotion.
12+
The poem should be creative, expressive, and resonate with the reader's emotions and experiences.
13+
Your poem should be well-structured, engaging, and evoke a sense of beauty and meaning.
14+
15+
**Parameters**:
16+
- Topic: {topic}
17+
"""
18+
),
19+
expected_output="A creative and expressive poem that captures the essence of the given topic.",
20+
agent=agent,
21+
output_file="poem.txt",
22+
)

src/examples/crewai_example/trip_planner/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from crewai import Agent
2+
from langchain_openai import ChatOpenAI
3+
from langchain_ollama import ChatOllama
4+
from langchain_cohere import ChatCohere
5+
from langchain_anthropic import ChatAnthropic
6+
from dotenv import load_dotenv
7+
8+
load_dotenv()
9+
10+
11+
class TravelAgents:
12+
def __init__(self):
13+
self.OpenAIGPT35 = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.7)
14+
self.OpenAIGPT4 = ChatOpenAI(model_name="gpt-4", temperature=0.7)
15+
self.Ollama = ChatOllama(model="llama3")
16+
self.Cohere = ChatCohere(model="command-r")
17+
self.Anthropic = ChatAnthropic(model="claude-3-5-sonnet-20240620")
18+
19+
def expert_travel_agent(self):
20+
return Agent(
21+
role="Expert Travel Agent",
22+
backstory="""
23+
I am an Expert in travel planning and itinerary creation.
24+
I have been in the travel industry for over 10 years and have helped thousands of clients plan their dream vacations.
25+
I have extensive knowledge of popular travel destinations, local attractions, and travel logistics. I am here to help you create a personalized travel itinerary that suits your preferences and budget.
26+
""",
27+
goal="""Create a 7 day travel itinerary with detailed per-day plans, include budget, packing suggestions, and local/safety tips.""",
28+
# tools=[tool_1, tool_2],
29+
allow_delegation=False,
30+
verbose=True,
31+
llm=self.Cohere,
32+
)
33+
34+
def city_selection_expert(self):
35+
return Agent(
36+
role="City Selection Expert",
37+
backstory="""Expert at analyzing and selecting the best cities for travel based on data""",
38+
goal="""Select the best cities based on weather, season, prices and traveler preferences""",
39+
# tools=[tool_1, tool_2],
40+
allow_delegation=False,
41+
verbose=True,
42+
llm=self.Cohere,
43+
)
44+
45+
def local_tour_guide(self):
46+
return Agent(
47+
role="Local Expert at this city",
48+
goal="Provide the BEST insights about the selected city",
49+
backstory="""A knowledgeable local guide with extensive information about the city, it's attractions and customs""",
50+
# tools=[tool_1, tool_2],
51+
allow_delegation=False,
52+
verbose=True,
53+
llm=self.Cohere,
54+
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from crewai import Crew
2+
from .agents import TravelAgents
3+
from .tasks import TravelTasks
4+
from langtrace_python_sdk import langtrace
5+
from dotenv import load_dotenv
6+
7+
load_dotenv()
8+
9+
langtrace.init()
10+
11+
12+
class TripCrew:
13+
def __init__(self, origin, cities, date_range, interests):
14+
self.origin = origin
15+
self.cities = cities
16+
self.date_range = date_range
17+
self.interests = interests
18+
19+
def run(self):
20+
# Define your custom agents and tasks in agents.py and tasks.py
21+
agents = TravelAgents()
22+
tasks = TravelTasks()
23+
24+
# Define your custom agents and tasks here
25+
expert_travel_agent = agents.expert_travel_agent()
26+
city_selection_expert = agents.city_selection_expert()
27+
local_tour_guide = agents.local_tour_guide()
28+
29+
# Custom tasks include agent name and variables as input
30+
plan_itinerary = tasks.plan_itinerary(
31+
expert_travel_agent, self.cities, self.date_range, self.interests
32+
)
33+
34+
identify_city = tasks.identify_city(
35+
city_selection_expert,
36+
self.origin,
37+
self.cities,
38+
self.interests,
39+
self.date_range,
40+
)
41+
42+
gather_city_info = tasks.gather_city_info(
43+
local_tour_guide, self.cities, self.date_range, self.interests
44+
)
45+
46+
# Define your custom crew here
47+
crew = Crew(
48+
agents=[expert_travel_agent, city_selection_expert, local_tour_guide],
49+
tasks=[plan_itinerary, identify_city, gather_city_info],
50+
verbose=True,
51+
)
52+
53+
result = crew.kickoff()
54+
return result
55+
56+
57+
# This is the main function that you will use to run your custom crew.
58+
if __name__ == "__main__":
59+
print("## Welcome to Trip Planner Crew")
60+
print("-------------------------------")
61+
62+
trip_crew = TripCrew("cairo", "marsa alam", "sep", "scuba diving")
63+
result = trip_crew.run()
64+
print("\n\n########################")
65+
print("## Here is you Trip Plan")
66+
print("########################\n")
67+
print(result)

0 commit comments

Comments
 (0)