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

Release 7.4.2 #441

Merged
merged 28 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c7b1413
Merge pull request #2 from betalgo/dev
belaszalontai Nov 13, 2023
98dc70d
Merge pull request #3 from betalgo/master
belaszalontai Nov 18, 2023
50199d5
Merge pull request #4 from belaszalontai/master
belaszalontai Nov 18, 2023
308ab97
Add system_fingerprint to the ChatCompletionCreateResponse class as per:
shanepowell Nov 19, 2023
3fb561b
Add new tool choices to the ChatCompletionCreateRequest and ChatMessa…
shanepowell Nov 20, 2023
50c24a1
Add support for tool message role type into ChatMessage.
shanepowell Nov 21, 2023
c7b1d66
Extend Chat Completion API with Vision
szabe74 Nov 24, 2023
e83746e
fix missing response property
szabe74 Nov 25, 2023
3468323
Added StaticValues for ImageStatics.Quality
kayhantolga Dec 3, 2023
c3ce63e
Merge pull request #439 from Michael-Herzog/master
kayhantolga Dec 3, 2023
66705cb
Merge pull request #435 from belaszalontai/feature/image-revised-prompt
kayhantolga Dec 3, 2023
f5426cf
Make more compatible with the Assistant API changes.
shanepowell Dec 3, 2023
ded0e94
minor name change.
shanepowell Dec 3, 2023
4e4a571
Merge pull request #5 from betalgo/dev
belaszalontai Dec 4, 2023
be0d504
Merge branch 'dev' into feature/chat-with-vision
szabe74 Dec 4, 2023
f1a28af
Merge pull request #431 from shanepowell/add_system_fingerprint
kayhantolga Dec 4, 2023
20fc247
Merge branch 'dev' into new_tools_chat_request
shanepowell Dec 4, 2023
293eec6
Removed obsolete support for legacy function call.
kayhantolga Dec 4, 2023
9fa7609
ToolChoice field converted from object to class, removed default valu…
kayhantolga Dec 5, 2023
816e64d
Merge pull request #432 from shanepowell/new_tools_chat_request
kayhantolga Dec 5, 2023
b5127a3
Merge branch 'dev' into pr/434
kayhantolga Dec 5, 2023
5e3904e
VisionContent has been renamed as MessageContent, and the rest of the…
kayhantolga Dec 5, 2023
be68f79
Merge pull request #434 from belaszalontai/feature/chat-with-vision
kayhantolga Dec 5, 2023
984fa91
Merge branch 'master' into dev
kayhantolga Dec 5, 2023
4a50f23
added DefineFunction
kayhantolga Dec 6, 2023
3e82371
Merge pull request #444 from betalgo/add-define-function-method-to-to…
kayhantolga Dec 6, 2023
418a5ba
version bump for 7.4.2
kayhantolga Dec 6, 2023
92d850f
Merge pull request #445 from betalgo/version-bump-7.4.2
kayhantolga Dec 6, 2023
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
8 changes: 7 additions & 1 deletion OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@
// | / \ / \ | \ /) | ( \ /o\ / ) | (\ / | / \ / \ |
// |-----------------------------------------------------------------------|


await ChatCompletionTestHelper.RunSimpleChatCompletionTest(sdk);
// Vision
//await VisionTestHelper.RunSimpleVisionTest(sdk);
//await VisionTestHelper.RunSimpleVisionStreamTest(sdk);
//await VisionTestHelper.RunSimpleVisionTestUsingBase64EncodedImage(sdk);

//await ChatCompletionTestHelper.RunSimpleCompletionStreamTest(sdk);
//await ChatCompletionTestHelper.RunChatFunctionCallTest(sdk);
//await ChatCompletionTestHelper.RunChatFunctionCallTestAsStream(sdk);
//await FineTuningJobTestHelper.RunCaseStudyIsTheModelMakingUntrueStatements(sdk);

// Whisper
//await AudioTestHelper.RunSimpleAudioCreateTranscriptionTest(sdk);
//await AudioTestHelper.RunSimpleAudioCreateTranslationTest(sdk);
Expand Down
86 changes: 68 additions & 18 deletions OpenAI.Playground/TestHelpers/ChatCompletionTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static async Task RunSimpleCompletionStreamTest(IOpenAIService sdk)

