Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
KATTA-00 committed Aug 14, 2024
1 parent 2e85221 commit 623d863
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 660 deletions.
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.9.2"
org = "ballerinax"
name = "openai.finetunes"
version = "1.0.7"
version = "1.0.5"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = [] # TODO: Add keywords
Expand Down
6 changes: 0 additions & 6 deletions examples/Sarcastic-bot/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ distribution = "2201.9.2"

[build-options]
observabilityIncluded = true

[[dependency]]
org = "ballerinax"
name = "openai.finetunes"
version = "1.0.7"
repository = "local"
312 changes: 0 additions & 312 deletions examples/Sarcastic-bot/Dependencies.toml

This file was deleted.

23 changes: 11 additions & 12 deletions examples/Sarcastic-bot/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ configurable string token = ?;
const SERVICE_URL = "https://api.openai.com/v1";
const TRAINING_FILENAME = "training.jsonl";
const VALIDATION_FILENAME = "validation.jsonl";
const TRAINING_FILEPATH = "./data/" + trainingFileName;
const VALIDATION_FILEPATH = "./data/" + validationFileName;
const TRAINING_FILEPATH = "./data/" + TRAINING_FILENAME;
const VALIDATION_FILEPATH = "./data/" + VALIDATION_FILENAME;

final finetunes:ConnectionConfig config = {auth: {token}};
final finetunes:Client openAIFinetunes = check new finetunes:Client(config, serviceUrl);
final finetunes:Client openAIFinetunes = check new finetunes:Client(config, SERVICE_URL);

public function main() returns error? {

byte[] trainingFileContent = check io:fileReadBytes(trainingFilePath);
byte[] validationFileContent = check io:fileReadBytes(validationFilePath);
byte[] trainingFileContent = check io:fileReadBytes(TRAINING_FILEPATH);
byte[] validationFileContent = check io:fileReadBytes(VALIDATION_FILEPATH);

finetunes:CreateFileRequest trainingFileRequest = {
file: {fileContent: trainingFileContent, fileName: trainingFileName},
file: {fileContent: trainingFileContent, fileName: TRAINING_FILENAME},
purpose: "fine-tune"
};
finetunes:CreateFileRequest validationFileRequest = {
file: {fileContent: validationFileContent, fileName: validationFileName},
file: {fileContent: validationFileContent, fileName: VALIDATION_FILENAME},
purpose: "fine-tune"
};

Expand Down Expand Up @@ -72,30 +72,29 @@ public function main() returns error? {
check openAIFinetunes->/fine_tuning/jobs/[fineTuneJobId].get();

io:print("Validating files...");
while (fineTuneJob.status == "validating_files") {
while fineTuneJob.status == "validating_files" {
io:print(".");
fineTuneJob = check openAIFinetunes->/fine_tuning/jobs/[fineTuneJobId].get();

runtime:sleep(1);
}

io:print("\nFiles validated successfully.");
while (fineTuneJob.status == "queued") {
while fineTuneJob.status == "queued" {
io:print(".");
fineTuneJob = check openAIFinetunes->/fine_tuning/jobs/[fineTuneJobId].get();
runtime:sleep(1);
}

io:println("\nTraining...");
finetunes:ListFineTuningJobEventsResponse eventsResponse;
while (fineTuneJob.status == "running") {
while fineTuneJob.status == "running" {
fineTuneJob = check openAIFinetunes->/fine_tuning/jobs/[fineTuneJobId].get();
eventsResponse = check openAIFinetunes->/fine_tuning/jobs/[fineTuneJobId]/events.get();
io:println(eventsResponse.data[0].message);
runtime:sleep(1);
}

if (fineTuneJob.status != "succeeded") {
if fineTuneJob.status != "succeeded" {
io:println("Fine-tuning job failed.");
return;
}
Expand Down
Loading

0 comments on commit 623d863

Please sign in to comment.