File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -159,5 +159,7 @@ cython_debug/
159
159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
160
.idea /
161
161
162
+ .vscode /
163
+
162
164
.pdm-python
163
165
.python-version
Original file line number Diff line number Diff line change 22
22
23
23
import requests
24
24
25
+ from llmwhisperer .utils import LLMWhispererUtils
26
+
25
27
BASE_URL = "https://llmwhisperer-api.unstract.com/v1"
26
28
27
29
@@ -110,6 +112,9 @@ def __init__(
110
112
111
113
if api_key == "" :
112
114
self .api_key = os .getenv ("LLMWHISPERER_API_KEY" , "" )
115
+ else :
116
+ self .api_key = api_key
117
+ self .logger .debug ("api_key set to %s" , LLMWhispererUtils .redact_key (self .api_key ))
113
118
114
119
self .api_timeout = api_timeout
115
120
Original file line number Diff line number Diff line change
1
+ class LLMWhispererUtils :
2
+ @staticmethod
3
+ def redact_key (api_key : str , reveal_length = 4 ) -> str :
4
+ """Hides sensitive information partially. Useful for logging keys.
5
+
6
+ Args:
7
+ api_key (str): API key to redact
8
+
9
+ Returns:
10
+ str: Redacted API key
11
+ """
12
+ if not isinstance (api_key , str ):
13
+ raise ValueError ("API key must be a string" )
14
+
15
+ if reveal_length < 0 :
16
+ raise ValueError ("Reveal length must be a non-negative integer" )
17
+
18
+ redacted_length = max (len (api_key ) - reveal_length , 0 )
19
+ revealed_part = api_key [:reveal_length ]
20
+ redacted_part = "x" * redacted_length
21
+ return revealed_part + redacted_part
You can’t perform that action at this time.
0 commit comments