public static async Task RunChatFunctionCallTest(IOpenAIService sdk)
{
ConsoleExtensions.WriteLine("Chat Function Call Testing is starting:", ConsoleColor.Cyan);
ConsoleExtensions.WriteLine("Chat Tool Functions Call Testing is starting:", ConsoleColor.Cyan);

// example taken from:
// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb
Expand Down Expand Up @@ -130,9 +130,11 @@ public static async Task RunChatFunctionCallTest(IOpenAIService sdk)
ChatMessage.FromSystem("Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."),
ChatMessage.FromUser("Give me a weather report for Chicago, USA, for the next 5 days.")
},
Functions = new List<FunctionDefinition> {fn1, fn2, fn3, fn4},
Tools = new List<ToolDefinition> { ToolDefinition.DefineFunction(fn1), ToolDefinition.DefineFunction(fn2) ,ToolDefinition.DefineFunction(fn3) ,ToolDefinition.DefineFunction(fn4) },
// optionally, to force a specific function:
// FunctionCall = new Dictionary<string, string> { { "name", "get_current_weather" } },
//ToolChoice = ToolChoice.FunctionChoice("get_current_weather"),
// or auto tool choice:
//ToolChoice = ToolChoice.Auto,
MaxTokens = 50,
Model = Models.Gpt_3_5_Turbo
});
Expand All @@ -152,13 +154,23 @@ public static async Task RunChatFunctionCallTest(IOpenAIService sdk)
var choice = completionResult.Choices.First();
Console.WriteLine($"Message: {choice.Message.Content}");

var fn = choice.Message.FunctionCall;
if (fn != null)
var tools = choice.Message.ToolCalls;
if (tools != null)
{
Console.WriteLine($"Function call: {fn.Name}");
foreach (var entry in fn.ParseArguments())
Console.WriteLine($"Tools: {tools.Count}");
foreach (var toolCall in tools)
{
Console.WriteLine($" {entry.Key}: {entry.Value}");
Console.WriteLine($" {toolCall.Id}: {toolCall.FunctionCall}");

var fn = toolCall.FunctionCall;
if (fn != null)
{
Console.WriteLine($" Function call: {fn.Name}");
foreach (var entry in fn.ParseArguments())
{
Console.WriteLine($" {entry.Key}: {entry.Value}");
}
}
}
}
}
Expand All @@ -181,7 +193,7 @@ public static async Task RunChatFunctionCallTest(IOpenAIService sdk)

public static async Task RunChatFunctionCallTestAsStream(IOpenAIService sdk)
{
ConsoleExtensions.WriteLine("Chat Function Call Testing is starting:", ConsoleColor.Cyan);
ConsoleExtensions.WriteLine("Chat Tool Functions Call Stream Testing is starting:", ConsoleColor.Cyan);

// example taken from:
// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb
Expand Down Expand Up @@ -221,11 +233,13 @@ public static async Task RunChatFunctionCallTestAsStream(IOpenAIService sdk)
// or to test array functions, use this instead:
// ChatMessage.FromUser("The combination is: One. Two. Three. Four. Five."),
},
Functions = new List<FunctionDefinition> {fn1, fn2, fn3, fn4},
Tools = new List<ToolDefinition> { ToolDefinition.DefineFunction(fn1), ToolDefinition.DefineFunction(fn2), ToolDefinition.DefineFunction(fn3), ToolDefinition.DefineFunction(fn4) },
// optionally, to force a specific function:
// FunctionCall = new Dictionary<string, string> { { "name", "get_current_weather" } },
ToolChoice = ToolChoice.FunctionChoice("get_current_weather"),
// or auto tool choice:
// ToolChoice = ToolChoice.Auto,
MaxTokens = 50,
Model = Models.Gpt_3_5_Turbo_0613
Model = Models.Gpt_4_1106_preview
});

/* when testing weather forecasts, expected output should be along the lines of:
Expand All @@ -243,21 +257,57 @@ public static async Task RunChatFunctionCallTestAsStream(IOpenAIService sdk)
Function call: identify_number_sequence
values: [1, 2, 3, 4, 5]
*/

