-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_flow_test.go
62 lines (57 loc) · 1.2 KB
/
example_flow_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
package anyi_test
import (
"log"
"os"
"github.com/jieliu2000/anyi"
"github.com/jieliu2000/anyi/llm"
)
func Example_flowWithDynamicConfig() {
config := anyi.AnyiConfig{
Clients: []llm.ClientConfig{
{
Name: "dashscope",
Type: "dashscope",
Config: map[string]interface{}{
"model": "qwen-max",
"apiKey": os.Getenv("DASHSCOPE_API_KEY"),
},
},
},
Flows: []anyi.FlowConfig{
{
Name: "smart_writer",
Steps: []anyi.StepConfig{
{
Name: "write_story",
Executor: &anyi.ExecutorConfig{
Type: "llm",
WithConfig: map[string]interface{}{
"template": "Write a sci-fi story about {{.Text}}",
},
},
},
{
Name: "translate_story",
Executor: &anyi.ExecutorConfig{
Type: "llm",
WithConfig: map[string]interface{}{
"template": `Translate below text to French without any extra output. The text to be translated:
'''{{.Text}}'''`,
},
},
},
},
},
},
}
anyi.Config(&config)
flow, err := anyi.GetFlow("smart_writer")
if err != nil {
panic(err)
}
context, err := flow.RunWithInput("the moon")
if err != nil {
panic(err)
}
log.Printf("%s", context.Text)
}