From 1a8ed45a9efe0b3e3107d86164637616b176c6ea Mon Sep 17 00:00:00 2001 From: rzubek Date: Sun, 18 Jun 2023 15:10:32 -0500 Subject: [PATCH 1/4] Added a missing JsonPropertyName --- OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs b/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs index 1ccbb7d4..75c3ab8e 100644 --- a/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs +++ b/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs @@ -169,6 +169,7 @@ public class FunctionParameterPropertyValue /// /// Optional. List of allowed values for this argument. /// + [JsonPropertyName("enum")] public IList? Enum { get; set; } } From a5de25d624826657915b9a7eb7f33b7155f5a513 Mon Sep 17 00:00:00 2001 From: rzubek Date: Sun, 18 Jun 2023 15:36:02 -0500 Subject: [PATCH 2/4] Clarify that the first block just takes the "arguments" string as is, and we only perform appending on subsequent blocks. The prior version (without this change) risked doubling up the first argument string. It doesn't happened in practice, because ChatGPT's first streaming message has an empty arguments string (i.e. `"arguments": ""`), so doubling up an empty string had no effect. But let's fix this just in case their implementation changes. --- OpenAI.SDK/Managers/OpenAIChatCompletions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenAI.SDK/Managers/OpenAIChatCompletions.cs b/OpenAI.SDK/Managers/OpenAIChatCompletions.cs index fc614b3e..1628e5bc 100644 --- a/OpenAI.SDK/Managers/OpenAIChatCompletions.cs +++ b/OpenAI.SDK/Managers/OpenAIChatCompletions.cs @@ -108,6 +108,7 @@ public void Process(ChatCompletionCreateResponse block) if (firstChoice == null) { return; } // not a valid state? nothing to do var isStreamingFnCall = IsStreamingFunctionCall(); + var justStarted = false; // If we're not yet assembling, and we just got a streaming block that has a function_call segment, // this is the beginning of a function call assembly. @@ -116,10 +117,12 @@ public void Process(ChatCompletionCreateResponse block) { FnCall = firstChoice.Message.FunctionCall; firstChoice.Message.FunctionCall = null; + justStarted = true; } // As long as we're assembling, keep on appending those args - if (IsFnAssemblyActive) + // (Skip the first one, because it was already processed in the block above) + if (IsFnAssemblyActive && !justStarted) { FnCall.Arguments += ExtractArgsSoFar(); } From 7f6a050e8ac52ecdbafeed915f191a232ed14034 Mon Sep 17 00:00:00 2001 From: Tolga Kayhan Date: Thu, 22 Jun 2023 02:36:14 +0100 Subject: [PATCH 3/4] bug fix update --- OpenAI.SDK/OpenAI.csproj | 2 +- Readme.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenAI.SDK/OpenAI.csproj b/OpenAI.SDK/OpenAI.csproj index 302cfad7..dda51973 100644 --- a/OpenAI.SDK/OpenAI.csproj +++ b/OpenAI.SDK/OpenAI.csproj @@ -10,7 +10,7 @@ https://openai.com/ OpenAI-Betalgo.png true - 7.1.0-beta + 7.1.1-beta Tolga Kayhan, Betalgo Betalgo Up Ltd. OpenAI ChatGPT, Whisper, GPT-4 and DALL·E dotnet SDK diff --git a/Readme.md b/Readme.md index 10644ce8..2916775a 100644 --- a/Readme.md +++ b/Readme.md @@ -189,6 +189,8 @@ I will always be using the latest libraries, and future releases will frequently I am incredibly busy. If I forgot your name, please accept my apologies and let me know so I can add it to the list. ## Changelog +### 7.1.1-beta +- Bugfix https://github.com/betalgo/openai/pull/302 ### 7.1.0-beta - Function Calling: We're releasing this version to bring in a new feature that lets you call functions faster. But remember, this version might not be perfectly stable and we might change it a lot later. A big shout-out to @rzubek for helping us add this feature. Although I liked his work, I didn't have enough time to look into it thoroughly. Still, the tests I did showed it was working, so I decided to add his feature to our code. This lets everyone use it now. Even though I'm busy moving houses and didn't have much time, seeing @rzubek's help made things a lot easier for me. - Support for New Models: This update also includes support for new models that OpenAI recently launched. I've also changed the naming style to match OpenAI's. Model names will no longer start with 'chat'; instead, they'll start with 'gpt_3_5' and so on. From 9080eb4daceba3dffc8a215eaba283f277e4fb7f Mon Sep 17 00:00:00 2001 From: Tolga Kayhan Date: Thu, 22 Jun 2023 02:42:50 +0100 Subject: [PATCH 4/4] function role --- OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs | 5 ++++- OpenAI.SDK/ObjectModels/StaticValueHelper.cs | 1 + OpenAI.SDK/OpenAI.csproj | 2 +- Readme.md | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs b/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs index 75c3ab8e..6b6a8aa2 100644 --- a/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs +++ b/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs @@ -53,7 +53,10 @@ public static ChatMessage FromAssistant(string content, string? name = null) { return new ChatMessage(StaticValues.ChatMessageRoles.Assistant, content, name); } - + public static ChatMessage FromFunction(string content, string? name = null) + { + return new ChatMessage(StaticValues.ChatMessageRoles.Function, content, name); + } public static ChatMessage FromUser(string content, string? name = null) { return new ChatMessage(StaticValues.ChatMessageRoles.User, content, name); diff --git a/OpenAI.SDK/ObjectModels/StaticValueHelper.cs b/OpenAI.SDK/ObjectModels/StaticValueHelper.cs index e94352f1..8f953b70 100644 --- a/OpenAI.SDK/ObjectModels/StaticValueHelper.cs +++ b/OpenAI.SDK/ObjectModels/StaticValueHelper.cs @@ -35,5 +35,6 @@ public static class ChatMessageRoles public static string System => "system"; public static string User => "user"; public static string Assistant => "assistant"; + public static string Function => "function"; } } \ No newline at end of file diff --git a/OpenAI.SDK/OpenAI.csproj b/OpenAI.SDK/OpenAI.csproj index dda51973..197372b5 100644 --- a/OpenAI.SDK/OpenAI.csproj +++ b/OpenAI.SDK/OpenAI.csproj @@ -10,7 +10,7 @@ https://openai.com/ OpenAI-Betalgo.png true - 7.1.1-beta + 7.1.2-beta Tolga Kayhan, Betalgo Betalgo Up Ltd. OpenAI ChatGPT, Whisper, GPT-4 and DALL·E dotnet SDK diff --git a/Readme.md b/Readme.md index 2916775a..9899e203 100644 --- a/Readme.md +++ b/Readme.md @@ -189,8 +189,9 @@ I will always be using the latest libraries, and future releases will frequently I am incredibly busy. If I forgot your name, please accept my apologies and let me know so I can add it to the list. ## Changelog -### 7.1.1-beta +### 7.1.2-beta - Bugfix https://github.com/betalgo/openai/pull/302 +- Added support for Function role https://github.com/betalgo/openai/issues/303 ### 7.1.0-beta - Function Calling: We're releasing this version to bring in a new feature that lets you call functions faster. But remember, this version might not be perfectly stable and we might change it a lot later. A big shout-out to @rzubek for helping us add this feature. Although I liked his work, I didn't have enough time to look into it thoroughly. Still, the tests I did showed it was working, so I decided to add his feature to our code. This lets everyone use it now. Even though I'm busy moving houses and didn't have much time, seeing @rzubek's help made things a lot easier for me. - Support for New Models: This update also includes support for new models that OpenAI recently launched. I've also changed the naming style to match OpenAI's. Model names will no longer start with 'chat'; instead, they'll start with 'gpt_3_5' and so on.