osmosis-ai 0.1.6__py3-none-any.whl → 0.1.8__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/consts.py CHANGED
@@ -2,15 +2,16 @@ from enum import Enum
2
2
 
3
3
  # Extract package metadata
4
4
  package_name = "osmosis-ai"
5
- package_version = "0.1.6"
5
+ package_version = "0.1.8"
6
6
 
7
7
  indent = 2 # Number of spaces to use for indentation in pretty print
8
- osmosis_api_url = "https://ftgrv77m9f.execute-api.us-west-2.amazonaws.com/prod"
8
+ osmosis_api_url = "https://osmosis.gulp.dev"
9
9
 
10
10
  DEFAULT_LOG_DESTINATION = "none" # "none" or "stdout" or "stderr" or "file"
11
11
 
12
+
12
13
  class LogDestination(Enum):
13
14
  NONE = "none"
14
15
  STDOUT = "stdout"
15
16
  STDERR = "stderr"
16
- FILE = "file"
17
+ FILE = "file"
osmosis_ai/logger.py CHANGED
@@ -8,7 +8,7 @@ import os
8
8
  from .consts import LogDestination, DEFAULT_LOG_DESTINATION
9
9
 
10
10
  # Create logger
11
- logger = logging.getLogger('osmosis_ai')
11
+ logger = logging.getLogger("osmosis_ai")
12
12
  logger.setLevel(logging.INFO)
13
13
 
14
14
  # Default configuration - no logging
@@ -18,6 +18,7 @@ logger.propagate = False
18
18
  log_destination = DEFAULT_LOG_DESTINATION
19
19
  logger.log_destination = log_destination
20
20
 
21
+
21
22
  def set_log_destination(destination: LogDestination) -> None:
22
23
  """
23
24
  Set the log destination for the logger
@@ -26,6 +27,7 @@ def set_log_destination(destination: LogDestination) -> None:
26
27
  log_destination = destination
27
28
  logger.log_destination = destination
28
29
 
30
+
29
31
  def configure_logger() -> None:
30
32
  """
31
33
  Configure the logger based on the log_destination setting in consts.py
@@ -33,7 +35,7 @@ def configure_logger() -> None:
33
35
  # Remove any existing handlers
34
36
  for handler in logger.handlers[:]:
35
37
  logger.removeHandler(handler)
36
-
38
+
37
39
  # Configure based on log_destination
38
40
  if log_destination == "none":
39
41
  # No logging
@@ -54,18 +56,22 @@ def configure_logger() -> None:
54
56
  handler = logging.StreamHandler(sys.stderr)
55
57
  logger.addHandler(handler)
56
58
  logger.warning(f"Invalid log_destination: {log_destination}, using stderr")
57
-
59
+
58
60
  # Set formatter
59
- formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
61
+ formatter = logging.Formatter(
62
+ "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
63
+ )
60
64
  for handler in logger.handlers:
61
65
  handler.setFormatter(formatter)
62
66
 
67
+
63
68
  # Initialize the logger on module import
64
69
  configure_logger()
65
70
 
71
+
66
72
  # Function to force reconfiguration if log_destination is changed
67
73
  def reconfigure_logger() -> None:
68
74
  """
69
75
  Reconfigure the logger, should be called if log_destination changes
70
76
  """
71
- configure_logger()
77
+ configure_logger()
osmosis_ai/utils.py CHANGED
@@ -4,10 +4,13 @@ Utility functions for osmosisadapters
4
4
 
5
5
  import json
6
6
  from datetime import datetime, timezone
7
- from typing import Any, Dict
7
+ from typing import Any, Dict, Callable
8
8
  import xxhash
9
+ import functools
10
+
9
11
  # Import constants
10
12
  from .consts import osmosis_api_url
13
+
11
14
  # Import logger
12
15
  from .logger import logger
13
16
 
@@ -16,10 +19,11 @@ enabled = True
16
19
  osmosis_api_key = None # Will be set by init()
17
20
  _initialized = False
18
21
 
22
+
19
23
  def init(api_key: str) -> None:
20
24
  """
21
25
  Initialize osmosiswith the OSMOSIS API key.
22
-
26
+
23
27
  Args:
24
28
  api_key: The OSMOSIS API key for logging LLM usage
25
29
  """
@@ -27,18 +31,23 @@ def init(api_key: str) -> None:
27
31
  osmosis_api_key = api_key
28
32
  _initialized = True
29
33
 
34
+
30
35
  def disable_osmosis() -> None:
31
36
  global enabled
32
37
  enabled = False
33
38
 
39
+
34
40
  def enable_osmosis() -> None:
35
41
  global enabled
36
42
  enabled = True
37
43
 
