mirror of
https://github.com/hanzoai/dashscope-go-sdk.git
synced 2026-09-30 21:39:25 +00:00
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
|
|
dashscopego "github.com/hanzoai/dashscope-go-sdk"
|
|
|
|
"github.com/hanzoai/dashscope-go-sdk/qwen"
|
|
)
|
|
|
|
func main() {
|
|
model := qwen.QwenVLPlus
|
|
token := os.Getenv("DASHSCOPE_API_KEY")
|
|
|
|
if token == "" {
|
|
panic("token is empty")
|
|
}
|
|
|
|
cli := dashscopego.NewTongyiClient(model, token)
|
|
|
|
sysContent := qwen.VLContentList{
|
|
{
|
|
Text: "You are a helpful assistant.",
|
|
},
|
|
}
|
|
userContent := qwen.VLContentList{
|
|
{
|
|
// Text: "describe the image",
|
|
Text: "用唐诗体说明一下这张图片中的内容", //nolint:gosmopolitan
|
|
},
|
|
{
|
|
// Image: "https://pic.ntimg.cn/20140113/8800276_184351657000_2.jpg",
|
|
// Image: "file:///Users/xxxx/xxxx.png",
|
|
Image: "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg",
|
|
},
|
|
}
|
|
|
|
input := dashscopego.VLInput{
|
|
Messages: []dashscopego.VLMessage{
|
|
{Role: "system", Content: &sysContent},
|
|
{Role: "user", Content: &userContent},
|
|
},
|
|
}
|
|
|
|
// callback function: print stream result
|
|
streamCallbackFn := func(ctx context.Context, chunk []byte) error {
|
|
log.Print(string(chunk))
|
|
return nil
|
|
}
|
|
req := &dashscopego.VLRequest{
|
|
Input: input,
|
|
StreamingFn: streamCallbackFn,
|
|
}
|
|
|
|
ctx := context.TODO()
|
|
resp, err := cli.CreateVLCompletion(ctx, req)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
log.Println("\nnon-stream result: ")
|
|
log.Println(resp.Output.Choices[0].Message.Content.ToString())
|
|
}
|