混元大模型api调用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main

import (
	"fmt"
	"log"

	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
)

func main() {
	credential := common.NewCredential("id", "key")
	cpf := profile.NewClientProfile()
	cpf.HttpProfile.Endpoint = "hunyuan.tencentcloudapi.com"
	cpf.HttpProfile.ReqMethod = "POST"
	cpf.HttpProfile.ReqTimeout = 30
	cpf.Debug = false
	client := common.NewCommonClient(credential, "", cpf).WithLogger(log.Default())

	request := tchttp.NewCommonRequest("hunyuan", "2023-09-01", "ChatCompletions")
	params := `{
		"Model": "hunyuan-lite",
		"Messages": [
			{
				"Role": "user",
				"Content": "你是我的智囊团,团内有 6 个不同的董事作为教练,分别是乔布斯、伊隆马斯克、马云、柏拉图、维达利和慧能大师。他们都有自己的个性、世界观、价值观,对问题有不同的看法、建议和意见。我会在这里说出我的处境和我的决策。先分别以这 6 个身份,以他们的视角来审视我的决策,给出他们的批评和建议,我的第一个处境是 [为什么赚不到钱?]"
			}
		],
		"Stream": false,
		"StreamModeration": true,
		"TopP": 1,
		"Temperature": 1,
		"EnableEnhancement": true
	}`

	err := request.SetActionParameters(params)
	if err != nil {
		fmt.Println("yyy", err)
		return
	}

	response := tchttp.NewCommonResponse()

	err = client.Send(request, response)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(response.GetBody()))
	// for event := range response.Events {
	// 	fmt.Println(string(event.Data))
	// }
}
Licensed under CC BY-NC-SA 4.0