openai-java
openai-java copied to clipboard
Fine tune request HTTP 400 error with the Java API but same parameters work with the CMD API.
Tried removing various parameters down to training file only, but same error.
All other Java API calls work fine e.g. Completion, Image, Embedding.
Here's my code:
public class ExampleFinetuning {
public static void main(String[] args) {
createFinetuneModel(
"D:/Projects/Visual Studio/GPT Fine Tuning/GPT Fine Tune Check/data/sentiment_prepared_train.jsonl",
"D:/Projects/Visual Studio/GPT Fine Tuning/GPT Fine Tune Check/data/sentiment_prepared_valid.jsonl",
"curie",
" positive ###",
"sentiment-230708");
/*
DOES NOT WORK - Exception in thread "main" retrofit2.adapter.rxjava2.HttpException: HTTP 400 Bad Request
But works with cmd :
openai api fine_tunes.create
-t "D:\Projects\Visual Studio\GPT Fine Tuning\GPT Fine Tune Check\data\sentiment_prepared_train.jsonl"
-v "D:\Projects\Visual Studio\GPT Fine Tuning\GPT Fine Tune Check\data\sentiment_prepared_valid.jsonl"
--compute_classification_metrics
--classification_positive_class " positive ###"
FYI - file size for sentiment_prepared_train.jsonl : 3518Kb
sentiment_prepared_valid.jsonl : 880kb
*/
}
public static String createFinetuneModel(String trainingfile, String validationfile, String model, String posClass, String suffix) {
OpenAiService service = new OpenAiService(key,0);
FineTuneRequest fineTuneRequest = FineTuneRequest.builder()
.trainingFile(trainingfile)
.validationFile(validationfile)
.classificationPositiveClass(posClass)
.computeClassificationMetrics(true)
.model(model)
.suffix(suffix)
.build();
FineTuneResult finalRequest = service.createFineTune(fineTuneRequest);
Date createDate = new Date(finalRequest.getCreatedAt());
String ret = finalRequest.getFineTunedModel() + " was created at " + createDate + " with status: "+ finalRequest.getStatus();
System.out.println(ret);
return ret;
}
}
Not sure this is helpful, but it sounds like a path handling difference between python and java. AKA the spaces in your directory names need to be double quoted.
Many thanks.
I did consider that, and tried to putting the files in my root D:, so the path was: "D:/sentiment_prepared_train.jsonl" but got the same error.
If it has worked for others, I would guess it must be environmental also.
Yeah, that seems odd. Maybe try doing gradle test from a powershell. See if the default fine tune test works.
https://github.com/TheoKanning/openai-java/blob/038e42c0e679af7652ed9a33fd3d3e87160d248b/service/src/test/java/com/theokanning/openai/service/FineTuneTest.java#L24
Only other guess is maybe try "ada" instead of "curie", though the documentation says all should be supported, but that's the only diff I see between the tests and your code.
https://platform.openai.com/docs/guides/fine-tuning
Ok thanks.
I have just tried "ada" as the model, but got the same result.
Will dig in, and if I can work it out I will update.