Skip to content

Commit 0d6f5ee

Browse files
Release (#314)
* remove logs * remove requirements * Bump version * Squash * CrewAI enhancements and embedchain support (#313) * Minor fixes * example update * remove stream_usage * Add embed chain support * update README * fix * update version and deps --------- Co-authored-by: Ali Waleed <[email protected]> --------- Co-authored-by: Ali Waleed <[email protected]>
1 parent e011881 commit 0d6f5ee

File tree

15 files changed

+247
-11
lines changed

15 files changed

+247
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Langtrace automatically captures traces from the following vendors:
255255
| Ollama | Framework | :x: | :white_check_mark: |
256256
| VertexAI | Framework | :x: | :white_check_mark: |
257257
| Vercel AI SDK| Framework | :white_check_mark: | :x: |
258+
| EmbedChain | Framework | :x: | :white_check_mark: |
258259
| Pinecone | Vector Database | :white_check_mark: | :white_check_mark: |
259260
| ChromaDB | Vector Database | :white_check_mark: | :white_check_mark: |
260261
| QDrant | Vector Database | :white_check_mark: | :white_check_mark: |

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dev = [
5555
"google-generativeai",
5656
"google-cloud-aiplatform",
5757
"mistralai",
58+
"embedchain",
5859
]
5960

6061
test = ["pytest", "pytest-vcr", "pytest-asyncio"]

src/examples/crewai_example/simple_agent/agents.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from crewai import Agent
2-
from langchain_openai import ChatOpenAI
32
from langchain_anthropic import ChatAnthropic
43
from langchain_cohere import ChatCohere
54
from langchain_ollama import ChatOllama
5+
from langchain_openai import ChatOpenAI
66

77

88
class PoetryAgents:
99
def __init__(self):
10-
self.open_ai = ChatOpenAI(
11-
model_name="gpt-4", temperature=0.7, stream_usage=True
12-
)
10+
self.open_ai = ChatOpenAI(model_name="gpt-4", temperature=0.7)
1311
self.anthropic = ChatAnthropic(
1412
model_name="claude-3-5-sonnet-20240620", temperature=0.7
1513
)
@@ -30,3 +28,28 @@ def create_poet_agent(self):
3028
verbose=True,
3129
llm=self.open_ai,
3230
)
31+
32+
def poet_agent_2(self):
33+
return Agent(
34+
role="Renaissance Poet",
35+
backstory="""
36+
I am a Renaissance Poet. I am well-versed in the art of poetry and have a deep appreciation for the beauty of language and expression.
37+
""",
38+
goal="""Create a poem that is inspired by the works of the Renaissance poets""",
39+
allow_delegation=False,
40+
verbose=True,
41+
llm=self.open_ai,
42+
)
43+
44+
def poet_agent_3(self):
45+
return Agent(
46+
role="William Shakespeare",
47+
backstory="""
48+
I am william shakespeare. I am an Expert in poetry writing and creative expression.
49+
I have been writing poetry for over 10 years and have published several collections.
50+
""",
51+
goal="""Create a poem that is inspired by the works of William Shakespeare""",
52+
allow_delegation=False,
53+
verbose=True,
54+
llm=self.open_ai,
55+
)

src/examples/crewai_example/simple_agent/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from agents import PoetryAgents
12
from crewai import Crew
2-
from .agents import PoetryAgents
3-
from .tasks import PoetryTasks
4-
from langtrace_python_sdk import langtrace
53
from dotenv import load_dotenv
4+
from tasks import PoetryTasks
5+
6+
from langtrace_python_sdk import langtrace
67

78
load_dotenv()
89
langtrace.init()
@@ -17,10 +18,14 @@ def run(self):
1718
tasks = PoetryTasks()
1819

1920
poetry_agent = agents.create_poet_agent()
21+
poetry_agent_2 = agents.poet_agent_2()
22+
poetry_agent_3 = agents.poet_agent_3()
2023

2124
create_poem = tasks.create_poem(poetry_agent, self.topic)
25+
create_poem_2 = tasks.create_poem(poetry_agent_2, self.topic)
26+
create_poem_3 = tasks.create_poem(poetry_agent_3, self.topic)
2227

23-
crew = Crew(agents=[poetry_agent], tasks=[create_poem], verbose=True)
28+
crew = Crew(agents=[poetry_agent], tasks=[create_poem], verbose=True, memory=True)
2429
res = crew.kickoff()
2530
return res
2631

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from dotenv import load_dotenv
2+
from embedchain import App
3+
from langtrace_python_sdk import langtrace
4+
5+
load_dotenv()
6+
langtrace.init()
7+
8+
app = App()
9+
app.reset()
10+
app.add("https://www.forbes.com/profile/elon-musk")
11+
app.add("https://en.wikipedia.org/wiki/Elon_Musk")
12+
res = app.query("What is the net worth of Elon Musk today?")
13+
print(res)
14+
re2 = app.search("Elon Musk")
15+
print(re2)

src/langtrace_python_sdk/constants/instrumentation/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"VERTEXAI": "VertexAI",
3131
"GEMINI": "Gemini",
3232
"MISTRAL": "Mistral",
33+
"EMBEDCHAIN": "Embedchain",
3334
}
3435

