Browse Source

add loggers

kevin 1 year ago
parent
commit
426863946a
1 changed files with 8 additions and 1 deletions
  1. 8 1
      main.py

+ 8 - 1
main.py

@@ -246,6 +246,7 @@ def train():
         return train_with_id(job_id=request.form['job_id'])
     elif 'train_file' in request.files:
         train_file = request.files['train_file']
+        app.logger.info({"filename": train_file.filename})
         openai_file = None
         if train_file.filename.split('.')[1] == 'jsonl':
             openai_file = train_file.stream.read()
@@ -255,6 +256,7 @@ def train():
             openai_file = alpaca_to_chatgpt(train_file)
         if 'prev_model' in request.form:
             prev_model = request.form['prev_model']
+        app.logger.info(f"Previous model: {prev_model}")
         if 'mock' not in request.form:
             f = app.openai_client.files.create(
                 file=openai_file,
@@ -267,21 +269,26 @@ def train():
                     "n_epochs": 5
                 }
             )
+            app.logger.info({"mock": "yes", "status": job.status, "job_id": job.id})
             return {"status": job.status, "job_id": job.id}
         else:
+            app.logger.info({"mock": "yes", "status": "ok"})
             return {"status": "ok"}
     else:
+        app.logger.error({"status": "error", "message": "Training file not found"})
         return {"status": "error", "message": "Training file not found"}
 
 def train_with_id(job_id):
     try:
         job = app.openai_client.fine_tuning.jobs.retrieve(job_id)
         if job.fine_tuned_model is None:
+            app.logger.info({"job_id": job_id, "status": job.status})
             return {"status": job.status}
         else:
+            app.logger.info({"job_id": job_id, "status": job.status, "model_name": job.fine_tuned_model})
             return {"status": job.status, "model_name": job.fine_tuned_model}
     except Exception as error_print:
-        print(error_print)
+        app.logger.error(error_print)
         return {"status": "Could not find job from id"}