Skip to content

Commit

Permalink
Minor Change
Browse files Browse the repository at this point in the history
Added valid file check to the function that retrieves the API key from an external file
  • Loading branch information
zq99 committed Jul 19, 2023
1 parent d006c78 commit 9d21bf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Binary file modified OpenAIFrameworkDemo.xlsm
Binary file not shown.
10 changes: 8 additions & 2 deletions clsOpenAI.cls
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,20 @@ Public Sub ClearSettings()
End Sub


Public Function GetReadAPIKeyFromFolder(ByVal strfolderPath As String) As String
Public Function GetReadAPIKeyFromFolder(ByVal strfolderPath As String, Optional ByVal strDefaultTextFileName As String = "apikey") As String
'Purpose: Allows retrieval of an API KEY saved in an external file (possibly stored on a drive only the current user can access)

Dim intFileNumber As Integer
Dim strAPIKey As String
Dim strFilePath As String

strFilePath = strfolderPath & "\apikey.txt" ' Construct the full file path
strFilePath = strfolderPath & "\" & strDefaultTextFileName & ".txt" ' Construct the full file path

'check file exists
If Dir(strFilePath) = "" Then
GetReadAPIKeyFromFolder = Empty
Exit Function
End If

intFileNumber = FreeFile ' Get the first available file number

Expand Down

0 comments on commit 9d21bf0

Please sign in to comment.