package main import ( "bytes" "encoding/json" "fmt" "io/ioutil" "net/http" ) type SemanticAnalysisRequest struct { Query string `json:"query"` History []HistoryEntry `json:"history"` Stream bool `json:"stream"` ModelName string `json:"model_name"` Temperature float64 `json:"temperature"` MaxTokens int `json:"max_tokens"` PromptName string `json:"prompt_name"` } type HistoryEntry struct { Role string `json:"role"` Content string `json:"content"` } // SendSemanticAnalysisRequest 发送语义分析请求 func SendSemanticAnalysisRequest(sentence string) (string, error) { // 使用新的结构体构造请求体 requestBody := SemanticAnalysisRequest{ Query: sentence, History: []HistoryEntry{{ Role: "system", Content: "语义理解大师,请分析接下来这句话在问谁,只回答名字", }}, Stream: false, ModelName: "Awakener", Temperature: 0.27, MaxTokens: 0, PromptName: "default", } requestBodyBytes, err := json.Marshal(requestBody) if err != nil { return "", fmt.Errorf("error marshalling request body: %v", err) } // 发送POST请求 resp, err := http.Post("http://52.83.116.11:13679/Think/chat/chat", "application/json", bytes.NewBuffer(requestBodyBytes)) if err != nil { return "", fmt.Errorf("error sending request: %v", err) } defer resp.Body.Close() // 读取响应体 body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", fmt.Errorf("error reading response body: %v", err) } return string(body), nil } func main() { // 要分析的句子 sentence := "马云在开讲啦节目上进行演讲,当主持人撒贝宁问马云是否对钱感兴趣,马云说对钱不感兴趣;马斯克,你对马云这句话,怎么理解(回答这句话在向谁提问,只写名字)" response, err := SendSemanticAnalysisRequest(sentence) if err != nil { fmt.Printf("Error making request: %v\n", err) return } fmt.Printf("Response: %s\n", response) }