hishtory/shared/ai/ai_test.go
David Dworken c1729f1ee2
Add ability to configure custom OpenAI API endpoint for #186 (#194)
* Add ability to configure custom OpenAI API endpoint for #186

* Ensure the AiCompletionEndpoint field is always initialized
2024-08-11 12:29:37 -07:00

26 lines
777 B
Go

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("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)
}