mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-29 02:08:53 +01:00
c1729f1ee2
* Add ability to configure custom OpenAI API endpoint for #186 * Ensure the AiCompletionEndpoint field is always initialized
26 lines
777 B
Go
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)
|
|
}
|