From e16afaf7af9c6ff81e983fc33b37183ecd99fb35 Mon Sep 17 00:00:00 2001 From: Christopher Creutzig Date: Wed, 30 Oct 2024 13:06:49 +0000 Subject: [PATCH] Drop `OPENAI_KEY` 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`. --- .github/workflows/ci.yml | 1 - tests/texampleTests.m | 2 +- tests/textractOpenAIEmbeddings.m | 22 ++++++++-------------- tests/topenAIImages.m | 21 ++++++++------------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6be9f48..8412a1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/tests/texampleTests.m b/tests/texampleTests.m index e08a5c9..4fbeb61 100644 --- a/tests/texampleTests.m +++ b/tests/texampleTests.m @@ -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 diff --git a/tests/textractOpenAIEmbeddings.m b/tests/textractOpenAIEmbeddings.m index f5352aa..da889c5 100644 --- a/tests/textractOpenAIEmbeddings.m +++ b/tests/textractOpenAIEmbeddings.m @@ -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(); @@ -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 @@ -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) diff --git a/tests/topenAIImages.m b/tests/topenAIImages.m index 4ec024e..3d586fd 100644 --- a/tests/topenAIImages.m +++ b/tests/topenAIImages.m @@ -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; @@ -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 @@ -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. " + ...