Skip to content

Conversation

cnaples79
Copy link

Summary

  • Implements CLI tools for chat fine-tuning as requested in OpenAI CLI Tools for Chat Fine-Tuning #622
  • Adds openai tools chat_fine_tunes.prepare_data for data validation and preparation
  • Adds openai api chat_fine_tunes.* commands as convenience aliases

Changes Made

  • Created src/openai/cli/_tools/chat_fine_tunes.py with data preparation functionality
  • Created src/openai/cli/_api/chat_fine_tunes/ module with API command aliases
  • Added chat-specific validators in src/openai/lib/_validators.py
  • Updated registration files to include new commands

Test Plan

  • Syntax validation passes for all new files
  • Commands properly registered in CLI structure
  • Chat message format validation implemented
  • API commands delegate to existing fine_tuning.jobs implementation

The implementation follows the existing patterns in the codebase and provides the interface proposed by @henriqueln7 in the issue comments.

Fixes #622

This implements the feature requested in issue openai#622 to provide CLI tools
for chat fine-tuning that work with the new chat message format.

Added functionality:
- `openai tools chat_fine_tunes.prepare_data` for validating and preparing
  chat fine-tuning data in the messages format
- `openai api chat_fine_tunes.*` commands (create, list, get, cancel) as
  convenience aliases for the existing fine_tuning.jobs commands
- Chat-specific validators that check for proper message format with
  role and content fields
- Support for system, user, and assistant roles

The tools work with JSONL files containing messages arrays, which is the
format required for chat fine-tuning with the new API.

Fixes openai#622
@cnaples79 cnaples79 requested a review from a team as a code owner September 23, 2025 11:46
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines +1 to +13
from __future__ import annotations

from typing import TYPE_CHECKING
from argparse import ArgumentParser

from .chat_fine_tunes import jobs

if TYPE_CHECKING:
from argparse import _SubParsersAction


def register(subparser: _SubParsersAction[ArgumentParser]) -> None:
jobs.register(subparser) No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Avoid circular import in chat_fine_tunes CLI module

The new alias module is defined in cli/_api/chat_fine_tunes.py while a package with the same name (cli/_api/chat_fine_tunes/) contains jobs.py. When _api/_main imports chat_fine_tunes, Python loads this file and the statement from .chat_fine_tunes import jobs resolves to the module itself rather than the sibling package, leaving jobs undefined and raising ImportError: cannot import name 'jobs' from partially initialized module .... As a result, none of the chat_fine_tunes commands can be registered. The alias module needs a different name or should be removed in favour of the package so the import resolves correctly.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAI CLI Tools for Chat Fine-Tuning
1 participant