forked from tmc/langchaingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllm_azure_test.go
40 lines (34 loc) · 926 Bytes
/
llm_azure_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package chains
import (
"context"
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/tmc/langchaingo/llms/openai"
"github.com/tmc/langchaingo/prompts"
)
func TestLLMChainAzure(t *testing.T) {
t.Parallel()
if openaiKey := os.Getenv("OPENAI_API_KEY"); openaiKey == "" {
t.Skip("OPENAI_API_KEY not set")
}
if openaiBase := os.Getenv("OPENAI_BASE_URL"); openaiBase == "" {
t.Skip("OPENAI_BASE_URL not set")
}
model, err := openai.New(openai.WithModel("gpt-35-turbo"), openai.WithAPIType(openai.APITypeAzure))
require.NoError(t, err)
prompt := prompts.NewPromptTemplate(
"What is the capital of {{.country}}",
[]string{"country"},
)
require.NoError(t, err)
chain := NewLLMChain(model, prompt)
result, err := Predict(context.Background(), chain,
map[string]any{
"country": "France",
},
)
require.NoError(t, err)
require.True(t, strings.Contains(result, "Paris"))
}