38
- def send_to_osmosis(query: Dict[str, Any], response: Dict[str, Any], status: int = 200) -> None:
44
+
45
+ def send_to_osmosis(
46
+ query: Dict[str, Any], response: Dict[str, Any], status: int = 200
47
+ ) -> None:
39
48
  """
40
49
  Send query and response data to the OSMOSIS API using AWS Firehose.
41
-
50
+
42
51
  Args:
43
52
  query: The query/request data
44
53
  response: The response data
@@ -54,35 +63,58 @@ def send_to_osmosis(query: Dict[str, Any], response: Dict[str, Any], status: int
54
63
  try:
55
64
  # Import requests only when needed
56
65
  import requests
57
-
66
+
58
67
  # Create headers
59
- headers = {
60
- "Content-Type": "application/json",
61
- "x-api-key": osmosis_api_key
62
- }
63
-
68
+ headers = {"Content-Type": "application/json", "x-api-key": osmosis_api_key}
69
+
64
70
  # Prepare main data payload
65
71
  data = {
66
- "owner": xxhash.xxh32(osmosis_api_key.encode('utf-8')).hexdigest(),
72
+ "owner": xxhash.xxh32(osmosis_api_key.encode("utf-8")).hexdigest(),
67
73
  "date": int(datetime.now(timezone.utc).timestamp()),
68
74
  "query": query,
69
75
  "response": response,
70
- "status": status
76
+ "status": status,
71
77
  }
72
78
 
73
79
  logger.info(f"Sending data to OSMOSIS API: {data}")
74
-
80
+
75
81
  # Send main data payload
76
82
  response_data = requests.post(
77
- f"{osmosis_api_url}/data",
83
+ f"{osmosis_api_url}/ingest",
78
84
  headers=headers,
79
- data=json.dumps(data).replace('\n', '') + '\n'
85
+ data=json.dumps(data).replace("\n", "") + "\n",
80
86
  )
81
-
87
+
82
88
  if response_data.status_code != 200:
83
- logger.warning(f"OSMOSIS API returned status {response_data.status_code} for data")
84
-
89
+ logger.warning(
90
+ f"OSMOSIS API returned status {response_data.status_code} for data with error: {response_data.text}"
91
+ )
92
+
85
93
  except ImportError:
86
- logger.warning("Requests library not installed. Please install it with 'pip install requests'.")
94
+ logger.warning(
95
+ "Requests library not installed. Please install it with 'pip install requests'."
96
+ )
87
97
  except Exception as e:
88
- logger.warning(f"Failed to send data to OSMOSIS API: {str(e)}")
98
+ logger.warning(f"Failed to send data to OSMOSIS API: {str(e)}")
99
+
100
+
101
+ def osmosis_reward(func: Callable) -> Callable:
102
+ """
103
+ Decorator for reward functions.
104
+
105
+ Args:
106
+ func: The reward function to be wrapped
107
+
108
+ Returns:
109
+ The wrapped function
110
+
111
+ Example:
112
+ @osmosis_reward
113
+ def calculate_reward(state, action):
114
+ return state.score + action.value
115
+ """
116
+ @functools.wraps(func)
117
+ def wrapper(*args, **kwargs):
118
+ return func(*args, **kwargs)
119
+
120
+ return wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osmosis-ai
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: Monkey patches LLM client libraries to print all prompts and responses
5
5
  Author-email: Gulp AI <jake@gulp.ai>
6
6
  License: MIT License
@@ -0,0 +1,15 @@
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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.0.2)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,15 +0,0 @@
1
- osmosis_ai/__init__.py,sha256=nQJwkT7efmsSQ0ydygcH1OUW8y2rKxHCnwKD-Br51Co,4266
2
- osmosis_ai/consts.py,sha256=EqrQmFe6kXMHgK5J2xdtzUFnuRVaV3KDDsbQATQphwo,441
3
- osmosis_ai/logger.py,sha256=eG-GJoUo7bcrFkLOS0HGzCSbshaZRoowjSI0ZsUZH1U,2160
4
- osmosis_ai/utils.py,sha256=_CLtNAxli8bTzIzDY86MWefpJpFoAdta9RHC2DnEpP0,2470
5
- osmosis_ai/adapters/__init__.py,sha256=IOaShk3HYVdKYRd6aPLu1Shvt_LeUjYaCrtOE3BIrJw,262
6
- osmosis_ai/adapters/anthropic.py,sha256=GzTw03L9zth7GjCKEbNgEgDQQApwohmm6MpWbsa52CE,21796
7
- osmosis_ai/adapters/langchain.py,sha256=s_T7LM-o8VR3UMGeudj-XSjC_jDQvAHHAWdgTUJcOKA,26397
8
- osmosis_ai/adapters/langchain_anthropic.py,sha256=VME8PJMjjtikL00JiFaH7VWtySAWJ9eYez2gFyhGN8U,13350
9
- osmosis_ai/adapters/langchain_openai.py,sha256=1Jo3X5Yv14SztvidLZM4usdnF8lcjxhVhECO85hgWl4,22908
10
- osmosis_ai/adapters/openai.py,sha256=8pVtVkD5rUGI5tpNmGIYVBTOyPmheQTknmGHNDjrYd8,38620
11
- osmosis_ai-0.1.6.dist-info/licenses/LICENSE,sha256=WLvxAm2-fPuT8qECE6ejD8ezG9btIanJl7zysXvtQgM,1064
12
- osmosis_ai-0.1.6.dist-info/METADATA,sha256=Yl84ihmD7UbC7lS0atAC7lIriauKyXXKq0DNZ0oxVK8,9255
13
- osmosis_ai-0.1.6.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
14
- osmosis_ai-0.1.6.dist-info/top_level.txt,sha256=UPNRTKIBSrxsJVNxwXnLCqSoBS4bAiL_3jMtjvf5zEY,11
15
- osmosis_ai-0.1.6.dist-info/RECORD,,