diff --git a/OpenAI-DotNet-Tests/TestFixture_03_Chat.cs b/OpenAI-DotNet-Tests/TestFixture_03_Chat.cs index b823fe35..736450f5 100644 --- a/OpenAI-DotNet-Tests/TestFixture_03_Chat.cs +++ b/OpenAI-DotNet-Tests/TestFixture_03_Chat.cs @@ -157,7 +157,7 @@ public async Task Test_4_GetChatFunctionCompletion() }) }; - var chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + var chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); var result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); Assert.IsNotNull(result); Assert.IsNotNull(result.Choices); @@ -169,7 +169,7 @@ public async Task Test_4_GetChatFunctionCompletion() var locationMessage = new Message(Role.User, "I'm in Glasgow, Scotland"); messages.Add(locationMessage); Console.WriteLine($"{locationMessage.Role}: {locationMessage.Content}"); - chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); Assert.IsNotNull(result); @@ -184,7 +184,7 @@ public async Task Test_4_GetChatFunctionCompletion() var unitMessage = new Message(Role.User, "celsius"); messages.Add(unitMessage); Console.WriteLine($"{unitMessage.Role}: {unitMessage.Content}"); - chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); Assert.IsNotNull(result); Assert.IsNotNull(result.Choices); @@ -198,8 +198,11 @@ public async Task Test_4_GetChatFunctionCompletion() var functionArgs = JsonSerializer.Deserialize(result.FirstChoice.Message.Function.Arguments.ToString()); var functionResult = WeatherService.GetCurrentWeather(functionArgs); Assert.IsNotNull(functionResult); - messages.Add(new Message(Role.Function, functionResult)); + messages.Add(new Message(Role.Function, functionResult, nameof(WeatherService.GetCurrentWeather))); Console.WriteLine($"{Role.Function}: {functionResult}"); + chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); + Console.WriteLine(result); } [Test] @@ -241,7 +244,7 @@ public async Task Test_5_GetChatFunctionCompletion_Streaming() }) }; - var chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + var chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); var result = await OpenAIClient.ChatEndpoint.StreamCompletionAsync(chatRequest, partialResponse => { Assert.IsNotNull(partialResponse); @@ -266,7 +269,7 @@ public async Task Test_5_GetChatFunctionCompletion_Streaming() var locationMessage = new Message(Role.User, "I'm in Glasgow, Scotland"); messages.Add(locationMessage); Console.WriteLine($"{locationMessage.Role}: {locationMessage.Content}"); - chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); result = await OpenAIClient.ChatEndpoint.StreamCompletionAsync(chatRequest, partialResponse => { Assert.IsNotNull(partialResponse); @@ -295,7 +298,7 @@ public async Task Test_5_GetChatFunctionCompletion_Streaming() var unitMessage = new Message(Role.User, "celsius"); messages.Add(unitMessage); Console.WriteLine($"{unitMessage.Role}: {unitMessage.Content}"); - chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); result = await OpenAIClient.ChatEndpoint.StreamCompletionAsync(chatRequest, partialResponse => { Assert.IsNotNull(partialResponse); @@ -325,7 +328,7 @@ public async Task Test_5_GetChatFunctionCompletion_Streaming() var functionArgs = JsonSerializer.Deserialize(result.FirstChoice.Message.Function.Arguments.ToString()); var functionResult = WeatherService.GetCurrentWeather(functionArgs); Assert.IsNotNull(functionResult); - messages.Add(new Message(Role.Function, functionResult)); + messages.Add(new Message(Role.Function, functionResult, nameof(WeatherService.GetCurrentWeather))); Console.WriteLine($"{Role.Function}: {functionResult}"); } @@ -369,7 +372,7 @@ public async Task Test_6_GetChatFunctionForceCompletion() }) }; - var chatRequest = new ChatRequest(messages, functions: functions, functionCall: null, model: "gpt-3.5-turbo-0613"); + var chatRequest = new ChatRequest(messages, functions: functions, functionCall: null, model: "gpt-3.5-turbo"); var result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); Assert.IsNotNull(result); Assert.IsNotNull(result.Choices); @@ -400,7 +403,7 @@ public async Task Test_6_GetChatFunctionForceCompletion() var functionArgs = JsonSerializer.Deserialize(result.FirstChoice.Message.Function.Arguments.ToString()); var functionResult = WeatherService.GetCurrentWeather(functionArgs); Assert.IsNotNull(functionResult); - messages.Add(new Message(Role.Function, functionResult)); + messages.Add(new Message(Role.Function, functionResult, nameof(WeatherService.GetCurrentWeather))); Console.WriteLine($"{Role.Function}: {functionResult}"); } } diff --git a/OpenAI-DotNet/Chat/Message.cs b/OpenAI-DotNet/Chat/Message.cs index daf8aebe..fa521cf4 100644 --- a/OpenAI-DotNet/Chat/Message.cs +++ b/OpenAI-DotNet/Chat/Message.cs @@ -45,7 +45,7 @@ public Message(Role role, string content, string name = null, Function function /// [JsonInclude] [JsonPropertyName("content")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] public string Content { get; private set; } /// diff --git a/OpenAI-DotNet/OpenAI-DotNet.csproj b/OpenAI-DotNet/OpenAI-DotNet.csproj index f9c296ff..c3787292 100644 --- a/OpenAI-DotNet/OpenAI-DotNet.csproj +++ b/OpenAI-DotNet/OpenAI-DotNet.csproj @@ -17,8 +17,10 @@ More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet- https://github.com/RageAgainstThePixel/OpenAI-DotNet OpenAI, AI, ML, API, gpt-4, gpt-3.5-tubo, gpt-3, chatGPT, chat-gpt, gpt-2, gpt OpenAI API - 7.0.4 - Version 7.0.4 + 7.0.5 + Version 7.0.5 +- Fixed Message.Content serialization in Role.Function message history +Version 7.0.4 - Fixed ChatRequest forced function calls Version 7.0.3 - Fixed chat streaming message copy from delta diff --git a/README.md b/README.md index 55ec9d88..1b3ec658 100644 --- a/README.md +++ b/README.md @@ -467,7 +467,7 @@ var functions = new List }) }; -var chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); +var chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); var result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); messages.Add(result.FirstChoice.Message); @@ -476,7 +476,7 @@ Console.WriteLine($"{result.FirstChoice.Message.Role}: {result.FirstChoice.Messa var locationMessage = new Message(Role.User, "I'm in Glasgow, Scotland"); messages.Add(locationMessage); Console.WriteLine($"{locationMessage.Role}: {locationMessage.Content}"); -chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); +chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); messages.Add(result.FirstChoice.Message); @@ -488,7 +488,7 @@ if (!string.IsNullOrEmpty(result.FirstChoice.Message.Content)) var unitMessage = new Message(Role.User, "celsius"); messages.Add(unitMessage); Console.WriteLine($"{unitMessage.Role}: {unitMessage.Content}"); - chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo-0613"); + chatRequest = new ChatRequest(messages, functions: functions, functionCall: "auto", model: "gpt-3.5-turbo"); result = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest); } @@ -496,7 +496,7 @@ Console.WriteLine($"{result.FirstChoice.Message.Role}: {result.FirstChoice.Messa Console.WriteLine($"{result.FirstChoice.Message.Function.Arguments}"); var functionArgs = JsonSerializer.Deserialize(result.FirstChoice.Message.Function.Arguments.ToString()); var functionResult = WeatherService.GetCurrentWeather(functionArgs); -messages.Add(new Message(Role.Function, functionResult)); +messages.Add(new Message(Role.Function, functionResult, nameof(WeatherService.GetCurrentWeather))); Console.WriteLine($"{Role.Function}: {functionResult}"); // System: You are a helpful weather assistant. // User: What's the weather like today?