Skip to content

Commit 4aa92c9

Browse files
committed
Merge branch 'development' of github.com:Scale3-Labs/langtrace-python-sdk into ali/s3en-2136-instrument-litellm
2 parents 31628a7 + d231f90 commit 4aa92c9

File tree

58 files changed

+1437
-463
lines changed

Some content is hidden

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

58 files changed

+1437
-463
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"attachments": [
3+
{
4+
"pretext": "{{ env.PRE_TEXT_MESSAGE }}",
5+
"fallback": "{{ env.FALLBACK_MESSAGE }}",
6+
"color": "{{ env.COLOR }}",
7+
"author_name": "{{ github.workflow }}",
8+
"author_link": "{{ env.GITHUB_SERVER_URL }}/{{ env.GITHUB_REPOSITORY }}/actions/runs/{{ env.GITHUB_RUN_ID }}",
9+
"title": "{{ env.GITHUB_REPOSITORY }}",
10+
"title_link": "{{ env.GITHUB_SERVER_URL }}/{{ env.GITHUB_REPOSITORY }}",
11+
"fields": [
12+
{
13+
"title": "Release Tag",
14+
"short": true,
15+
"value": "{{ env.RELEASETAG }}"
16+
}
17+
],
18+
"footer": "deployed by: {{ github.actor }}",
19+
"footer_icon": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
20+
}
21+
]
22+
}

.github/workflows/release.yml

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ jobs:
2121
- name: Set up Python
2222
uses: actions/setup-python@v2
2323
with:
24-
python-version: '3.x'
24+
python-version: "3.x"
2525

2626
- name: Install hatch
27-
run: |
27+
run: |
2828
pip install hatch
29-
29+
3030
- name: Get Version
3131
id: version
32-
run: |
32+
run: |
3333
echo "version=$(hatch version)" >> $GITHUB_OUTPUT
34-
34+
3535
publish:
3636
runs-on: ubuntu-latest
3737
needs:
@@ -54,17 +54,58 @@ jobs:
5454
- name: Set up Python
5555
uses: actions/setup-python@v2
5656
with:
57-
python-version: '3.x'
57+
python-version: "3.x"
5858

5959
- name: Install hatch
60-
run: |
60+
run: |
6161
pip install hatch
6262
6363
- name: Build SDK
64-
run: |
64+
run: |
6565
hatch build
6666
6767
- name: Publish Python 🐍 distributions 📦 to PyPI
6868
uses: pypa/gh-action-pypi-publish@master
6969
with:
7070
password: ${{ secrets.PYPI_TOKEN }}
71+
72+
post-release:
73+
name: Post Release Actions
74+
75+
runs-on: ubuntu-latest
76+
if: ${{ always() }}
77+
needs:
78+
- generate-version
79+
- publish
80+
81+
steps:
82+
- name: Checkout main branch
83+
uses: actions/[email protected]
84+
with:
85+
ref: main
86+
87+
- name: Slack - Success Message
88+
uses: DSdatsme/slack-github-action@env_support
89+
if: ${{ success() && needs.publish.result == 'success' }}
90+
with:
91+
channel-id: ${{ vars.SLACK_CHANNEL_ID }}
92+
payload-file-path: ./.github/resources/slack-payloads/slack-message-template.json
93+
env:
94+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
95+
RELEASETAG: ${{ needs.generate-version.outputs.new_version }}
96+
PRE_TEXT_MESSAGE: "Workflow Passed! :successkid:"
97+
FALLBACK_MESSAGE: "Workflow Passed!"
98+
COLOR: "good"
99+
100+
- name: Slack - Failure Message
101+
uses: DSdatsme/slack-github-action@env_support
102+
if: ${{ failure() || needs.publish.result != 'success' }}
103+
with:
104+
channel-id: ${{ vars.SLACK_CHANNEL_ID }}
105+
payload-file-path: ./.github/resources/slack-payloads/slack-message-template.json
106+
env:
107+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
108+
RELEASETAG: ${{ needs.generate-version.outputs.new_version }}
109+
PRE_TEXT_MESSAGE: "<!channel> Workflow Failed! :x:"
110+
FALLBACK_MESSAGE: "Workflow Failed!"
111+
COLOR: "danger"

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def main():
194194
from langtrace_python_sdk import with_langtrace_root_span, with_additional_attributes
195195

