package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

// 创建请求参数的结构体
type ModelSettings struct {
	GptModelPath    string `json:"gpt_model_path"`
	SovitsModelPath string `json:"sovits_model_path"`
}

// 设置音色模型的函数
func setModel() {
	// 设置请求的URL
	url := "http://58.34.54.45:17666/set_model"

	// 构造请求体
	settings := ModelSettings{
		GptModelPath:    "/psycheEpic/GPT-SoVITS/GPT_weights/huainvren-e20.ckpt",
		SovitsModelPath: "/psycheEpic/GPT-SoVITS/SoVITS_weights/huainvren_e51_s816.pth",
	}

	// 将结构体转换为JSON格式的字节切片
	requestBody, err := json.Marshal(settings)
	if err != nil {
		fmt.Println("Error marshalling JSON: ", err)
		return
	}

	// 创建POST请求
	resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
	if err != nil {
		fmt.Println("Error sending request: ", err)
		return
	}
	defer resp.Body.Close()

	// 读取并打印响应体
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response body: ", err)
		return
	}

	fmt.Println("Response:", string(body))
}

func main() {
	setModel()
}
