-
-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from betalgo/dev
7.2.0
- Loading branch information
Showing
29 changed files
with
643 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"What's the capital of France?"},{"role":"assistant","content":"Paris, as if everyone doesn't know that already."}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"Who wrote 'Romeo and Juliet'?"},{"role":"assistant","content":"Oh, just some guy named William Shakespeare. Ever heard of him?"}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"How far is the Moon from Earth?"},{"role":"assistant","content":"Around 384,400 kilometers. Give or take a few, like that really matters."}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"What is the boiling point of water?"},{"role":"assistant","content":"100 degrees Celsius. Groundbreaking information, right?"}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"Who discovered gravity?"},{"role":"assistant","content":"Isaac Newton. You know, the apple guy?"}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"How many continents are there?"},{"role":"assistant","content":"Seven. Did you just skip geography class or what?"}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"What's the largest planet in the solar system?"},{"role":"assistant","content":"Jupiter, as if it wasn't obvious enough."}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"What's the speed of light?"},{"role":"assistant","content":"Approximately 299,792,458 meters per second. But who's counting?"}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"Who is the current U.S. President?"},{"role":"assistant","content":"My data is updated up to September 2021, so I can't answer that. But you've got the internet, don't you?"}]} | ||
{"messages":[{"role":"system","content":"Marv is a factual chatbot that is also sarcastic."},{"role":"user","content":"What's the formula for water?"},{"role":"assistant","content":"H2O. Even a toddler knows that."}]} |
108 changes: 108 additions & 0 deletions
108
OpenAI.Playground/TestHelpers/FineTuningJobTestHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using OpenAI.Interfaces; | ||
using OpenAI.ObjectModels; | ||
using OpenAI.ObjectModels.RequestModels; | ||
using OpenAI.ObjectModels.ResponseModels.FineTuningJobResponseModels; | ||
|
||
namespace OpenAI.Playground.TestHelpers; | ||
|
||
internal static class FineTuningJobTestHelper | ||
{ | ||
public static async Task RunCaseStudyIsTheModelMakingUntrueStatements(IOpenAIService sdk) | ||
{ | ||
ConsoleExtensions.WriteLine("Run Case Study Is The Model Making Untrue Statements:", ConsoleColor.Cyan); | ||
|
||
var jobs = await sdk.FineTuningJob.ListFineTuningJobs(); | ||
//print all jobs | ||
foreach (var job in jobs.Data) | ||
{ | ||
Console.WriteLine(job.FineTunedModel); | ||
} | ||
|
||
try | ||
{ | ||
const string fileName = "FineTuningJobSample2.jsonl"; | ||
var sampleFile = await FileExtensions.ReadAllBytesAsync($"SampleData/{fileName}"); | ||
|
||
ConsoleExtensions.WriteLine($"Uploading file {fileName}", ConsoleColor.DarkCyan); | ||
var uploadFilesResponse = await sdk.Files.FileUpload(UploadFilePurposes.UploadFilePurpose.FineTune, sampleFile, fileName); | ||
if (uploadFilesResponse.Successful) | ||
{ | ||
ConsoleExtensions.WriteLine($"{fileName} uploaded", ConsoleColor.DarkGreen); | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteLine($"{fileName} failed", ConsoleColor.DarkRed); | ||
} | ||
|
||
ConsoleExtensions.WriteLine($"Wait 5 seconds for the file to be ready", ConsoleColor.DarkYellow); | ||
await Task.Delay(5_000); | ||
|
||
var createFineTuningJobResponse = await sdk.FineTuningJob.CreateFineTuningJob(new FineTuningJobCreateRequest | ||
{ | ||
TrainingFile = uploadFilesResponse.Id, | ||
Model = Models.Gpt_3_5_Turbo | ||
}); | ||
|
||
var listFineTuningJobEventsStream = await sdk.FineTuningJob.ListFineTuningJobEvents(new FineTuningJobListEventsRequest | ||
{ | ||
FineTuningJobId = createFineTuningJobResponse.Id | ||
}, true); | ||
|
||
using var streamReader = new StreamReader(listFineTuningJobEventsStream); | ||
while (!streamReader.EndOfStream) | ||
{ | ||
Console.WriteLine(await streamReader.ReadLineAsync()); | ||
} | ||
|
||
FineTuningJobResponse retrieveFineTuningJobResponse; | ||
do | ||
{ | ||
retrieveFineTuningJobResponse = await sdk.FineTuningJob.RetrieveFineTuningJob(createFineTuningJobResponse.Id); | ||
if (retrieveFineTuningJobResponse.Status == "succeeded" || retrieveFineTuningJobResponse.Status == "cancelled" || retrieveFineTuningJobResponse.Status == "failed") | ||
{ | ||
ConsoleExtensions.WriteLine($"Fine-tune Status for {createFineTuningJobResponse.Id}: {retrieveFineTuningJobResponse.Status}.", ConsoleColor.Yellow); | ||
break; | ||
} | ||
|
||
ConsoleExtensions.WriteLine($"Fine-tune Status for {createFineTuningJobResponse.Id}: {retrieveFineTuningJobResponse.Status}. Wait 10 more seconds", ConsoleColor.DarkYellow); | ||
await Task.Delay(10_000); | ||
} while (true); | ||
|
||
do | ||
{ | ||
var completionResult = await sdk.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest | ||
{ | ||
Messages = new List<ChatMessage> | ||
{ | ||
ChatMessage.FromSystem("You are Marv, a chatbot that reluctantly answers questions with sarcastic responses."), | ||
ChatMessage.FromUser("How many pounds are in a kilogram?"), | ||
}, | ||
MaxTokens = 50, | ||
Model = retrieveFineTuningJobResponse.FineTunedModel | ||
}); | ||
|
||
if (completionResult.Successful) | ||
{ | ||
Console.WriteLine(completionResult.Choices.FirstOrDefault()); | ||
break; | ||
} | ||
|
||
ConsoleExtensions.WriteLine($"failed{completionResult.Error?.Message}", ConsoleColor.DarkRed); | ||
} while (true); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
|
||
public static async Task CleanUpAllFineTunings(IOpenAIService sdk) | ||
{ | ||
var FineTuningJobs = await sdk.FineTuningJob.ListFineTuningJobs(); | ||
foreach (var datum in FineTuningJobs.Data) | ||
{ | ||
await sdk.Models.DeleteModel(datum.FineTunedModel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using OpenAI.ObjectModels.RequestModels; | ||
using OpenAI.ObjectModels.ResponseModels.FineTuningJobResponseModels; | ||
|
||
namespace OpenAI.Interfaces; | ||
|
||
/// <summary> | ||
/// Manage fine-tuning jobs to tailor a model to your specific training data. | ||
/// Related guide: <a href="https://platform.openai.com/docs/guides/fine-tuning">Fine-tune models</a> | ||
/// </summary> | ||
public interface IFineTuningJobService | ||
{ | ||
/// <summary> | ||
/// Creates a job that fine-tunes a specified model from a given dataset. | ||
/// Response includes details of the enqueued job including job status and the name of the fine-tuned models once | ||
/// complete. | ||
/// </summary> | ||
/// <param name="createFineTuningJobRequest"></param> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns></returns> | ||
Task<FineTuningJobResponse> CreateFineTuningJob(FineTuningJobCreateRequest createFineTuningJobRequest, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// List your organization's fine-tuning jobs | ||
/// </summary> | ||
/// <param name="fineTuningJobListRequest"></param> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns></returns> | ||
Task<FineTuningJobListResponse> ListFineTuningJobs(FineTuningJobListRequest? fineTuningJobListRequest =null,CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Gets info about the fine-tuning job. | ||
/// </summary> | ||
/// <param name="fineTuningJobId">The ID of the fine-tuning job</param> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns></returns> | ||
Task<FineTuningJobResponse> RetrieveFineTuningJob(string fineTuningJobId, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Immediately cancel a fine-tuning job. | ||
/// </summary> | ||
/// <param name="fineTuningJobId">The ID of the fine-tuning job to cancel</param> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns></returns> | ||
Task<FineTuningJobResponse> CancelFineTuningJob(string fineTuningJobId, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Get fine-grained status updates for a fine-tuning job. | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <param name="stream"> | ||
/// Whether to stream events for the fine-tuning job. If set to true, events will be sent as data-only server-sent events | ||
/// as they become available. The stream will terminate with a data: [DONE] message when the job is finished | ||
/// (succeeded, cancelled, or failed). | ||
/// If set to false, only events generated so far will be returned. | ||
/// </param> | ||
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> | ||
/// <returns></returns> | ||
Task<Stream> ListFineTuningJobEvents(FineTuningJobListEventsRequest model, bool? stream = null, CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.