# README
dashscopego
阿里云平台 dashscope api 的 golang 封装 (非官方)
Install:
go get -u github.com/zhs007/dashscopego
Examples:
通义千问
通义万相
- 文本生成图像
- 人像风格重绘
- 图像背景生成
Paraformer(语音识别)
- 实时语音识别
- 录音文件识别
模型插件调用
- pdf解析
- 计算器
- 图片生成
- Python代码解释器
- 自定义plugin-example
langchaingo-Agent
- TODO...
开发中...
import (
"context"
"fmt"
"os"
"github.com/zhs007/dashscopego"
"github.com/zhs007/dashscopego/qwen"
)
func main() {
model := qwen.QwenTurbo
token := os.Getenv("DASHSCOPE_API_KEY")
if token == "" {
panic("token is empty")
}
cli := dashscopego.NewTongyiClient(model, token)
content := qwen.TextContent{Text: "讲个冷笑话"}
input := dashscopego.TextInput{
Messages: []dashscopego.TextMessage{
{Role: "user", Content: &content},
},
}
// (可选 SSE开启) 需要流式输出时 通过该 Callback Function 获取实时显示的结果
// 开启 SSE 时的 request_id/finish_reason/token usage 等信息在调用完成统一返回(resp)
streamCallbackFn := func(ctx context.Context, chunk []byte) error {
fmt.Print(string(chunk))
return nil
}
req := &dashscopego.TextRequest{
Input: input,
StreamingFn: streamCallbackFn,
}
ctx := context.TODO()
resp, err := cli.CreateCompletion(ctx, req)
if err != nil {
panic(err)
}
fmt.Println("\nnon-stream result: ")
fmt.Println(resp.Output.Choices[0].Message.Content.ToString())
// request_id, finish_reason, token usage
fmt.Println(resp.RequestID)
fmt.Println(resp.Output.Choices[0].FinishReason)
fmt.Println(resp.Usage.TotalTokens)
}
# Packages
No description provided by the author
No description provided by the author
Code generated by MockGen.
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
# Constants
nolint:gosec.
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author