osmosis-ai 0.1.8__py3-none-any.whl → 0.1.9__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.

Potentially problematic release.


This version of osmosis-ai might be problematic. Click here for more details.

osmosis_ai/logger.py DELETED
@@ -1,77 +0,0 @@
1
- """
2
- Logging utilities for Osmosis
3
- """
4
-
5
- import sys
6
- import logging
7
- import os
8
- from .consts import LogDestination, DEFAULT_LOG_DESTINATION
9
-
10
- # Create logger
11
- logger = logging.getLogger("osmosis_ai")
12
- logger.setLevel(logging.INFO)
13
-
14
- # Default configuration - no logging
15
- logger.propagate = False
16
-
17
- # Default log destination
18
- log_destination = DEFAULT_LOG_DESTINATION
19
- logger.log_destination = log_destination
20
-
21
-
22
- def set_log_destination(destination: LogDestination) -> None:
23
- """
24
- Set the log destination for the logger
25
- """
26
- global log_destination
27
- log_destination = destination
28
- logger.log_destination = destination
29
-
30
-
31
- def configure_logger() -> None:
32
- """
33
- Configure the logger based on the log_destination setting in consts.py
34
- """
35
- # Remove any existing handlers
36
- for handler in logger.handlers[:]:
37
- logger.removeHandler(handler)
38
-
39
- # Configure based on log_destination
40
- if log_destination == "none":
41
- # No logging
42
- return
43
- elif log_destination == "stdout":
44
- handler = logging.StreamHandler(sys.stdout)
45
- logger.addHandler(handler)
46
- elif log_destination == "stderr":
47
- handler = logging.StreamHandler(sys.stderr)
48
- logger.addHandler(handler)
49
- elif log_destination == "file":
50
- # Log to a file in the current directory
51
- log_file = os.environ.get("OSMOSIS_LOG_FILE", "osmosis_ai.log")
52
- handler = logging.FileHandler(log_file)
53
- logger.addHandler(handler)
54
- else:
55
- # Invalid setting, log to stderr as fallback
56
- handler = logging.StreamHandler(sys.stderr)
57
- logger.addHandler(handler)
58
- logger.warning(f"Invalid log_destination: {log_destination}, using stderr")
59
-
60
- # Set formatter
61
- formatter = logging.Formatter(
62
- "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
63
- )
64
- for handler in logger.handlers:
65
- handler.setFormatter(formatter)
66
-
67
-
68
- # Initialize the logger on module import
69
- configure_logger()
70
-
71
-
72
- # Function to force reconfiguration if log_destination is changed
73
- def reconfigure_logger() -> None:
74
- """
75
- Reconfigure the logger, should be called if log_destination changes
76
- """
77
- configure_logger()
@@ -1,281 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: osmosis-ai
3
- Version: 0.1.8
4
- Summary: Monkey patches LLM client libraries to print all prompts and responses
5
- Author-email: Gulp AI <jake@gulp.ai>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 Gulp AI
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
- Project-URL: Homepage, https://github.com/Gulp-AI/osmosis-sdk-python
28
- Project-URL: Issues, https://github.com/Gulp-AI/osmosis-sdk-python/issues
29
- Classifier: Programming Language :: Python :: 3
30
- Classifier: License :: OSI Approved :: MIT License
31
- Classifier: Operating System :: OS Independent
32
- Requires-Python: >=3.6
33
- Description-Content-Type: text/markdown
34
- License-File: LICENSE
35
- Requires-Dist: python-dotenv>=0.19.0
36
- Requires-Dist: requests>=2.25.0
37
- Requires-Dist: xxhash>=3.4.1
38
- Provides-Extra: anthropic
39
- Requires-Dist: anthropic>=0.5.0; extra == "anthropic"
40
- Provides-Extra: openai
41
- Requires-Dist: openai>=0.27.0; extra == "openai"
42
- Provides-Extra: langchain
43
- Requires-Dist: langchain>=0.0.200; extra == "langchain"
44
- Provides-Extra: langchain-openai
45
- Requires-Dist: langchain>=0.0.200; extra == "langchain-openai"
46
- Requires-Dist: langchain-openai>=0.0.200; extra == "langchain-openai"
47
- Requires-Dist: openai>=0.27.0; extra == "langchain-openai"
48
- Provides-Extra: langchain-anthropic
49
- Requires-Dist: langchain>=0.0.200; extra == "langchain-anthropic"
50
- Requires-Dist: langchain-anthropic>=0.0.200; extra == "langchain-anthropic"
51
- Requires-Dist: anthropic>=0.5.0; extra == "langchain-anthropic"
52
- Provides-Extra: all
53
- Requires-Dist: anthropic>=0.5.0; extra == "all"
54
- Requires-Dist: openai>=0.27.0; extra == "all"
55
- Requires-Dist: langchain>=0.0.200; extra == "all"
56
- Requires-Dist: langchain-openai>=0.0.200; extra == "all"
57
- Requires-Dist: langchain-anthropic>=0.0.200; extra == "all"
58
- Dynamic: license-file
59
-
60
- [![Run Tests](https://github.com/Gulp-AI/osmosis-sdk-python/actions/workflows/test.yml/badge.svg)](https://github.com/Gulp-AI/osmosis-sdk-python/actions/workflows/test.yml)
61
-
62
- # Osmosis
63
-
64
- A Python library that monkey patches LLM client libraries to send all prompts and responses to the Osmosis API for logging and monitoring.
65
-
66
- ## Supported Libraries
67
-
68
- - **Anthropic**: Logs all Claude API requests and responses (both sync and async clients)
69
- - **OpenAI**: Logs all OpenAI API requests and responses (supports v1 and v2 API versions, both sync and async clients)
70
- - **LangChain**: Currently supports prompt template logging (LLM and ChatModel support varies by LangChain version)
71
-
72
- ## Installation
73
-
74
- [pypi](https://pypi.org/project/osmosis-ai/)
75
-
76
- ```bash
77
- # Basic installation with minimal dependencies
78
- pip install osmosis-ai
79
-
80
- # Install with specific provider support
81
- pip install "osmosis-ai[openai]" # Only OpenAI support
82
- pip install "osmosis-ai[anthropic]" # Only Anthropic support
83
-
84
- # Install with LangChain support
85
- pip install "osmosis-ai[langchain]" # Base LangChain support
86
- pip install "osmosis-ai[langchain-openai]" # LangChain + OpenAI support
87
- pip install "osmosis-ai[langchain-anthropic]" # LangChain + Anthropic support
88
-
89
- # Install with all dependencies
90
- pip install "osmosis-ai[all]"
91
- ```
92
-
93
- Or install from source:
94
-
95
- ```bash
96
- git clone https://github.com/your-username/osmosis-sdk-python.git
97
- cd osmosis-ai
98
- pip install -e .
99
- ```
100
-
101
- For development, you can install all dependencies using:
102
-
103
- ```bash
104
- pip install -r requirements.txt
105
- ```
106
-
107
- ## Environment Setup
108
-
109
- osmosisrequires a OSMOSIS API key to log LLM usage. Create a `.env` file in your project directory:
110
-
111
- ```bash
112
- # Copy the sample .env file
113
- cp .env.sample .env
114
-
115
- # Edit the .env file with your API keys
116
- ```
117
-
118
- Edit the `.env` file to add your API keys:
119
-
120
- ```
121
- # Required for logging
122
- OSMOSIS_API_KEY=your_osmosis_api_key_here
123
-
124
- # Optional: Only needed if you're using these services
125
- ANTHROPIC_API_KEY=your_anthropic_key_here
126
- OPENAI_API_KEY=your_openai_key_here
127
- ```
128
-
129
- ## Usage
130
-
131
- First, import and initialize osmosiswith your OSMOSIS API key:
132
-
133
- ```python
134
- import os
135
- import osmosis_ai
136
-
137
- # Initialize with your OSMOSIS API key
138
- osmosis_ai.init("your-osmosis-api-key")
139
-
140
- # Or load from environment variable
141
- osmosis_api_key = os.environ.get("OSMOSIS_API_KEY")
142
- osmosis_ai.init(osmosis_api_key)
143
- ```
144
-
145
- Once you import `osmosis_ai` and initialize it, the library automatically patches the supported LLM clients. You can then use your LLM clients normally, and all API calls will be logged to OSMOSIS:
146
-
147
- ### Anthropic Example
148
-
149
- ```python
150
- # Import osmosis_ai first and initialize it
151
- import osmosis_ai
152
- osmosis_ai.init(os.environ.get("OSMOSIS_API_KEY"))
153
-
154
- # Then import and use Anthropic as normal
155
- from anthropic import Anthropic
156
-
157
- # Create and use the Anthropic client as usual - it's already patched
158
- client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
159
-
160
- # All API calls will now be logged to OSMOSIS automatically
161
- response = client.messages.create(
162
- model="claude-3-haiku-20240307",
163
- max_tokens=1000,
164
- messages=[
165
- {"role": "user", "content": "Hello, Claude!"}
166
- ]
167
- )
168
-
169
- # Async client is also supported and automatically patched
170
- from anthropic import AsyncAnthropic
171
- import asyncio
172
-
173
- async def call_claude_async():
174
- async_client = AsyncAnthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
175
- response = await async_client.messages.create(
176
- model="claude-3-haiku-20240307",
177
- max_tokens=1000,
178
- messages=[
179
- {"role": "user", "content": "Hello, async Claude!"}
180
- ]
181
- )
182
- return response
183
-
184
- # All async API calls will be logged to OSMOSIS as well
185
- asyncio.run(call_claude_async())
186
- ```
187
-
188
- ### OpenAI Example
189
-
190
- ```python
191
- # Import osmosis_ai first and initialize it
192
- import osmosis_ai
193
- osmosis_ai.init(os.environ.get("OSMOSIS_API_KEY"))
194
-
195
- # Then import and use OpenAI as normal
196
- from openai import OpenAI
197
-
198
- # Create and use the OpenAI client as usual - it's already patched
199
- client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
200
-
201
- # All API calls will now be logged to OSMOSIS automatically
202
- response = client.chat.completions.create(
203
- model="gpt-4o-mini",
204
- max_tokens=150,
205
- messages=[
206
- {"role": "user", "content": "Hello, GPT!"}
207
- ]
208
- )
209
-
210
- # Async client is also supported and automatically patched
211
- from openai import AsyncOpenAI
212
- import asyncio
213
-
214
- async def call_openai_async():
215
- async_client = AsyncOpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
216
- response = await async_client.chat.completions.create(
217
- model="gpt-4o-mini",
218
- max_tokens=150,
219
- messages=[
220
- {"role": "user", "content": "Hello, async GPT!"}
221
- ]
222
- )
223
- return response
224
-
225
- # All async API calls will be logged to OSMOSIS as well
226
- asyncio.run(call_openai_async())
227
- ```
228
-
229
- ### LangChain Example
230
-
231
- ```python
232
- # Import osmosis_ai first and initialize it
233
- import osmosis_ai
234
- osmosis_ai.init(os.environ.get("OSMOSIS_API_KEY"))
235
-
236
- # Then use LangChain as normal
237
- from langchain_core.prompts import PromptTemplate
238
-
239
- # Use LangChain prompt templates as usual
240
- template = PromptTemplate(
241
- input_variables=["topic"],
242
- template="Write a short paragraph about {topic}."
243
- )
244
-
245
- # Formatting the prompt will be logged to OSMOSIS automatically
246
- formatted_prompt = template.format(topic="artificial intelligence")
247
- print(f"Formatted prompt: {formatted_prompt}")
248
-
249
- # Multiple prompt templates are also captured
250
- template2 = PromptTemplate(
251
- input_variables=["name", "profession"],
252
- template="My name is {name} and I work as a {profession}."
253
- )
254
- formatted_prompt2 = template2.format(name="Alice", profession="data scientist")
255
- print(f"Formatted prompt 2: {formatted_prompt2}")
256
- ```
257
-
258
- ## Configuration
259
-
260
- You can configure the behavior of the library by modifying the following variables:
261
-
262
- ```python
263
- import osmosis_ai
264
-
265
- # Disable logging to OSMOSIS (default: True)
266
- osmosis_ai.enabled = False
267
- ```
268
-
269
- ## How it Works
270
-
271
- This library uses monkey patching to override the LLM clients' methods that make API calls. When you import the `osmosis_ai` module, it automatically patches the supported LLM client libraries. When methods are called on these clients, the library intercepts the calls and sends the request parameters and response data to the OSMOSIS API for logging and monitoring.
272
-
273
- The data sent to OSMOSIS includes:
274
- - Timestamp (UTC)
275
- - Request parameters
276
- - Response data
277
- - HTTP status code
278
-
279
- ## License
280
-
281
- MIT
@@ -1,15 +0,0 @@
1
- osmosis_ai/__init__.py,sha256=p6SXDKMc-AUoFSJSOCgM6zvIEYJ6IrqtymqBNAB8lW4,4471
2
- osmosis_ai/consts.py,sha256=tZ3duER7kZ5bxMdMfMiwFlsSRmOaIpTReu19NPBuZPc,408
3
- osmosis_ai/logger.py,sha256=J2Yw_QMGqXySzJlj_QQqHLs52S1oKYXoELnU66YCAuI,2170
4
- osmosis_ai/utils.py,sha256=l46vQYLZEUCFSCCUlM9tCgNgDV-WzIwzwTwR8K3vZ4I,2992
5
- osmosis_ai/adapters/__init__.py,sha256=MlS3aGG8AQqQUQlV196sPdChTvfenK6ZdSaP0Tsr8eQ,262
6
- osmosis_ai/adapters/anthropic.py,sha256=Q9pb_AxgaSTyjNYkGGZL5mslyVnfTbGI04WbxLDhvLA,22959
7
- osmosis_ai/adapters/langchain.py,sha256=oVIIRmpdadgozoysJBxoJsTVwJcjrtoA63SjRchXr9E,27673
8
- osmosis_ai/adapters/langchain_anthropic.py,sha256=qWtcNAQ3tQpJfTttV9y5mMCkPujuRodoFkaoYx9pOW8,14557
9
- osmosis_ai/adapters/langchain_openai.py,sha256=8sq4vGSqm96-UjeeiW0ZGWMOUXiv85A1BLGwaeboBF8,24815
10
- osmosis_ai/adapters/openai.py,sha256=B-dNQvA8XcmX4kB5ZZGf4EoS_VAVZPo3aTfem_xe-8I,39437
11
- osmosis_ai-0.1.8.dist-info/licenses/LICENSE,sha256=WLvxAm2-fPuT8qECE6ejD8ezG9btIanJl7zysXvtQgM,1064
12
- osmosis_ai-0.1.8.dist-info/METADATA,sha256=Zeuhm80tBeJXhG6OMvVplbH52VjQnOFsd5z2PAEBfEU,9255
13
- osmosis_ai-0.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- osmosis_ai-0.1.8.dist-info/top_level.txt,sha256=UPNRTKIBSrxsJVNxwXnLCqSoBS4bAiL_3jMtjvf5zEY,11
15
- osmosis_ai-0.1.8.dist-info/RECORD,,