Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.7.0 #635

Merged
merged 17 commits into from
Sep 23, 2024
Merged

8.7.0 #635

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
//await AudioTestHelper.RunSimpleAudioCreateTranslationTest(sdk);
//await AudioTestHelper.RunSimpleAudioCreateSpeechTest(sdk);

//await ChatCompletionTestHelper.RunChatReasoningModel(sdk);
//await ModelTestHelper.FetchModelsTest(sdk);
//await EditTestHelper.RunSimpleEditCreateTest(sdk);
//await ImageTestHelper.RunSimpleCreateImageTest(sdk);
Expand Down
28 changes: 28 additions & 0 deletions OpenAI.Playground/TestHelpers/AssistantHelpers/VectorTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,34 @@ public static async Task CreateVector(IOpenAIService openAI)
}
}

public static async Task CreateVectorWithChunkingStrategy(IOpenAIService openAI)
{
ConsoleExtensions.WriteLine("Create Vector Testing is starting:", ConsoleColor.Cyan);
var result = await openAI.Beta.VectorStores.CreateVectorStore(new()
{
Name = "Support FAQ",
ChunkingStrategy = new()
{
Type = StaticValues.VectorStoreStatics.ChunkingStrategyType.Static,
StaticParameters = new()
{
ChunkOverlapTokens = 400,
MaxChunkSizeTokens = 800
}
}
});

if (result.Successful)
{
CreatedVectorId = result.Id;
ConsoleExtensions.WriteLine($"Vector Created Successfully with ID: {result.Id}", ConsoleColor.Green);
}
else
{
ConsoleExtensions.WriteError(result.Error);
}
}

public static async Task ListVectors(IOpenAIService openAI)
{
ConsoleExtensions.WriteLine("List Vectors Testing is starting:", ConsoleColor.Cyan);
Expand Down
74 changes: 48 additions & 26 deletions OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,43 +457,29 @@ public static async Task RunChatWithJsonSchemaResponseFormat(IOpenAIService sdk)
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are a helpful math tutor. Guide the user through the solution step by step."),
ChatMessage.FromUser("how can I solve 8x + 7 = -23"),
ChatMessage.FromUser("how can I solve 8x + 7 = -23")
},
Model = "gpt-4o-2024-08-06",
ResponseFormat = new ResponseFormat()
ResponseFormat = new()
{
Type = StaticValues.CompletionStatics.ResponseFormat.JsonSchema,
JsonSchema = new()
{
Name = "math_response",
Strict = true,
Schema = PropertyDefinition.DefineObject(
new Dictionary<string, PropertyDefinition>
Schema = PropertyDefinition.DefineObject(new Dictionary<string, PropertyDefinition>
{
{
"steps", PropertyDefinition.DefineArray(PropertyDefinition.DefineObject(new Dictionary<string, PropertyDefinition>
{
"steps", PropertyDefinition.DefineArray(
PropertyDefinition.DefineObject(
new Dictionary<string, PropertyDefinition>
{
{ "explanation", PropertyDefinition.DefineString("The explanation of the step") },
{ "output", PropertyDefinition.DefineString("The output of the step") }
},
new List<string> { "explanation", "output" },
false,
"A step in the mathematical process",
null
)
)
},
{
"final_answer", PropertyDefinition.DefineString("The final answer of the mathematical process")
}
{ "explanation", PropertyDefinition.DefineString("The explanation of the step") },
{ "output", PropertyDefinition.DefineString("The output of the step") }
}, new List<string> { "explanation", "output" }, false, "A step in the mathematical process", null))
},
new List<string> { "steps", "final_answer" },
false,
"Response containing steps and final answer of a mathematical process",
null
)
{
"final_answer", PropertyDefinition.DefineString("The final answer of the mathematical process")
}
}, new List<string> { "steps", "final_answer" }, false, "Response containing steps and final answer of a mathematical process", null)
}
}
});
Expand All @@ -518,4 +504,40 @@ public static async Task RunChatWithJsonSchemaResponseFormat(IOpenAIService sdk)
throw;
}
}

