-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
68 lines (56 loc) · 1.43 KB
/
main.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
package main
import (
"context"
"log"
"os"
"os/user"
"path/filepath"
"github.com/devinyf/dashscopego"
"github.com/devinyf/dashscopego/qwen"
)
func main() {
model := qwen.QwenTurbo
token := os.Getenv("DASHSCOPE_API_KEY")
if token == "" {
panic("token is empty")
}
cli := dashscopego.NewTongyiClient(model, token)
usr, err := user.Current()
if err != nil {
panic(err)
}
// 比亚迪财报
pdfFile := filepath.Join(usr.HomeDir, "Downloads", "financial_results_byd.pdf")
filePath := "file://" + pdfFile
content := qwen.FileContentList{
{
Text: "分析该公司的财报信息, 判断有哪些风险和机会, 并预测后续的业绩发展趋势, 给出投资建议",
},
{
// File: "https://qianwen-res.oss-cn-beijing.aliyuncs.com/QWEN_TECHNICAL_REPORT.pdf",
File: filePath,
},
}
input := dashscopego.FileInput{
Messages: []dashscopego.FileMessage{
{Role: qwen.RoleUser, Content: &content},
},
}
// callback function: print stream result
streamCallbackFn := func(ctx context.Context, chunk []byte) error {
log.Print(string(chunk))
return nil
}
req := &dashscopego.FileRequest{
Input: input,
StreamingFn: streamCallbackFn,
Plugins: qwen.Plugins{qwen.PluginPDFExtracter: {}},
}
ctx := context.TODO()
resp, err := cli.CreateFileCompletion(ctx, req)
if err != nil {
panic(err)
}
log.Println("\nnon-stream result: ")
log.Println(resp.Output.Choices[0].Message.Content.ToString())
}