Skip to content

Commit

Permalink
Drop OPENAI_KEY
Browse files Browse the repository at this point in the history
For some reason, we used both `OPENAI_KEY` and `OPENAI_API_KEY` env variables, expecting them to have the same values. Drop the `OPENAI_KEY` one, since we document our use of `OPENAI_API_KEY`.
  • Loading branch information
ccreutzi committed Oct 30, 2024
1 parent e5e90fa commit e16afaf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
cache: true
- name: Run tests and generate artifacts
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
AZURE_OPENAI_DEPLOYMENT: ${{ secrets.AZURE_DEPLOYMENT }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_ENDPOINT }}
Expand Down
2 changes: 1 addition & 1 deletion tests/texampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function setUpAndTearDowns(testCase)
import matlab.unittest.fixtures.CurrentFolderFixture
testCase.applyFixture(CurrentFolderFixture("../examples/mlx-scripts"));

openAIEnvVar = "OPENAI_KEY";
openAIEnvVar = "OPENAI_API_KEY";
secretKey = getenv(openAIEnvVar);
% Create an empty .env file because it is expected by our .mlx
% example files
Expand Down
22 changes: 8 additions & 14 deletions tests/textractOpenAIEmbeddings.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

% Copyright 2023-2024 The MathWorks, Inc.

methods (TestClassSetup)
function saveEnvVar(testCase)
% Ensures key is not in environment variable for tests
openAIEnvVar = "OPENAI_API_KEY";
if isenv(openAIEnvVar)
key = getenv(openAIEnvVar);
unsetenv(openAIEnvVar);
testCase.addTeardown(@(x) setenv(openAIEnvVar, x), key);
end
end
end

properties(TestParameter)
InvalidInput = iGetInvalidInput();
ValidDimensionsModelCombinations = iGetValidDimensionsModelCombinations();
Expand All @@ -29,6 +17,13 @@ function embedsDifferentStringTypes(testCase)
end

function keyNotFound(testCase)
% Ensures key is not in environment variable for tests
openAIEnvVar = "OPENAI_API_KEY";
if isenv(openAIEnvVar)
key = getenv(openAIEnvVar);
reset = onCleanup(@() setenv(openAIEnvVar, key));
unsetenv(openAIEnvVar);
end
testCase.verifyError(@()extractOpenAIEmbeddings("bla"), "llms:keyMustBeSpecified");
end

Expand All @@ -40,8 +35,7 @@ function validCombinationOfModelAndDimension(testCase, ValidDimensionsModelCombi
end

function embedStringWithSuccessfulOpenAICall(testCase)
testCase.verifyWarningFree(@()extractOpenAIEmbeddings("bla", ...
APIKey=getenv("OPENAI_KEY")));
testCase.verifyWarningFree(@()extractOpenAIEmbeddings("bla"));
end

function invalidCombinationOfModelAndDimension(testCase)
Expand Down
21 changes: 8 additions & 13 deletions tests/topenAIImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

% Copyright 2024 The MathWorks, Inc.

methods (TestClassSetup)
function saveEnvVar(testCase)
% Ensures key is not in environment variable for tests
openAIEnvVar = "OPENAI_API_KEY";
if isenv(openAIEnvVar)
key = getenv(openAIEnvVar);
testCase.addTeardown(@() setenv(openAIEnvVar, key));
unsetenv(openAIEnvVar);
end
end
end

properties(TestParameter)
InvalidConstructorInput = iGetInvalidConstructorInput;
InvalidGenerateInput = iGetInvalidGenerateInput;
Expand All @@ -32,6 +20,13 @@ function generateAcceptsSingleStringAsInput(testCase)
end

function keyNotFound(testCase)
% Ensures key is not in environment variable for tests
openAIEnvVar = "OPENAI_API_KEY";
if isenv(openAIEnvVar)
key = getenv(openAIEnvVar);
reset = onCleanup(@() setenv(openAIEnvVar, key));
unsetenv(openAIEnvVar);
end
testCase.verifyError(@()openAIImages, "llms:keyMustBeSpecified");
end

Expand Down Expand Up @@ -131,7 +126,7 @@ function invalidInputsVariation(testCase, InvalidVariationInput)
end

function testThatImageIsReturned(testCase)
mdl = openAIImages(APIKey=getenv("OPENAI_KEY"));
mdl = openAIImages;

[images, response] = generate(mdl, ...
"Create a 3D avatar of a whimsical sushi on the beach. " + ...
Expand Down

0 comments on commit e16afaf

Please sign in to comment.