public static async Task RunChatReasoningModel(IOpenAIService sdk)
{
ConsoleExtensions.WriteLine("Chat Completion Reasoning Testing is starting:", ConsoleColor.Cyan);
try
{
var completionResult = await sdk.ChatCompletion.CreateCompletion(new()
{
Messages = [
ChatMessage.FromUser("Write a bash script that takes a matrix represented as a string with format '[1,2],[3,4],[5,6]' and prints the transpose in the same format.")
],
MaxCompletionTokens = 2000,
Model = Models.O1_preview
});

if (completionResult.Successful)
{
Console.WriteLine(completionResult.Choices.First().Message.Content);
Console.WriteLine("Used:" + (completionResult.Usage.CompletionTokensDetails?.ReasoningTokens??0) + " reasoning tokens" );
}
else
{
if (completionResult.Error == null)
{
throw new("Unknown Error");
}

Console.WriteLine($"{completionResult.Error.Code}: {completionResult.Error.Message}");
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
42 changes: 33 additions & 9 deletions OpenAI.SDK/ObjectModels/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public enum Model

Text_moderation_007,
Text_moderation_latest,
Text_moderation_stable
Text_moderation_stable,
O1_preview,
O1_preview_2024_09_12,
O1_mini,
O1_mini_2024_09_12
}

public enum Subject
Expand Down Expand Up @@ -223,18 +227,18 @@ public enum Subject
public static string Gpt_4o_2024_05_13 => "gpt-4o-2024-05-13";

/// <summary>
/// Our affordable and intelligent small model for fast, lightweight tasks.
/// GPT-4o mini is cheaper and more capable than GPT-3.5 Turbo.
/// Currently points to gpt-4o-mini-2024-07-18.
/// 128,000 tokens Up to Oct 2023
/// Our affordable and intelligent small model for fast, lightweight tasks.
/// GPT-4o mini is cheaper and more capable than GPT-3.5 Turbo.
/// Currently points to gpt-4o-mini-2024-07-18.
/// 128,000 tokens Up to Oct 2023
/// </summary>
public static string Gpt_4o_mini => "gpt-4o-mini";

/// <summary>
/// Our affordable and intelligent small model for fast, lightweight tasks.
/// GPT-4o mini is cheaper and more capable than GPT-3.5 Turbo.
/// Currently points to gpt-4o-mini-2024-07-18.
/// 128,000 tokens Up to Oct 2023
/// Our affordable and intelligent small model for fast, lightweight tasks.
/// GPT-4o mini is cheaper and more capable than GPT-3.5 Turbo.
/// Currently points to gpt-4o-mini-2024-07-18.
/// 128,000 tokens Up to Oct 2023
/// </summary>
public static string Gpt_4o_mini_2024_07_18 => "gpt-4o-mini-2024-07-18";

Expand Down Expand Up @@ -383,6 +387,22 @@ public enum Subject
/// </summary>
public static string Tts_1_hd => "tts-1-hd";

/// <summary>
/// Reasoning model designed to solve hard problems across domains.
/// Released in Sep 2024.
/// </summary>
public static string O1_preview => "o1-preview";

/// <summary>
/// Faster and cheaper reasoning model particularly good at coding, math, and science.
/// Released in Sep 2024.
/// </summary>
public static string O1_mini => "o1-mini";

public static string O1_preview_2024_09_12 => "o1-preview-2024-09-12";

public static string O1_mini_2024_09_12 => "o1-mini-2024-09-12";

/// <summary>
/// This method does not guarantee returned model exists.
/// </summary>
Expand Down Expand Up @@ -482,6 +502,10 @@ public static string EnumToString(this Model model)
Model.Text_moderation_007 => TextModeration007,
Model.Text_moderation_latest => TextModerationLatest,
Model.Text_moderation_stable => TextModerationStable,
Model.O1_mini => O1_mini,
Model.O1_mini_2024_09_12 => O1_mini_2024_09_12,
Model.O1_preview => O1_preview,
Model.O1_preview_2024_09_12 => O1_preview_2024_09_12,
_ => throw new ArgumentOutOfRangeException(nameof(model), model, null)
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public IList<string>? StopCalculated
[JsonPropertyName("max_tokens")]
public int? MaxTokens { get; set; }


/// <summary>
/// An upper bound for the number of tokens that can be generated for a completion,
/// including visible output tokens and reasoning tokens.
/// </summary>
/// <see href="https://platform.openai.com/docs/api-reference/chat/create#chat-create-max_completion_tokens" />
[JsonPropertyName("max_completion_tokens")]
public int? MaxCompletionTokens { get; set; }

/// <summary>
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
/// increasing the model's likelihood to talk about new topics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ public class CreateVectorStoreFileBatchRequest
/// </summary>
[JsonPropertyName("file_ids")]
public List<string> FileIds { get; set; }

/// <summary>
/// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.
/// Only applicable if file_ids is non-empty.
/// </summary>
[JsonPropertyName("chunking_strategy")]
public ChunkingStrategy? ChunkingStrategy { get; set; }
}
39 changes: 39 additions & 0 deletions OpenAI.SDK/ObjectModels/RequestModels/CreateVectorStoreRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,43 @@ public class CreateVectorStoreRequest
/// </summary>
[JsonPropertyName("metadata")]
public Dictionary<string, string>? Metadata { get; set; }

/// <summary>
/// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.
/// Only applicable if file_ids is non-empty.
/// </summary>
[JsonPropertyName("chunking_strategy")]
public ChunkingStrategy? ChunkingStrategy { get; set; }
}

