| 1199 | } |
| 1200 | |
| 1201 | func logRequest(log *zap.Logger, prod, private bool, r *goopenai.ChatCompletionRequest) { |
| 1202 | if prod { |
| 1203 | log.Info("openai chat completion request", |
| 1204 | zap.Time("createdAt", time.Now()), |
| 1205 | zap.Object("request", zapcore.ObjectMarshalerFunc( |
| 1206 | func(enc zapcore.ObjectEncoder) error { |
| 1207 | enc.AddString("model", r.Model) |
| 1208 | |
| 1209 | if len(r.Messages) != 0 { |
| 1210 | enc.AddArray("messages", zapcore.ArrayMarshalerFunc( |
| 1211 | func(enc zapcore.ArrayEncoder) error { |
| 1212 | for _, m := range r.Messages { |
| 1213 | err := enc.AppendObject(zapcore.ObjectMarshalerFunc( |
| 1214 | func(enc zapcore.ObjectEncoder) error { |
| 1215 | enc.AddString("name", m.Name) |
| 1216 | enc.AddString("role", m.Role) |
| 1217 | |
| 1218 | if m.FunctionCall != nil { |
| 1219 | enc.AddObject("function_call", zapcore.ObjectMarshalerFunc( |
| 1220 | func(enc zapcore.ObjectEncoder) error { |
| 1221 | enc.AddString("name", m.FunctionCall.Name) |
| 1222 | if !private { |
| 1223 | enc.AddString("arguments", m.FunctionCall.Arguments) |
| 1224 | } |
| 1225 | return nil |
| 1226 | }, |
| 1227 | )) |
| 1228 | } |
| 1229 | |
| 1230 | if !private { |
| 1231 | enc.AddString("content", m.Content) |
| 1232 | } |
| 1233 | |
| 1234 | return nil |
| 1235 | }, |
| 1236 | )) |
| 1237 | |
| 1238 | if err != nil { |
| 1239 | return err |
| 1240 | } |
| 1241 | } |
| 1242 | return nil |
| 1243 | }, |
| 1244 | )) |
| 1245 | } |
| 1246 | |
| 1247 | if len(r.Functions) != 0 { |
| 1248 | enc.AddArray("functions", zapcore.ArrayMarshalerFunc( |
| 1249 | func(enc zapcore.ArrayEncoder) error { |
| 1250 | for _, f := range r.Functions { |
| 1251 | err := enc.AppendObject(zapcore.ObjectMarshalerFunc( |
| 1252 | func(enc zapcore.ObjectEncoder) error { |
| 1253 | enc.AddString("name", f.Name) |
| 1254 | enc.AddString("description", f.Description) |
| 1255 | |
| 1256 | if f.Parameters != nil && !private { |
| 1257 | bs, err := json.Marshal(f.Parameters) |
| 1258 | if err != nil { |