-
Notifications
You must be signed in to change notification settings - Fork 8
/
llm_test.go
120 lines (93 loc) · 2.83 KB
/
llm_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package wfl_test
import (
"fmt"
"os"
"github.com/dgruber/drmaa2interface"
"github.com/dgruber/wfl"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Llm", func() {
Context("OpenAI provider related tests", func() {
It("should return an error when no OpenAI token is provided", func() {
flow := wfl.NewWorkflow(wfl.NewProcessContext()).WithLLMOpenAI(
wfl.OpenAIConfig{
Token: "",
})
Expect(flow.HasError()).To(BeTrue())
})
It("should return an error when wrong OpenAI token is provided", func() {
flow := wfl.NewWorkflow(wfl.NewProcessContext()).WithLLMOpenAI(
wfl.OpenAIConfig{
Token: "wrong",
})
Expect(flow.HasError()).To(BeTrue())
})
It("should not return an error when correct OpenAI token is provided", func() {
if os.Getenv("OPENAI_KEY") == "" {
Skip("OPENAI_KEY not set")
}
flow := wfl.NewWorkflow(wfl.NewProcessContext()).WithLLMOpenAI(
wfl.OpenAIConfig{
Token: os.Getenv("OPENAI_KEY"),
})
Expect(flow.HasError()).To(BeFalse())
})
})
Context("ErrorP related tests", func() {
It("should convert an error message", func() {
if os.Getenv("OPENAI_KEY") == "" {
Skip("OPENAI_KEY not set")
}
flow := wfl.NewWorkflow(wfl.NewProcessContext()).WithLLMOpenAI(
wfl.OpenAIConfig{
Token: os.Getenv("OPENAI_KEY"),
})
job := flow.RunT(drmaa2interface.JobTemplate{
RemoteCommand: "/bin/bsh", // NOTE the job error here!
})
Expect(job.Errored()).To(BeTrue())
Expect(job.ErrorP("Explain the error and provide a solution")).NotTo(BeEmpty())
})
})
Context("OutputP related tests", func() {
It("should convert a job output", func() {
if os.Getenv("OPENAI_KEY") == "" {
Skip("OPENAI_KEY not set")
}
flow := wfl.NewWorkflow(wfl.NewProcessContext()).WithLLMOpenAI(
wfl.OpenAIConfig{
Token: os.Getenv("OPENAI_KEY"),
})
job := flow.RunT(drmaa2interface.JobTemplate{
RemoteCommand: "/bin/bash",
Args: []string{
"-c",
`uname -a`,
},
OutputPath: "/tmp/wfl-test-output.txt",
}).Wait()
Expect(job.Errored()).To(BeFalse())
Expect(job.Success()).To(BeTrue())
Expect(job.OutputP("Describe the system")).NotTo(BeEmpty())
})
})
Context("TemplateP related tests", func() {
It("should create a job template", func() {
if os.Getenv("OPENAI_KEY") == "" {
Skip("OPENAI_KEY not set")
}
flow := wfl.NewWorkflow(wfl.NewProcessContext()).WithLLMOpenAI(
wfl.OpenAIConfig{
Token: os.Getenv("OPENAI_KEY"),
})
// generates a bash job template for Linux
template, err := flow.TemplateP("How much memory is available?")
Expect(err).To(BeNil())
Expect(template).NotTo(BeNil())
Expect(template.RemoteCommand).To(Equal("/bin/bash"))
Expect(template.Args[1]).NotTo(Equal(""))
fmt.Printf("Script: %s\n", template.Args[1])
})
})
})