2023-11-12 10:27:05 +01:00
|
|
|
package ai
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2024-08-11 21:15:44 +02:00
|
|
|
"github.com/ddworken/hishtory/shared/testutils"
|
2024-08-11 21:26:09 +02:00
|
|
|
|
2023-11-12 10:27:05 +01:00
|
|
|
"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") == "" {
|
2024-08-11 21:15:44 +02:00
|
|
|
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")
|
|
|
|
}
|
2023-11-12 10:27:05 +01:00
|
|
|
}
|
2024-08-11 21:15:44 +02:00
|
|
|
results, _, err := GetAiSuggestionsViaOpenAiApi("https://api.openai.com/v1/chat/completions", "list files in the current directory", "bash", "Linux", "", 3)
|
2023-11-12 10:27:05 +01:00
|
|
|
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)
|
|
|
|
}
|