aitracer 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aitracer-0.1.0.dist-info/METADATA +234 -0
- aitracer-0.1.0.dist-info/RECORD +15 -0
- aitracer-0.1.0.dist-info/WHEEL +4 -0
- python/__init__.py +30 -0
- python/client.py +437 -0
- python/integrations/__init__.py +5 -0
- python/integrations/langchain.py +452 -0
- python/pii.py +223 -0
- python/queue.py +219 -0
- python/session.py +144 -0
- python/trace.py +65 -0
- python/wrappers/__init__.py +7 -0
- python/wrappers/anthropic_wrapper.py +208 -0
- python/wrappers/gemini_wrapper.py +350 -0
- python/wrappers/openai_wrapper.py +193 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aitracer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AITracer SDK - Monitor your AI/LLM applications
|
|
5
|
+
Project-URL: Homepage, https://aitracer.co
|
|
6
|
+
Project-URL: Documentation, https://docs.aitracer.co
|
|
7
|
+
Project-URL: Repository, https://github.com/haro-inc/aitracer
|
|
8
|
+
Author-email: "HARO Inc." <info@haro.co.jp>
|
|
9
|
+
License: Proprietary
|
|
10
|
+
Keywords: ai,anthropic,llm,monitoring,observability,openai
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: Other/Proprietary License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Requires-Dist: anthropic>=0.18.0
|
|
22
|
+
Requires-Dist: httpx>=0.25.0
|
|
23
|
+
Requires-Dist: openai>=1.0.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# AITracer Python SDK
|
|
33
|
+
|
|
34
|
+
AIエージェント/LLMアプリの実行ログ・コスト・パフォーマンスを監視するためのPython SDK。
|
|
35
|
+
|
|
36
|
+
## インストール
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install aitracer
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## クイックスタート
|
|
43
|
+
|
|
44
|
+
### 基本的な使い方
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from aitracer import AITracer
|
|
48
|
+
from openai import OpenAI
|
|
49
|
+
|
|
50
|
+
# AITracerを初期化
|
|
51
|
+
tracer = AITracer(
|
|
52
|
+
api_key="at-xxxxxxxx",
|
|
53
|
+
project="my-chatbot"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# OpenAIクライアントをラップ
|
|
57
|
+
client = tracer.wrap_openai(OpenAI())
|
|
58
|
+
|
|
59
|
+
# 普通に使う(自動でログが送信される)
|
|
60
|
+
response = client.chat.completions.create(
|
|
61
|
+
model="gpt-4o",
|
|
62
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Anthropic対応
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from aitracer import AITracer
|
|
70
|
+
from anthropic import Anthropic
|
|
71
|
+
|
|
72
|
+
tracer = AITracer(
|
|
73
|
+
api_key="at-xxxxxxxx",
|
|
74
|
+
project="my-chatbot"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Anthropicクライアントをラップ
|
|
78
|
+
client = tracer.wrap_anthropic(Anthropic())
|
|
79
|
+
|
|
80
|
+
response = client.messages.create(
|
|
81
|
+
model="claude-3-5-sonnet-20241022",
|
|
82
|
+
max_tokens=1024,
|
|
83
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Google Gemini対応
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from aitracer import AITracer
|
|
91
|
+
import google.generativeai as genai
|
|
92
|
+
|
|
93
|
+
tracer = AITracer(
|
|
94
|
+
api_key="at-xxxxxxxx",
|
|
95
|
+
project="my-chatbot"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# Geminiを設定
|
|
99
|
+
genai.configure(api_key="your-google-api-key")
|
|
100
|
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
|
101
|
+
|
|
102
|
+
# Geminiモデルをラップ
|
|
103
|
+
model = tracer.wrap_gemini(model)
|
|
104
|
+
|
|
105
|
+
response = model.generate_content("Hello!")
|
|
106
|
+
print(response.text)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
ストリーミングも対応しています:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
response = model.generate_content("Write a story...", stream=True)
|
|
113
|
+
for chunk in response:
|
|
114
|
+
print(chunk.text, end="")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### トレース機能
|
|
118
|
+
|
|
119
|
+
複数のAPI呼び出しをグループ化して追跡できます。
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
with tracer.trace("user-query-123") as trace:
|
|
123
|
+
# この中のAPI呼び出しは同じtrace_idでグループ化される
|
|
124
|
+
response1 = client.chat.completions.create(
|
|
125
|
+
model="gpt-4o",
|
|
126
|
+
messages=[{"role": "user", "content": "Summarize this..."}]
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
response2 = client.chat.completions.create(
|
|
130
|
+
model="gpt-4o",
|
|
131
|
+
messages=[{"role": "user", "content": "Translate to Japanese..."}]
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# メタデータを追加
|
|
135
|
+
trace.set_metadata({
|
|
136
|
+
"user_id": "user-456",
|
|
137
|
+
"feature": "summarization"
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
# タグを追加
|
|
141
|
+
trace.add_tag("production")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### ストリーミング対応
|
|
145
|
+
|
|
146
|
+
ストリーミングレスポンスも自動的にログされます。
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
stream = client.chat.completions.create(
|
|
150
|
+
model="gpt-4o",
|
|
151
|
+
messages=[{"role": "user", "content": "Write a story..."}],
|
|
152
|
+
stream=True
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
for chunk in stream:
|
|
156
|
+
print(chunk.choices[0].delta.content or "", end="")
|
|
157
|
+
|
|
158
|
+
# ストリーム完了後に自動的にログが送信される
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 設定オプション
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
tracer = AITracer(
|
|
165
|
+
# 必須
|
|
166
|
+
api_key="at-xxxxxxxx", # または AITRACER_API_KEY 環境変数
|
|
167
|
+
project="my-chatbot", # または AITRACER_PROJECT 環境変数
|
|
168
|
+
|
|
169
|
+
# オプション
|
|
170
|
+
base_url="https://api.aitracer.co", # APIエンドポイント
|
|
171
|
+
sync=False, # True: 同期送信(Lambda用)
|
|
172
|
+
flush_on_exit=True, # 終了時に未送信ログをフラッシュ
|
|
173
|
+
batch_size=10, # バッチサイズ
|
|
174
|
+
flush_interval=5.0, # 自動フラッシュ間隔(秒)
|
|
175
|
+
enabled=True, # False: ログ無効化(テスト用)
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Lambda/サーバーレス環境
|
|
180
|
+
|
|
181
|
+
サーバーレス環境では `sync=True` を使用してください。
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
tracer = AITracer(
|
|
185
|
+
api_key="at-xxxxxxxx",
|
|
186
|
+
project="my-lambda",
|
|
187
|
+
sync=True # 同期送信
|
|
188
|
+
)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 環境変数
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
export AITRACER_API_KEY=at-xxxxxxxx
|
|
195
|
+
export AITRACER_PROJECT=my-chatbot
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
# 環境変数から自動で読み込み
|
|
200
|
+
tracer = AITracer()
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## 手動ログ
|
|
204
|
+
|
|
205
|
+
自動ラッパーを使わずに手動でログを送信することもできます。
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
tracer.log(
|
|
209
|
+
model="gpt-4o",
|
|
210
|
+
provider="openai",
|
|
211
|
+
input_data={"messages": [{"role": "user", "content": "Hello"}]},
|
|
212
|
+
output_data={"content": "Hi there!"},
|
|
213
|
+
input_tokens=10,
|
|
214
|
+
output_tokens=5,
|
|
215
|
+
latency_ms=150,
|
|
216
|
+
status="success",
|
|
217
|
+
metadata={"user_id": "user-123"},
|
|
218
|
+
tags=["production"]
|
|
219
|
+
)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## フラッシュとシャットダウン
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
# 未送信のログを即座に送信
|
|
226
|
+
tracer.flush()
|
|
227
|
+
|
|
228
|
+
# シャットダウン(フラッシュ + リソース解放)
|
|
229
|
+
tracer.shutdown()
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## ライセンス
|
|
233
|
+
|
|
234
|
+
Copyright (c) 株式会社HARO. All rights reserved.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
python/__init__.py,sha256=ufrrGDz44Nv6tCjZqAyvCpN3Sk843rDu5F7z_OmiELg,866
|
|
2
|
+
python/client.py,sha256=yvH6f_RpTo9Bl0VXubuvNxDHVE1i_KafVBjKQ0fFOtA,14432
|
|
3
|
+
python/pii.py,sha256=Tgbq1NwM5L0I03aESNQvzbWd8WYlF5JLcYOxd933vE0,7412
|
|
4
|
+
python/queue.py,sha256=jYZNFFdTbVNZNiPQ-CCZ7y-KiQ5QLs0zIQG6-23d43I,6756
|
|
5
|
+
python/session.py,sha256=UtKruvKNWQW7qcFTmWrwEXCA6CutNzh4g5n4oT9E5xg,4927
|
|
6
|
+
python/trace.py,sha256=D7cfeBQxOmkJl7W9VCrYL0MXLMLKOc4XVpIq7sL6p1M,1517
|
|
7
|
+
python/integrations/__init__.py,sha256=hrYDWS9PVUfRurkszRvna3_2DB2nKYABF9jX1X79-Vg,144
|
|
8
|
+
python/integrations/langchain.py,sha256=qJAlpZ6y-gBZ_xNwEls1eO4ikwCPmqwjZzB4PlnMjzE,14567
|
|
9
|
+
python/wrappers/__init__.py,sha256=j8pwozRAMY633wFz-sWQtIajZvnK_4updOxQnfwRm-8,305
|
|
10
|
+
python/wrappers/anthropic_wrapper.py,sha256=WVvmWU4eKc_Qjgj4_ImqBnGddV5MfVgMmOKvQjBkhB0,6561
|
|
11
|
+
python/wrappers/gemini_wrapper.py,sha256=GdIZ5FlGI6Wrdr5WXUgyd5l2rPlAYnBUc4nI-v1fb0c,10976
|
|
12
|
+
python/wrappers/openai_wrapper.py,sha256=sziE6ClwwEKxpgCP_FxAhuXXoia3H9wZkSNIt-EMZRc,5859
|
|
13
|
+
aitracer-0.1.0.dist-info/METADATA,sha256=vBNOOuRH_9ek5_fso_QV-ugjeecfwbliXBJ2wg9EUvU,5875
|
|
14
|
+
aitracer-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
15
|
+
aitracer-0.1.0.dist-info/RECORD,,
|
python/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AITracer SDK - Monitor your AI/LLM applications
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
from aitracer import AITracer
|
|
6
|
+
from openai import OpenAI
|
|
7
|
+
|
|
8
|
+
tracer = AITracer(api_key="at-xxxxxxxx", project="my-chatbot")
|
|
9
|
+
client = tracer.wrap_openai(OpenAI())
|
|
10
|
+
|
|
11
|
+
response = client.chat.completions.create(
|
|
12
|
+
model="gpt-4o",
|
|
13
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
LangChain Integration:
|
|
17
|
+
from aitracer.integrations.langchain import AITracerCallbackHandler
|
|
18
|
+
from langchain_openai import ChatOpenAI
|
|
19
|
+
|
|
20
|
+
handler = AITracerCallbackHandler(api_key="at-xxx", project="my-langchain-app")
|
|
21
|
+
llm = ChatOpenAI(callbacks=[handler])
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from aitracer.client import AITracer
|
|
25
|
+
from aitracer.pii import PIIDetector
|
|
26
|
+
from aitracer.session import Session
|
|
27
|
+
from aitracer.trace import Trace
|
|
28
|
+
|
|
29
|
+
__version__ = "0.1.0"
|
|
30
|
+
__all__ = ["AITracer", "Trace", "Session", "PIIDetector"]
|