osbot-utils 2.38.0__py3-none-any.whl → 2.40.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.
@@ -26,6 +26,6 @@ class LLM_Request__Execute(Type_Safe):
26
26
  llm_response = Schema__LLM_Response(response_data=response_data) # Create response object
27
27
 
28
28
  if self.use_cache: # Cache the response if enabled
29
- self.llm_cache.add(llm_request, llm_response)
29
+ self.llm_cache.add(request=llm_request, response=llm_response, payload=llm_payload)
30
30
 
31
31
  return llm_response
@@ -25,14 +25,16 @@ class LLM_Request__Cache(Type_Safe):
25
25
  return Safe_Str__Hash(hash_value)
26
26
 
27
27
  @type_safe
28
- def add(self, request : Schema__LLM_Request , # Request to cache
29
- response : Schema__LLM_Response # Response to store
28
+ def add(self, request : Schema__LLM_Request , # Request to cache
29
+ response : Schema__LLM_Response, # Response to store
30
+ payload : dict # Payload to store
30
31
  ) -> Obj_Id: # returns cache_id
31
32
 
32
33
  hash_request = self.compute_request_hash (request) # calculate request hash
33
34
  cache_entry = Schema__LLM_Response__Cache(cache_id = Obj_Id() , # Create a cache entry
34
35
  llm_request = request ,
35
36
  llm_response = response ,
37
+ llm_payload = payload ,
36
38
  hash__request = hash_request )
37
39
  cache_id = cache_entry.cache_id
38
40
 
@@ -46,15 +48,30 @@ class LLM_Request__Cache(Type_Safe):
46
48
 
47
49
  if request_hash in self.cache_index.cache_id__from__hash__request: # Check if we have an exact match
48
50
  cache_id = self.cache_index.cache_id__from__hash__request[request_hash]
49
- cache_entry = self.get_cache_entry(cache_id)
51
+ cache_entry = self.get__cache_entry__from__cache_id(cache_id)
50
52
  if cache_entry:
51
53
  return cache_entry.llm_response
52
54
 
53
55
  return None
54
56
 
55
57
  @type_safe
56
- def get_cache_entry(self, cache_id: Obj_Id) -> Optional[Schema__LLM_Response__Cache]: # Get cache entry by ID
57
- return self.cache_entries.get(cache_id)
58
+ def get__cache_entry__from__cache_id(self, cache_id: Obj_Id) -> Optional[Schema__LLM_Response__Cache]: # Get cache entry by ID
59
+ if cache_id:
60
+ return self.cache_entries.get(cache_id)
61
+
62
+ @type_safe
63
+ def get__cache_entry__from__request(self, request: Schema__LLM_Request):
64
+ cache_id = self.get__cache_id__from__request(request)
65
+ return self.get__cache_entry__from__cache_id(cache_id)
66
+
67
+ @type_safe
68
+ def get__cache_id__from__request(self, request: Schema__LLM_Request):
69
+ request_hash = self.compute_request_hash(request)
70
+ return self.get__cache_id__from__request_hash(request_hash)
71
+
72
+ @type_safe
73
+ def get__cache_id__from__request_hash(self, request_hash: Safe_Str__Hash):
74
+ return self.cache_index.cache_id__from__hash__request.get(request_hash)
58
75
 
59
76
  def exists(self, request: Schema__LLM_Request) -> bool: # True if in cache
60
77
  request_hash = self.compute_request_hash(request)
@@ -76,7 +93,7 @@ class LLM_Request__Cache(Type_Safe):
76
93
  return self.save()
77
94
 
78
95
  def get_by_id(self, cache_id : Obj_Id)-> Optional[Schema__LLM_Response]: # Cached response or None
79
- cache_entry = self.get_cache_entry(cache_id)
96
+ cache_entry = self.get__cache_entry__from__cache_id(cache_id)
80
97
  if cache_entry:
81
98
  return cache_entry.llm_response
82
99
  return None
@@ -169,12 +169,13 @@ class LLM_Request__Cache__File_System(LLM_Request__Cache):
169
169
  return path
170
170
 
171
171
  @type_safe
172
- def add(self, request : Schema__LLM_Request,
172
+ def add(self, request : Schema__LLM_Request ,
173
173
  response : Schema__LLM_Response,
174
+ payload : dict ,
174
175
  now : datetime = None
175
176
  ) -> Obj_Id: # Save an LLM request/response pair using temporal organization.
176
177
 
177
- cache_id = super().add(request, response) # First use standard add() to handle in-memory caching
178
+ cache_id = super().add(request=request, response=response, payload=payload) # First use standard add() to handle in-memory caching
178
179
  cache_entry = self.cache_entries[cache_id] # get the cache entry (which will exist since it was added on super().add(request, response) )
179
180
  request_domains = self.extract_domains_from_request(request) # Extract domains and areas for organization
180
181
  domains = self.shared_domains + request_domains
@@ -219,7 +220,7 @@ class LLM_Request__Cache__File_System(LLM_Request__Cache):
219
220
  # cache_id_str = os.path.splitext(os.path.basename(item_path))[0]
220
221
  # if is_obj_id(cache_id_str):
221
222
  # cache_id = Obj_Id(cache_id_str)
222
- # cache_entry = self.get_cache_entry(cache_id)
223
+ # cache_entry = self.get_cache_entry__from__cache_id(cache_id)
223
224
  # if cache_entry:
224
225
  # results.append(cache_entry)
225
226
  #
@@ -10,4 +10,5 @@ class Schema__LLM_Response__Cache(Type_Safe):
10
10
  hash__request : Safe_Str__Hash = None
11
11
  llm_response : Schema__LLM_Response = None
12
12
  llm_request : Schema__LLM_Request = None
13
+ llm_payload : dict
13
14
  timestamp : Timestamp_Now
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.38.0
1
+ v2.40.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.38.0
3
+ Version: 2.40.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  License: MIT
6
6
  Author: Dinis Cruz
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  Powerful Python util methods and classes that simplify common apis and tasks.
25
25
 
26
- ![Current Release](https://img.shields.io/badge/release-v2.38.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v2.40.0-blue)
27
27
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
28
28
 
29
29
 
@@ -190,7 +190,7 @@ osbot_utils/helpers/html/Tag__Link.py,sha256=rQ-gZN8EkSv5x1S-smdjvFflwMQHACHQXiO
190
190
  osbot_utils/helpers/html/Tag__Style.py,sha256=LPPlIN7GyMvfCUlbs2eXVMUr9jS0PX5M94A5Ig_jXIs,846
191
191
  osbot_utils/helpers/html/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
192
192
  osbot_utils/helpers/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
193
- osbot_utils/helpers/llms/actions/LLM_Request__Execute.py,sha256=vR_7ManwTSyUOIF_eJK3sft1wBVadaGHkZOzspVc7T4,1987
193
+ osbot_utils/helpers/llms/actions/LLM_Request__Execute.py,sha256=F921XqKGdH7M77E1OKrGcJnYBoqMKeOdXp98VVCJhKE,2025
194
194
  osbot_utils/helpers/llms/actions/Type_Safe__Schema_For__LLMs.py,sha256=em9RoSZqSSo6BQBZvEKH8Qv8f8f8oubNpy0LIDsak-E,12024
195
195
  osbot_utils/helpers/llms/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
196
196
  osbot_utils/helpers/llms/builders/LLM_Request__Builder.py,sha256=c8MN66ijFn9DugbBIGmG0bm9ujS-0kvZDGqJcZsHHYc,3385
@@ -198,8 +198,8 @@ osbot_utils/helpers/llms/builders/LLM_Request__Builder__Open_AI.py,sha256=JwyPDe
198
198
  osbot_utils/helpers/llms/builders/LLM_Request__Factory.py,sha256=bpFXVTKpalBL7ZONjaHU5c0-2Rwzzd2vgdD1FpYxfGw,6291
199
199
  osbot_utils/helpers/llms/builders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
200
200
  osbot_utils/helpers/llms/cache/LLM_Cache__Path_Generator.py,sha256=7kDY-aaUWR4Da6lj5RPwjqTLUTGrOUYhbNfOPM30e40,4442
201
- osbot_utils/helpers/llms/cache/LLM_Request__Cache.py,sha256=8Ayz26bteYhc4GNLpItNYlTwF4_yKvhFridDVA61fPo,6783
202
- osbot_utils/helpers/llms/cache/LLM_Request__Cache__File_System.py,sha256=m4guw6yoo8Q05PQea6SJnET5xpJMwmmXhdN-kaRvX5s,15306
201
+ osbot_utils/helpers/llms/cache/LLM_Request__Cache.py,sha256=xmHZ8hV1w6aUjPp8zmHIydjr84keUT--Ug_ABpNSVlE,7684
202
+ osbot_utils/helpers/llms/cache/LLM_Request__Cache__File_System.py,sha256=4xYBhzydIoZI0g9CAswSGdFtwp6dcItm8_vnMfeSoTg,15408
203
203
  osbot_utils/helpers/llms/cache/LLM_Request__Cache__Storage.py,sha256=0ok7z2kGiK3edlgD0hwD5z2hYFZ91Viar1JgD7SNoxg,5434
204
204
  osbot_utils/helpers/llms/cache/Virtual_Storage__Local__Folder.py,sha256=xNM2xy0-2ROvhEFXa_jwqth7eApIcRTqcRUDxo0THXI,3214
205
205
  osbot_utils/helpers/llms/cache/Virtual_Storage__Sqlite.py,sha256=j8EWuKFVMtDBxrCEi8yNdpzwvTxO6Bri2Bi4-KwO-3s,4638
@@ -214,7 +214,7 @@ osbot_utils/helpers/llms/schemas/Schema__LLM_Request__Function_Call.py,sha256=VJ
214
214
  osbot_utils/helpers/llms/schemas/Schema__LLM_Request__Message__Content.py,sha256=nl-16yz4G_72ViACKE9CvGStrKxw2Gm_JcaU8wVcJXI,521
215
215
  osbot_utils/helpers/llms/schemas/Schema__LLM_Request__Message__Role.py,sha256=T99w0cRrDPXQqPT-Nw7_14tMr4vKpUlhw74UJZL6w6w,168
216
216
  osbot_utils/helpers/llms/schemas/Schema__LLM_Response.py,sha256=R62zjoUqu9sbtbFcOX7vG1t0vTaAhS_3Z9CkxESrTjI,298
217
- osbot_utils/helpers/llms/schemas/Schema__LLM_Response__Cache.py,sha256=ZlD3DeKeS-29n9qiMVrsnj0M4lkZWknnP-Wn8wanu6E,786
217
+ osbot_utils/helpers/llms/schemas/Schema__LLM_Response__Cache.py,sha256=jRV637LYbj9HhRtipYsd0JBxcvRnVHcF0OFJHObGhHA,820
218
218
  osbot_utils/helpers/llms/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
219
219
  osbot_utils/helpers/pubsub/Event__Queue.py,sha256=bCtIdVlAuG-jvFEnz14oNhgRScEUrd8v9BqLcZleGks,5038
220
220
  osbot_utils/helpers/pubsub/PubSub__Client.py,sha256=6K3l4H-Tc0DhktrxpYzLVur1uZ532pQsHWprLNRXFJE,2316
@@ -398,8 +398,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
398
398
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
399
399
  osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
400
400
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
401
- osbot_utils/version,sha256=5wV6C9vRtevBlgAl6UzZ00kufvcHsbgatM8FaiKy5Us,8
402
- osbot_utils-2.38.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
403
- osbot_utils-2.38.0.dist-info/METADATA,sha256=1oshM3ZIVLYEZhR_CgTKhCw7m2wWz62PvYqgCgLm22A,1329
404
- osbot_utils-2.38.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
405
- osbot_utils-2.38.0.dist-info/RECORD,,
401
+ osbot_utils/version,sha256=EA_osWNMH5Sn_inc9L5qYPjfsYR_EbU1rahws7uQB0o,8
402
+ osbot_utils-2.40.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
403
+ osbot_utils-2.40.0.dist-info/METADATA,sha256=YPJG2T0zO_VSq9HLF-n45Imxo2bf9vq2VxWN6QBc5ko,1329
404
+ osbot_utils-2.40.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
405
+ osbot_utils-2.40.0.dist-info/RECORD,,