Add basic sanity test to confirm that our interactions with the OpenAI API are correct

This commit is contained in:
David Dworken 2023-11-12 01:27:05 -08:00
parent a8f47cf340
commit 1a450c0817
2 changed files with 26 additions and 0 deletions

View File

@ -66,6 +66,7 @@ jobs:
- name: Go test
env:
DD_API_KEY: ${{ secrets.DD_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
# Once https://github.com/gotestyourself/gotestsum/pull/377 is merged, update this to pull from main rather than my fork

25
shared/ai/ai_test.go Normal file
View File

@ -0,0 +1,25 @@
package ai
import (
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// A basic sanity test that our integration with the OpenAI API is correct and is returning reasonable results (at least for a very basic query)
func TestLiveOpenAiApi(t *testing.T) {
if os.Getenv("OPENAI_API_KEY") == "" {
t.Skip("Skipping test since OPENAI_API_KEY is not set")
}
results, _, err := GetAiSuggestionsViaOpenAiApi("list files in the current directory", 3)
require.NoError(t, err)
resultsContainsLs := false
for _, result := range results {
if strings.Contains(result, "ls") {
resultsContainsLs = true
}
}
require.Truef(t, resultsContainsLs, "expected results=%#v to contain ls", results)
}