aitracer 0.1.0__tar.gz

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.
@@ -0,0 +1,222 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ # Python lib directories (but not frontend/src/lib)
18
+ /lib/
19
+ /backend/lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py.cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+ cover/
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # UV
100
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ #uv.lock
104
+
105
+ # poetry
106
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
107
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
108
+ # commonly ignored for libraries.
109
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
110
+ #poetry.lock
111
+ #poetry.toml
112
+
113
+ # pdm
114
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
115
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
116
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
117
+ #pdm.lock
118
+ #pdm.toml
119
+ .pdm-python
120
+ .pdm-build/
121
+
122
+ # pixi
123
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
124
+ #pixi.lock
125
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
126
+ # in the .venv directory. It is recommended not to include this directory in version control.
127
+ .pixi
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule
134
+ celerybeat.pid
135
+
136
+ # SageMath parsed files
137
+ *.sage.py
138
+
139
+ # Environments
140
+ .env
141
+ .envrc
142
+ .venv
143
+ env/
144
+ venv/
145
+ ENV/
146
+ env.bak/
147
+ venv.bak/
148
+
149
+ # Spyder project settings
150
+ .spyderproject
151
+ .spyproject
152
+
153
+ # Rope project settings
154
+ .ropeproject
155
+
156
+ # mkdocs documentation
157
+ /site
158
+
159
+ # mypy
160
+ .mypy_cache/
161
+ .dmypy.json
162
+ dmypy.json
163
+
164
+ # Pyre type checker
165
+ .pyre/
166
+
167
+ # pytype static type analyzer
168
+ .pytype/
169
+
170
+ # Cython debug symbols
171
+ cython_debug/
172
+
173
+ # PyCharm
174
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
175
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
176
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
177
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
178
+ #.idea/
179
+
180
+ # Abstra
181
+ # Abstra is an AI-powered process automation framework.
182
+ # Ignore directories containing user credentials, local state, and settings.
183
+ # Learn more at https://abstra.io/docs
184
+ .abstra/
185
+
186
+ # Visual Studio Code
187
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
188
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
189
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
190
+ # you could uncomment the following to ignore the entire vscode folder
191
+ # .vscode/
192
+
193
+ # Ruff stuff:
194
+ .ruff_cache/
195
+
196
+ # PyPI configuration file
197
+ .pypirc
198
+
199
+ # Cursor
200
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
201
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
202
+ # refer to https://docs.cursor.com/context/ignore-files
203
+ .cursorignore
204
+ .cursorindexingignore
205
+
206
+ # Marimo
207
+ marimo/_static/
208
+ marimo/_lsp/
209
+ __marimo__/
210
+ .claude/settings.local.json
211
+
212
+ # Node.js
213
+ node_modules/
214
+ .next/
215
+ out/
216
+ npm-debug.log*
217
+
218
+ # Docker
219
+ .env.local
220
+
221
+ # SSL certificates
222
+ nginx/ssl/
@@ -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,203 @@
1
+ # AITracer Python SDK
2
+
3
+ AIエージェント/LLMアプリの実行ログ・コスト・パフォーマンスを監視するためのPython SDK。
4
+
5
+ ## インストール
6
+
7
+ ```bash
8
+ pip install aitracer
9
+ ```
10
+
11
+ ## クイックスタート
12
+
13
+ ### 基本的な使い方
14
+
15
+ ```python
16
+ from aitracer import AITracer
17
+ from openai import OpenAI
18
+
19
+ # AITracerを初期化
20
+ tracer = AITracer(
21
+ api_key="at-xxxxxxxx",
22
+ project="my-chatbot"
23
+ )
24
+
25
+ # OpenAIクライアントをラップ
26
+ client = tracer.wrap_openai(OpenAI())
27
+
28
+ # 普通に使う(自動でログが送信される)
29
+ response = client.chat.completions.create(
30
+ model="gpt-4o",
31
+ messages=[{"role": "user", "content": "Hello!"}]
32
+ )
33
+ ```
34
+
35
+ ### Anthropic対応
36
+
37
+ ```python
38
+ from aitracer import AITracer
39
+ from anthropic import Anthropic
40
+
41
+ tracer = AITracer(
42
+ api_key="at-xxxxxxxx",
43
+ project="my-chatbot"
44
+ )
45
+
46
+ # Anthropicクライアントをラップ
47
+ client = tracer.wrap_anthropic(Anthropic())
48
+
49
+ response = client.messages.create(
50
+ model="claude-3-5-sonnet-20241022",
51
+ max_tokens=1024,
52
+ messages=[{"role": "user", "content": "Hello!"}]
53
+ )
54
+ ```
55
+
56
+ ### Google Gemini対応
57
+
58
+ ```python
59
+ from aitracer import AITracer
60
+ import google.generativeai as genai
61
+
62
+ tracer = AITracer(
63
+ api_key="at-xxxxxxxx",
64
+ project="my-chatbot"
65
+ )
66
+
67
+ # Geminiを設定
68
+ genai.configure(api_key="your-google-api-key")
69
+ model = genai.GenerativeModel("gemini-1.5-flash")
70
+
71
+ # Geminiモデルをラップ
72
+ model = tracer.wrap_gemini(model)
73
+
74
+ response = model.generate_content("Hello!")
75
+ print(response.text)
76
+ ```
77
+
78
+ ストリーミングも対応しています:
79
+
80
+ ```python
81
+ response = model.generate_content("Write a story...", stream=True)
82
+ for chunk in response:
83
+ print(chunk.text, end="")
84
+ ```
85
+
86
+ ### トレース機能
87
+
88
+ 複数のAPI呼び出しをグループ化して追跡できます。
89
+
90
+ ```python
91
+ with tracer.trace("user-query-123") as trace:
92
+ # この中のAPI呼び出しは同じtrace_idでグループ化される
93
+ response1 = client.chat.completions.create(
94
+ model="gpt-4o",
95
+ messages=[{"role": "user", "content": "Summarize this..."}]
96
+ )
97
+
98
+ response2 = client.chat.completions.create(
99
+ model="gpt-4o",
100
+ messages=[{"role": "user", "content": "Translate to Japanese..."}]
101
+ )
102
+
103
+ # メタデータを追加
104
+ trace.set_metadata({
105
+ "user_id": "user-456",
106
+ "feature": "summarization"
107
+ })
108
+
109
+ # タグを追加
110
+ trace.add_tag("production")
111
+ ```
112
+
113
+ ### ストリーミング対応
114
+
115
+ ストリーミングレスポンスも自動的にログされます。
116
+
117
+ ```python
118
+ stream = client.chat.completions.create(
119
+ model="gpt-4o",
120
+ messages=[{"role": "user", "content": "Write a story..."}],
121
+ stream=True
122
+ )
123
+
124
+ for chunk in stream:
125
+ print(chunk.choices[0].delta.content or "", end="")
126
+
127
+ # ストリーム完了後に自動的にログが送信される
128
+ ```
129
+
130
+ ## 設定オプション
131
+
132
+ ```python
133
+ tracer = AITracer(
134
+ # 必須
135
+ api_key="at-xxxxxxxx", # または AITRACER_API_KEY 環境変数
136
+ project="my-chatbot", # または AITRACER_PROJECT 環境変数
137
+
138
+ # オプション
139
+ base_url="https://api.aitracer.co", # APIエンドポイント
140
+ sync=False, # True: 同期送信(Lambda用)
141
+ flush_on_exit=True, # 終了時に未送信ログをフラッシュ
142
+ batch_size=10, # バッチサイズ
143
+ flush_interval=5.0, # 自動フラッシュ間隔(秒)
144
+ enabled=True, # False: ログ無効化(テスト用)
145
+ )
146
+ ```
147
+
148
+ ### Lambda/サーバーレス環境
149
+
150
+ サーバーレス環境では `sync=True` を使用してください。
151
+
152
+ ```python
153
+ tracer = AITracer(
154
+ api_key="at-xxxxxxxx",
155
+ project="my-lambda",
156
+ sync=True # 同期送信
157
+ )
158
+ ```
159
+
160
+ ### 環境変数
161
+
162
+ ```bash
163
+ export AITRACER_API_KEY=at-xxxxxxxx
164
+ export AITRACER_PROJECT=my-chatbot
165
+ ```
166
+
167
+ ```python
168
+ # 環境変数から自動で読み込み
169
+ tracer = AITracer()
170
+ ```
171
+
172
+ ## 手動ログ
173
+
174
+ 自動ラッパーを使わずに手動でログを送信することもできます。
175
+
176
+ ```python
177
+ tracer.log(
178
+ model="gpt-4o",
179
+ provider="openai",
180
+ input_data={"messages": [{"role": "user", "content": "Hello"}]},
181
+ output_data={"content": "Hi there!"},
182
+ input_tokens=10,
183
+ output_tokens=5,
184
+ latency_ms=150,
185
+ status="success",
186
+ metadata={"user_id": "user-123"},
187
+ tags=["production"]
188
+ )
189
+ ```
190
+
191
+ ## フラッシュとシャットダウン
192
+
193
+ ```python
194
+ # 未送信のログを即座に送信
195
+ tracer.flush()
196
+
197
+ # シャットダウン(フラッシュ + リソース解放)
198
+ tracer.shutdown()
199
+ ```
200
+
201
+ ## ライセンス
202
+
203
+ Copyright (c) 株式会社HARO. All rights reserved.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AITracer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.