Skip to content

Commit

Permalink
update dtypes and example
Browse files Browse the repository at this point in the history
  • Loading branch information
devinyf committed Feb 22, 2024
1 parent 105c58c commit a464947
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func main() {
model := string(qwen.QwenTurbo)
model := qwen.QwenTurbo
token := os.Getenv("DASHSCOPE_API_KEY")

if token == "" {
Expand Down Expand Up @@ -54,10 +54,10 @@ func main() {
}
```

通义万相
通义万相(文生图)
```go
func main() {
model := string(wanx.WanxV1)
model := wanx.WanxV1
token := os.Getenv("DASHSCOPE_API_KEY")
if token == "" {
panic("token is empty")
Expand Down Expand Up @@ -112,9 +112,10 @@ func saveImg2Desktop(fileType string, data []byte) {
```

通义千问VL(视觉理解大模型)
* P.S. 直接使用 本地图片路径 或 图片URL链接 目前非稳定实现, 还没有看官方文档指引, 这里暂时模拟了 dashscope python 库的实现, 后续可能会有变更
```go
func main() {
model := string(qwen.QwenVLPlus)
model := qwen.QwenVLPlus
token := os.Getenv("DASHSCOPE_API_KEY")

if token == "" {
Expand All @@ -133,7 +134,12 @@ func main() {
Text: "用唐诗体描述一下这张图片中的内容",
},
{
// 官方文档的例子, oss 下载
Image: "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg",
// 使用 图片URL链接
// Image: "https://pic.ntimg.cn/20140113/8800276_184351657000_2.jpg",
// 本地图片
// Image: "file:///Users/xxxx/xxxx.png",
},
}

Expand Down
2 changes: 1 addition & 1 deletion example/qwen/stream_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
model := string(qwen.QwenTurbo)
model := qwen.QwenTurbo
token := os.Getenv("DASHSCOPE_API_KEY")

if token == "" {
Expand Down
2 changes: 2 additions & 0 deletions example/qwen_vl/stream_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func main() {
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",
},
}
Expand Down
2 changes: 1 addition & 1 deletion example/wanx/img_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func main() {
model := string(wanx.WanxV1)
model := wanx.WanxV1
token := os.Getenv("DASHSCOPE_API_KEY")
if token == "" {
panic("token is empty")
Expand Down
12 changes: 7 additions & 5 deletions qwen/qwen_dtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ type Input[T IQwenContent] struct {
type StreamingFunc func(ctx context.Context, chunk []byte) error

type Request[T IQwenContent] struct {
Model string `json:"model"`
Input Input[T] `json:"input"`
Parameters *Parameters `json:"parameters,omitempty"`
StreamingFn StreamingFunc `json:"-"`
HasUploadOss bool `json:"-"`
Model string `json:"model"`
Input Input[T] `json:"input"`
Parameters *Parameters `json:"parameters,omitempty"`
// streaming callback function.
StreamingFn StreamingFunc `json:"-"`
// qwen-vl model need to upload image to oss for recognition.
HasUploadOss bool `json:"-"`
}

func (q *Request[T]) SetModel(value string) *Request[T] {
Expand Down
2 changes: 1 addition & 1 deletion qwen/qwen_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const (
QwenVLSubURL = "/v1/services/aigc/multimodal-generation/generation"
)

type ModelQwen string
type ModelQwen = string

const (
// text-generation model.
Expand Down
2 changes: 1 addition & 1 deletion wanx/wanx_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (
TaskURI = "/api/v1/tasks/%s"
)

type ModelWanx string
type ModelWanx = string

const (
WanxV1 ModelWanx = "wanx-v1"
Expand Down

0 comments on commit a464947

Please sign in to comment.