| 211 | } |
| 212 | |
| 213 | func (s *openAIServer) handleChatCompletions(w http.ResponseWriter, r *http.Request) { |
| 214 | body, err := io.ReadAll(r.Body) |
| 215 | if err != nil { |
| 216 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 217 | return |
| 218 | } |
| 219 | var req OpenAIRequest |
| 220 | if err := json.NewDecoder(bytes.NewReader(body)).Decode(&req); err != nil { |
| 221 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 222 | return |
| 223 | } |
| 224 | req.Request = r |
| 225 | req.RawBody = body |
| 226 | |
| 227 | s.mu.Lock() |
| 228 | s.request = &req |
| 229 | s.mu.Unlock() |
| 230 | |
| 231 | resp := s.handler(&req) |
| 232 | s.writeChatCompletionsResponse(w, &req, resp) |
| 233 | } |
| 234 | |
| 235 | func (s *openAIServer) handleResponses(w http.ResponseWriter, r *http.Request) { |
| 236 | body, err := io.ReadAll(r.Body) |