The ClassifyTypeWithGPT function is a VBA function that uses the OpenAI GPT API to classify an input into one of several predefined outputs.
- An API key from OpenAI. You can sign up and generate one from OpenAI here.
- VBA-JSON library found on GitHub.
- Download the ClassifyTypeWithGPT.bas file from this repository.
- Import the ClassifyTypeWithGPT.bas file into your VBA project.
- In your VBA code, call the ClassifyTypeWithGPT function with the required parameters.
To use the ClassifyTypeWithGPT function, you will need to provide the following parameters:
- inputValue - The value to be identified.
- outputOptions() - An array of possible types the value could be classified as.
- apikey - Your OpenAI API key.
Optional:
- modelName - An OpenAI API model name.
Note: If a modelName is not entered, the default GPT model 'gpt-3.5-turbo' will be used
Example:
Sub ExampleMacro()
Dim inputValue As String
Dim outputOptions(1) As String
Dim apiKey As String
Dim modelName As String
Dim result As String
inputValue = "apple"
outputOptions(0) = "fruit"
outputOptions(1) = "vegetable"
apiKey = "your-api-key"
modelName = "text-davinci-003"
result = ClassifyTypeWithGPT.ClassifyTypeWithGPT(inputValue, outputOptions, apiKey, modelName)
MsgBox "The item '" & inputValue & "' was classified as: " & result
End Sub
Output:
If GPT is unable to fit the inputValue into any of the provided options, it will return 'unknown':