跳转至

Fine Tuning

Note

调用前请先构建客户端,构建代码如下:

OpenAiClient client = OpenAiClient.builder()
        .apiHost("https://api.openai.com")
        .apiKey(System.getProperty("openai.token"))
        .build();

System.getProperty("openai.token") 是访问 API 授权的关键。

创建微调作业


创建一个作业,用于微调给定数据集中的指定模型。

FineTuningEntity entity = FineTuningEntity.builder()
        .file("file-Rcxv6RrQXzTuJ2i2LY9kuChL")
        .build();
client.createFineTuningJob(entity);

返回:

{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "gpt-3.5-turbo-0613",
  "created_at": 1614807352,
  "fine_tuned_model": null,
  "organization_id": "org-123",
  "result_files": [],
  "status": "queued",
  "validation_file": null,
  "training_file": "file-abc123",
}

列出微调作业


列出组织的微调作业

client.fineTuningJobs();

返回:

{
  "object": "list",
  "data": [
    {
      "object": "fine_tuning.job.event",
      "id": "ft-event-TjX0lMfOniCZX64t9PUQT5hn",
      "created_at": 1689813489,
      "level": "warn",
      "message": "Fine tuning process stopping due to job cancellation",
      "data": null,
      "type": "message"
    },
    { ... },
    { ... }
  ], "has_more": true
}

列出微调事件


获取微调作业的状态更新。

client.fineTuningJobEvents("ftjob-abc123");

返回:

{
  "object": "list",
  "data": [
    {
      "object": "fine_tuning.job.event",
      "id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm",
      "created_at": 1692407401,
      "level": "info",
      "message": "Fine tuning job successfully completed",
      "data": null,
      "type": "message"
    },
    {
      "object": "fine_tuning.job.event",
      "id": "ft-event-tyiGuB72evQncpH87xe505Sv",
      "created_at": 1692407400,
      "level": "info",
      "message": "New fine-tuned model created: ft:gpt-3.5-turbo:openai::7p4lURel",
      "data": null,
      "type": "message"
    }
  ],
  "has_more": true
}

检索微调作业


获取有关微调作业的信息。

client.retrieveFineTuningJob("ftjob-abc123");

返回:

{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "davinci-002",
  "created_at": 1692661014,
  "finished_at": 1692661190,
  "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
  "organization_id": "org-123",
  "result_files": [
    "file-abc123"
  ],
  "status": "succeeded",
  "validation_file": null,
  "training_file": "file-abc123",
  "hyperparameters": {
    "n_epochs": 4,
  },
  "trained_tokens": 5768
}

取消微调


立即取消微调作业。

client.cancelFineTuningJob("ftjob-abc123");

返回:

{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "gpt-3.5-turbo-0613",
  "created_at": 1689376978,
  "fine_tuned_model": null,
  "organization_id": "org-123",
  "result_files": [],
  "hyperparameters": {
    "n_epochs":  "auto"
  },
  "status": "cancelled",
  "validation_file": "file-abc123",
  "training_file": "file-abc123"
}