var functionArguments = new Dictionary<int, string>();
await foreach (var completionResult in completionResults)
{
if (completionResult.Successful)
{
var choice = completionResult.Choices.First();
Console.WriteLine($"Message: {choice.Message.Content}");

var fn = choice.Message.FunctionCall;
if (fn != null)
var tools = choice.Message.ToolCalls;
if (tools != null)
{
Console.WriteLine($"Function call: {fn.Name}");
foreach (var entry in fn.ParseArguments())
Console.WriteLine($"Tools: {tools.Count}");
for (int i = 0; i < tools.Count; i++)
{
Console.WriteLine($" {entry.Key}: {entry.Value}");
var toolCall = tools[i];
Console.WriteLine($" {toolCall.Id}: {toolCall.FunctionCall}");

var fn = toolCall.FunctionCall;
if (fn != null)
{
if (!string.IsNullOrEmpty(fn.Name))
{
Console.WriteLine($" Function call: {fn.Name}");
}

if (!string.IsNullOrEmpty(fn.Arguments))
{
if (functionArguments.TryGetValue(i, out var currentArguments))
{
currentArguments += fn.Arguments;
}
else
{
currentArguments = fn.Arguments;
}
functionArguments[i] = currentArguments;
fn.Arguments = currentArguments;

try
{
foreach (var entry in fn.ParseArguments())
{
Console.WriteLine($" {entry.Key}: {entry.Value}");
}
}
catch (Exception)
{
// ignore
}
}
}
}
}
}
Expand Down
185 changes: 185 additions & 0 deletions OpenAI.Playground/TestHelpers/VisionTestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
using OpenAI.Interfaces;
using OpenAI.ObjectModels;
using OpenAI.ObjectModels.RequestModels;
using static OpenAI.ObjectModels.StaticValues;

namespace OpenAI.Playground.TestHelpers;

internal static class VisionTestHelper
{
public static async Task RunSimpleVisionTest(IOpenAIService sdk)
{
ConsoleExtensions.WriteLine("VIsion Testing is starting:", ConsoleColor.Cyan);

try
{
ConsoleExtensions.WriteLine("Vision Test:", ConsoleColor.DarkCyan);

var completionResult = await sdk.ChatCompletion.CreateCompletion(
new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are an image analyzer assistant."),
ChatMessage.FromUser(
new List<MessageContent>
{
MessageContent.TextContent("What is on the picture in details?"),
MessageContent.ImageUrlContent(
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
ImageStatics.ImageDetailTypes.High
)
}
),
},
MaxTokens = 300,
Model = Models.Gpt_4_vision_preview,
N = 1
}
);

if (completionResult.Successful)
{
Console.WriteLine(completionResult.Choices.First().Message.Content);
}
else
{
if (completionResult.Error == null)
{
throw new Exception("Unknown Error");
}

Console.WriteLine(
$"{completionResult.Error.Code}: {completionResult.Error.Message}"
);
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}

public static async Task RunSimpleVisionStreamTest(IOpenAIService sdk)
{
ConsoleExtensions.WriteLine("Vision Stream Testing is starting:", ConsoleColor.Cyan);
try
{
ConsoleExtensions.WriteLine("Vision Stream Test:", ConsoleColor.DarkCyan);

var completionResult = sdk.ChatCompletion.CreateCompletionAsStream(
new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are an image analyzer assistant."),
ChatMessage.FromUser(
new List<MessageContent>
{
MessageContent.TextContent("What’s in this image?"),
MessageContent.ImageUrlContent(
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
ImageStatics.ImageDetailTypes.Low
)
}
),
},
MaxTokens = 300,
Model = Models.Gpt_4_vision_preview,
N = 1
}
);

await foreach (var completion in completionResult)
{
if (completion.Successful)
{
Console.Write(completion.Choices.First().Message.Content);
}
else
{
if (completion.Error == null)
{
throw new Exception("Unknown Error");
}

Console.WriteLine(
$"{completion.Error.Code}: {completion.Error.Message}"
);
}
}

Console.WriteLine("");
Console.WriteLine("Complete");
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}

public static async Task RunSimpleVisionTestUsingBase64EncodedImage(IOpenAIService sdk)
{
ConsoleExtensions.WriteLine("Vision Testing is starting:", ConsoleColor.Cyan);

try
{
ConsoleExtensions.WriteLine(
"Vision with base64 encoded image Test:",
ConsoleColor.DarkCyan
);

const string originalFileName = "image_edit_original.png";
var originalFile = await FileExtensions.ReadAllBytesAsync(
$"SampleData/{originalFileName}"
);

var completionResult = await sdk.ChatCompletion.CreateCompletion(
new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are an image analyzer assistant."),
ChatMessage.FromUser(
new List<MessageContent>
{
MessageContent.TextContent("What is on the picture in details?"),
MessageContent.ImageBinaryContent(
originalFile,
ImageStatics.ImageFileTypes.Png,
ImageStatics.ImageDetailTypes.High
)
}
),
},
MaxTokens = 300,
Model = Models.Gpt_4_vision_preview,
N = 1
}
);

if (completionResult.Successful)
{
Console.WriteLine(completionResult.Choices.First().Message.Content);
}
else
{
if (completionResult.Error == null)
{
throw new Exception("Unknown Error");
}

Console.WriteLine(
$"{completionResult.Error.Code}: {completionResult.Error.Message}"
);
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
Loading
Loading