-
Notifications
You must be signed in to change notification settings - Fork 13
Description
package main
import (
"context"
"fmt"
"github.com/devinyf/dashscopego"
"github.com/devinyf/dashscopego/qwen"
)
func main() {
// 定义 Model,API-KEY, 请求客户端
model := qwen.QwenTurbo
token := "sk-*********************"
if token == "" {
panic("token is empty")
}
cli := dashscopego.NewTongyiClient(model, token)
// 定义请求内容.
// 请求具体字段说明请查阅官方文档的 'HTTP调用接口' 部分.
content := qwen.TextContent{Text: "讲个冷笑话"}
input := dashscopego.TextInput{
Messages: []dashscopego.TextMessage{
{Role: qwen.RoleUser, Content: &content},
},
}
req := &dashscopego.TextRequest{
Input: input, // 请求内容
//StreamingFn: streamCallbackFn, // 流式输出的回调函数, 默认为 nil, 表示不使用流式输出.
Parameters: &qwen.Parameters{
ResultFormat: "text",
MaxTokens: 1000,
//Temperature: agentCfg.Temperature,
//TopP: agentCfg.TopP,
//TopK: agentCfg.TopK,
},
}
// 发送请求.
ctx := context.TODO()
resp, err := cli.CreateCompletion(ctx, req)
if err != nil {
panic(err)
}
/*
获取结果.
详细字段说明请查阅 'HTTP调用接口 -> 出参描述'.
如果request中没有定义流式输出的回调函数 StreamingFn, 则使用此方法获取应答内容.
*/
fmt.Println(resp.Output.Choices[0].Message.Content.ToString())
// 获取 RequestcID, Token 消耗, 结束标识等信息
fmt.Println(resp.RequestID)
fmt.Println(resp.Output.Choices[0].FinishReason)
fmt.Println(resp.Usage.TotalTokens)
}
参考文档案例测试,以上main函数,执行结果为:
panic: empty response
goroutine 1 [running]:
main.main()
/Users/admin/go_workspace/space/src/cube_lite/claro/llm_rsa_api_key.go:58 +0x2b8