196196

197-
@with_additional_attributes({"user.id": "1234", "user.feedback.rating": 1})
197+
@with_additional_attributes({"user.id": "1234"})
198198
def api_call1():
199199
response = client.chat.completions.create(
200200
model="gpt-4",
@@ -204,7 +204,7 @@ def api_call1():
204204
return response
205205

206206

207-
@with_additional_attributes({"user.id": "5678", "user.feedback.rating": -1})
207+
@with_additional_attributes({"user.id": "5678"})
208208
def api_call2():
209209
response = client.chat.completions.create(
210210
model="gpt-4",
@@ -228,6 +228,11 @@ from langtrace_python_sdk import get_prompt_from_registry
228228
prompt = get_prompt_from_registry(<Registry ID>, options={"prompt_version": 1, "variables": {"foo": "bar"} })
229229
```
230230

231+
### Opt out of tracing prompt and completion data
232+
By default, prompt and completion data are captured. If you would like to opt out of it, set the following env var,
233+
234+
`TRACE_PROMPT_COMPLETION_DATA=false`
235+
231236
## Supported integrations
232237

233238
Langtrace automatically captures traces from the following vendors:
@@ -248,6 +253,7 @@ Langtrace automatically captures traces from the following vendors:
248253
| CrewAI | Framework | :x: | :white_check_mark: |
249254
| Ollama | Framework | :x: | :white_check_mark: |
250255
| VertexAI | Framework | :x: | :white_check_mark: |
256+
| Vercel AI SDK| Framework | :white_check_mark: | :x: |
251257
| Pinecone | Vector Database | :white_check_mark: | :white_check_mark: |
252258
| ChromaDB | Vector Database | :white_check_mark: | :white_check_mark: |
253259
| QDrant | Vector Database | :white_check_mark: | :white_check_mark: |

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ classifiers=[
1818
"Operating System :: OS Independent",
1919
]
2020
dependencies = [
21-
'trace-attributes>=6.0.0,<7.0.0',
21+
'trace-attributes==7.0.1',
2222
'opentelemetry-api>=1.25.0',
2323
'opentelemetry-sdk>=1.25.0',
24-
'opentelemetry-instrumentation>=0.46b0',
24+
'opentelemetry-instrumentation>=0.47b0',
2525
'opentelemetry-instrumentation-sqlalchemy>=0.46b0',
2626
'opentelemetry-exporter-otlp-proto-http>=1.25.0',
2727
'opentelemetry-exporter-otlp-proto-grpc>=1.25.0',

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.ollama,
32+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from crewai import Crew
2+
from textwrap import dedent
3+
from .agents import PoetryAgents
4+
from .tasks import PoetryTasks
5+
from langtrace_python_sdk import langtrace
6+
from dotenv import load_dotenv
7+
import agentops
8+
9+
load_dotenv()
10+
agentops.init()
11+
langtrace.init(write_spans_to_console=False, batch=False)
12+
13+
14+
class PoetryCrew:
15+
def __init__(self, topic) -> None:
16+
self.topic = topic
17+
18+
def run(self):
19+
agents = PoetryAgents()
20+
tasks = PoetryTasks()
21+
22+
poetry_agent = agents.create_poet_agent()
23+
24+
create_poem = tasks.create_poem(poetry_agent, self.topic)
25+
26+
crew = Crew(agents=[poetry_agent], tasks=[create_poem], verbose=True)
27+
res = crew.kickoff()
28+
return res
29+
30+
31+
# This is the main function that you will use to run your custom crew.
32+
if __name__ == "__main__":
33+
print("## Welcome to Poetry Crew")
34+
print("-------------------------------")
35+
topic = input(
36+
dedent(
37+
"""
38+
What topic do you want to write a poem on?
39+
"""
40+
)
41+
)
42+
43+
poetry_crew = PoetryCrew(topic=topic)
44+
result = poetry_crew.run()
45+
print("\n\n########################")
46+
print("## Here is you poem")
47+
print("########################\n")
48+
print(result)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
)

src/examples/crewai_example/trip_planner/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)