mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-26 02:03:37 +01:00
32 lines
951 B
Go
32 lines
951 B
Go
package ai
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/ddworken/hishtory/shared/testutils"
|
|
|
|
"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") == "" {
|
|
if testutils.IsGithubAction() {
|
|
t.Fatal("OPENAI_API_KEY is not set, cannot run TestLiveOpenAiApi")
|
|
} else {
|
|
t.Skip("Skipping test since OPENAI_API_KEY is not set")
|
|
}
|
|
}
|
|
results, _, err := GetAiSuggestionsViaOpenAiApi("https://api.openai.com/v1/chat/completions", "list files in the current directory", "bash", "Linux", "", 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)
|
|
}
|