Skip to content

Commit fb78acf

Browse files
committed
Store API key for LLM inference in a file
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
1 parent a8cac95 commit fb78acf

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ Evaluation of Log Detective performance can be performed automatically using
5151
the `validation.py`script. Dependencies for the tool are defined in the
5252
`requirements.txt` file and should be installed in a virtual environment.
5353

54-
Before running the script, the API key for the LLM judge must be set
55-
in an environment variable `OPENAI_API_KEY`.
54+
Keys for OpenAI compatible LLM inference provider and Log Detective itself,
55+
must be stored in files. These will be used at runtime.
56+
This prevents logging of secrets in history.
5657

5758
Example:
5859

5960
```
60-
./validation.py <DATA_PATH> <LOG_DETECTIVE_URL> <LLM_URL> <LLM_NAME>
61+
./validation.py <PATH_TO_OPEN_AI_API_KEY> <DATA_PATH> <LOG_DETECTIVE_URL> <LLM_URL> <LLM_NAME>
6162
```
6263
Script sends each of the the stored log files for evaluation by Log Detective,
6364
then submits both results of final analysis from Log Detective and actual issue

validation.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
import argparse
1111
from pydantic import BaseModel, Field, ValidationError
1212

13-
# --- Configuration ---
14-
# Set your OpenAI API key as an environment variable named OPENAI_API_KEY
15-
# You can get a key from https://beta.openai.com/account/api-keys
16-
API_KEY = os.getenv("OPENAI_API_KEY")
1713
LOG_REPO_BASE_URL = (
1814
"https://raw.githubusercontent.com/fedora-copr/logdetective-sample/main/data/"
1915
)
@@ -222,6 +218,11 @@ def main():
222218
description="Evaluate AI system performance by comparing expected and actual responses.",
223219
formatter_class=argparse.ArgumentDefaultsHelpFormatter
224220
)
221+
parser.add_argument(
222+
"open_ai_api_key",
223+
help="Path to file with API key to OpenAI compatible inference provider",
224+
type=str,
225+
)
225226
parser.add_argument(
226227
"data_directory", help="Path to the directory containing the sample data."
227228
)
@@ -245,9 +246,7 @@ def main():
245246
)
246247
args = parser.parse_args()
247248

248-
if not API_KEY:
249-
print("Error: OPENAI_API_KEY environment variable not set.", file=sys.stderr)
250-
sys.exit(1)
249+
open_ai_api_key = get_api_key_from_file(args.open_ai_api_key)
251250

252251
if not os.path.isdir(args.data_directory):
253252
print(f"Error: Directory not found at '{args.data_directory}'", file=sys.stderr)
@@ -262,7 +261,7 @@ def main():
262261
server_address=args.logdetective_url,
263262
llm_url=args.llm_url,
264263
llm_model=args.llm_model,
265-
llm_token=API_KEY,
264+
llm_token=open_ai_api_key,
266265
log_detective_api_timeout=args.log_detective_api_timeout,
267266
log_detective_api_key=log_detective_api_key
268267
)

0 commit comments

Comments
 (0)