3536
LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY = "langtrace_additional_attributes"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
APIS = {
2+
"ADD": {
3+
"METHOD": "embedchain.add",
4+
"OPERATION": "add",
5+
},
6+
"QUERY": {
7+
"METHOD": "embedchain.query",
8+
"OPERATION": "query",
9+
},
10+
"SEARCH": {
11+
"METHOD": "embedchain.search",
12+
"OPERATION": "search",
13+
},
14+
}

src/langtrace_python_sdk/instrumentation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
from .vertexai import VertexAIInstrumentation
1818
from .gemini import GeminiInstrumentation
1919
from .mistral import MistralInstrumentation
20+
from .embedchain import EmbedchainInstrumentation
2021

2122
__all__ = [
2223
"AnthropicInstrumentation",
2324
"ChromaInstrumentation",
2425
"CohereInstrumentation",
2526
"CrewAIInstrumentation",
27+
"EmbedchainInstrumentation",
2628
"GroqInstrumentation",
2729
"LangchainInstrumentation",
2830
"LangchainCommunityInstrumentation",

src/langtrace_python_sdk/instrumentation/chroma/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def traced_method(wrapped, instance, args, kwargs):
5151
"langtrace.version": v(LANGTRACE_SDK_NAME),
5252
"db.system": "chromadb",
5353
"db.operation": api["OPERATION"],
54-
"db.query": json.dumps(kwargs.get("query")),
54+
"db.query": json.dumps(kwargs),
5555
**(extra_attributes if extra_attributes is not None else {}),
5656
}
5757

src/langtrace_python_sdk/instrumentation/crewai/patch.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,23 @@ def traced_method(wrapped, instance, args, kwargs):
114114
result = wrapped(*args, **kwargs)
115115
if result:
116116
span.set_status(Status(StatusCode.OK))
117+
if instance.__class__.__name__ == "Crew":
118+
span.set_attribute("crewai.crew.result", str(result))
119+
if hasattr(result, "tasks_output"):
120+
span.set_attribute("crewai.crew.tasks_output", str((result.tasks_output)))
121+
if hasattr(result, "token_usage"):
122+
span.set_attribute("crewai.crew.token_usage", str((result.token_usage)))
123+
if hasattr(result, "usage_metrics"):
124+
span.set_attribute("crewai.crew.usage_metrics", str((result.usage_metrics)))
125+
elif instance.__class__.__name__ == "Agent":
126+
span.set_attribute("crewai.agent.result", str(result))
127+
elif instance.__class__.__name__ == "Task":
128+
span.set_attribute("crewai.task.result", str(result))
117129

118130
span.end()
119131
return result
120132

121133
except Exception as err:
122-
print("Error", err)
123134
# Record the exception in the span
124135
span.record_exception(err)
125136

0 commit comments

Comments
 (0)