public class ChunkingStrategy
{
/// <summary>
/// The type of chunking strategy. Must be either "auto" or "static".
/// </summary>
[JsonPropertyName("type")]
public string Type { get; set; }

/// <summary>
/// The static chunking parameters. Required if type is "static".
/// </summary>
[JsonPropertyName("static")]
public StaticChunkingParameters? StaticParameters { get; set; }
}

public class StaticChunkingParameters
{
/// <summary>
/// The maximum number of tokens in each chunk. The default value is 800.
/// The minimum value is 100 and the maximum value is 4096.
/// </summary>
[JsonPropertyName("max_chunk_size_tokens")]
public int MaxChunkSizeTokens { get; set; }

/// <summary>
/// The number of tokens that overlap between chunks. The default value is 400.
/// Note that the overlap must not exceed half of max_chunk_size_tokens.
/// </summary>
[JsonPropertyName("chunk_overlap_tokens")]
public int ChunkOverlapTokens { get; set; }
}
3 changes: 2 additions & 1 deletion OpenAI.SDK/ObjectModels/RequestModels/ToolChoiceFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ToolChoice
{
public static ToolChoice None => new() { Type = StaticValues.CompletionStatics.ToolChoiceType.None };
public static ToolChoice Auto => new() { Type = StaticValues.CompletionStatics.ToolChoiceType.Auto };
public static ToolChoice Required => new() { Type = StaticValues.CompletionStatics.ToolChoiceType.Required };

/// <summary>
/// "none" is the default when no functions are present. <br />
Expand Down Expand Up @@ -91,4 +92,4 @@ public override void Write(Utf8JsonWriter writer, ToolChoiceOneOfType? value, Js
}
}
}
}
}
61 changes: 59 additions & 2 deletions OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ public class ToolDefinition
[JsonPropertyName("type")]
public string Type { get; set; }

/// <summary>
/// Structured Outputs for function calling can be enabled with a single parameter, just by supplying strict: true.
/// Please note: This field is not mentioned in the API documentation but is referenced in other documents.
/// </summary>
[JsonPropertyName("strict")]
public bool? Strict { get; set; }

/// <summary>
/// Overrides for the file search tool.
/// </summary>
[JsonPropertyName("file_search")]
public FileSearchTool? FileSearchTool { get; set; }

/// <summary>
/// A list of functions the model may generate JSON inputs for.
Expand Down Expand Up @@ -67,11 +79,56 @@ public static ToolDefinition DefineRetrieval()
};
}

public static ToolDefinition DefineFileSearch()
public static ToolDefinition DefineFileSearch(FileSearchTool? fileSearchTool = null)
{
return new()
{
Type = StaticValues.AssistantsStatics.ToolCallTypes.FileSearch
Type = StaticValues.AssistantsStatics.ToolCallTypes.FileSearch,
FileSearchTool = fileSearchTool
};
}
}

public class FileSearchTool
{
/// <summary>
/// The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for
/// gpt-3.5-turbo. This number should be between 1 and 50 inclusive.
/// Note that the file search tool may output fewer than max_num_results results.
/// <a href="https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings">
/// See the
/// file search tool documentation
/// </a>
/// for more information.
/// </summary>
[JsonPropertyName("max_num_results")]
public int? MaxNumberResults { get; set; }

/// <summary>
/// The ranking options for the file search. If not specified, the file search tool will use the auto ranker and a
/// score_threshold of 0.
/// See the
/// <a href="https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings">
/// file
/// search tool documentation
/// </a>
/// for more information.
/// </summary>
[JsonPropertyName("ranking_options")]
public RankingOptions? RankingOptions { get; set; }
}

public class RankingOptions
{
/// <summary>
/// The ranker to use for the file search. If not specified will use the auto ranker.
/// </summary>
[JsonPropertyName("ranker")]
public string? Ranker { get; set; }

/// <summary>
/// The score threshold for the file search. All values must be a floating point number between 0 and 1.
/// </summary>
[JsonPropertyName("score_threshold")]
public float ScoreThreshold { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace OpenAI.ObjectModels.ResponseModels;

public record CompletionTokensDetails
{
[JsonPropertyName("reasoning_tokens")]
public int ReasoningTokens { get; set; }
}
Loading
Loading