Skip to content

Commit

Permalink
Following API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JZO001 committed May 17, 2023
1 parent b319770 commit 8bc0354
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Forge.OpenAI/Forge.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 34,13 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/JZO001/Forge.OpenAI</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>1.1.4.0</AssemblyVersion>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageTags>OpenAI, Azure-OpenAI, Azure-OpenAI-API, ChatGPT, GPT4, GPT-4, GPT-4-API, GPT35, GPT-35, GPT-35-API, GPT3, GPT-3, GPT-3-API, DALLE, DALL-E, DALL-E-API, OpenAi, openAi, azure, Whisper, AI, ML, dotnet, dotnetcore, machine-learning, sdk, forge, translation, transcription, chat, chatbot, image, image-processing, embedding, embedding-models, moderation, text-completion, fine-tune, dotNet, csharp</PackageTags>
<PackageReleaseNotes>
v1.1.5 - Name field for the chat message. PromptLossWeight field of FineTuneCreateRequest is not mandatory (nullable). Azure endpoint default API version changed.
v1.1.4 - Added support for IHttpClientFactory. Now short-lived, long-lived and custom HttpClient instances can be used. Last one is useful for MAUI Android clients.
v1.1.3 - Added optimizations for .NET 7
</PackageReleaseNotes>
Expand Down
30 changes: 21 additions & 9 deletions Forge.OpenAI/Models/ChatCompletions/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 12,13 @@ public class ChatMessage
/// <summary>Initializes a new instance of the <see cref="ChatMessage" /> class.</summary>
/// <param name="role">The role.</param>
/// <param name="content">The content.</param>
/// <param name="name">The name of the author of this message (optional)</param>
[JsonConstructor]
public ChatMessage(string role, string content)
public ChatMessage(string role, string content, string name = null)
{
Role = role;
Content = content;
Name = name;
}

/// <summary>
Expand All @@ -31,53 33,63 @@ public ChatMessage(string role, string content)
[JsonPropertyName("content")]
public string Content { get; set; }

/// <summary>
/// The name of the author of this message (optional). May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>Creates the chat message with role and content specified</summary>
/// <param name="role">The role.</param>
/// <param name="content">The content.</param>
/// <param name="name">The name of the author of this message (optional)</param>
/// <returns>
/// ChatMessage
/// </returns>
/// <exception cref="System.ArgumentException">
/// Invalid role type provided. Please specify a valid value from the following items ${string.Join(", ", ChatMessageRoleTypes.ValidRoleTypes)} - role
/// </exception>
public static ChatMessage Create(string role, string content)
public static ChatMessage Create(string role, string content, string name = null)
{
if (!ChatMessageRoleTypes.ValidRoleTypes.Contains(role))
{
throw new ArgumentException($"Invalid role type provided. Please specify a valid value from the following items ${string.Join(", ", ChatMessageRoleTypes.ValidRoleTypes)}", nameof(role));
}

return new ChatMessage(role, content);
return new ChatMessage(role, content, name);
}

/// <summary>Creates the chat message with the given content as a System role.</summary>
/// <param name="content">The content.</param>
/// <param name="name">The name of the author of this message (optional)</param>
/// <returns>
/// ChatMessage
/// </returns>
public static ChatMessage CreateFromSystem(string content)
public static ChatMessage CreateFromSystem(string content, string name = null)
{
return new ChatMessage(ChatMessageRoleTypes.SYSTEM, content);
return new ChatMessage(ChatMessageRoleTypes.SYSTEM, content, name);
}

/// <summary>Creates the chat message with the given content as an Assistant role.</summary>
/// <param name="content">The content.</param>
/// <param name="name">The name of the author of this message (optional)</param>
/// <returns>
/// ChatMessage
/// </returns>
public static ChatMessage CreateFromAssistant(string content)
public static ChatMessage CreateFromAssistant(string content, string name = null)
{
return new ChatMessage(ChatMessageRoleTypes.ASSISTANT, content);
return new ChatMessage(ChatMessageRoleTypes.ASSISTANT, content, name);
}

/// <summary>Creates the chat message with the given content as a User role.</summary>
/// <param name="content">The content.</param>
/// <param name="name">The name of the author of this message (optional)</param>
/// <returns>
/// ChatMessage
/// </returns>
public static ChatMessage CreateFromUser(string content)
public static ChatMessage CreateFromUser(string content, string name = null)
{
return new ChatMessage(ChatMessageRoleTypes.USER, content);
return new ChatMessage(ChatMessageRoleTypes.USER, content, name);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Forge.OpenAI/Models/FineTunes/FineTuneCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 123,7 @@ public FineTuneCreateRequest(
/// <see href="https://beta.openai.com/docs/api-reference/fine-tunes/create#fine-tunes/create-prompt_loss_weight" />
/// </summary>
[JsonPropertyName("prompt_loss_weight")]
public double PromptLossWeight { get; set; }
public double? PromptLossWeight { get; set; }

/// <summary>
/// If set, we calculate classification-specific metrics such as accuracy and F-1 score using the validation set at the end of every epoch. These metrics can be viewed in the <a href="https://beta.openai.com/docs/api-reference/fine-tunes/create#fine-tunes/create-compute_classification_metrics">results file</a>. <br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@ public static class AzureProviderEndpointApiVersions
{

/// <summary>The default</summary>
public const string Default = V2022_12_01;
public const string Default = V2023_13_15_PREVIEW;

/// <summary>2022-12-01</summary>
public const string V2022_12_01 = "2022-12-01";
Expand Down

0 comments on commit 8bc0354

Please sign in to comment.