9um3yhdu commited on
Commit
66ec3b5
·
verified ·
1 Parent(s): 7c6fabd

Update main.go

Browse files
Files changed (1) hide show
  1. main.go +2 -5
main.go CHANGED
@@ -127,6 +127,7 @@ func handleChat(w http.ResponseWriter, r *http.Request) {
127
  return "", fmt.Errorf("创建请求失败: %v", err)
128
  }
129
  req.Header.Set("Content-Type", "application/json")
 
130
 
131
  client := &http.Client{}
132
  resp, err := client.Do(req)
@@ -135,15 +136,11 @@ func handleChat(w http.ResponseWriter, r *http.Request) {
135
  }
136
  defer resp.Body.Close()
137
 
138
- log.Printf("Pear API 响应状态码: %d", resp.StatusCode)
139
-
140
  var fullMessage string
141
  scanner := bufio.NewScanner(resp.Body)
142
 
143
  for scanner.Scan() {
144
  line := scanner.Text()
145
- log.Printf("Pear API 原始响应: %s", line)
146
-
147
  if openAIReq.Stream {
148
  _, err = fmt.Fprintf(w, "%s\n", line)
149
  if err != nil {
@@ -243,4 +240,4 @@ func writeSSE(w http.ResponseWriter, data interface{}) error {
243
  }
244
 
245
  return nil
246
- }
 
127
  return "", fmt.Errorf("创建请求失败: %v", err)
128
  }
129
  req.Header.Set("Content-Type", "application/json")
130
+ req.Header.Set("Authorization", "Bearer pearapifreechat")
131
 
132
  client := &http.Client{}
133
  resp, err := client.Do(req)
 
136
  }
137
  defer resp.Body.Close()
138
 
 
 
139
  var fullMessage string
140
  scanner := bufio.NewScanner(resp.Body)
141
 
142
  for scanner.Scan() {
143
  line := scanner.Text()
 
 
144
  if openAIReq.Stream {
145
  _, err = fmt.Fprintf(w, "%s\n", line)
146
  if err != nil {
 
240
  }
241
 
242
  return nil
243
+ }