Categorygithub.com/zhs007/dashscopego
modulepackage
0.0.9
Repository: https://github.com/zhs007/dashscopego.git
Documentation: pkg.go.dev

# README

dashscopego

阿里云平台 dashscope api 的 golang 封装 (非官方)

开通DashScope并创建API-KEY

Install:

go get -u github.com/zhs007/dashscopego

Examples:

通义千问

通义万相

Paraformer(语音识别)

模型插件调用

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

# 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