Repository navigation
Closed
Labels
.NETIssue or Pull requests regarding .NET codeIssue or Pull requests regarding .NET codebugSomething isn't workingSomething isn't working
Description
semantic-kernel/dotnet/src/Connectors/Connectors.OpenAI/Core/OpenAIFunctionToolCall.cs
Line 131 in ec9233c
| arguments.Append(update.FunctionArgumentsUpdate.ToString()); |
This code should check FunctionArgumentsUpdate if IsEmpty.
if (update.FunctionArgumentsUpdate is not null && !update.FunctionArgumentsUpdate.ToMemory().IsEmpty)
{
...
}
Log
Trace: [2024/10/11 21:25:51] Request: POST https://xxx.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview
Accept: application/json
User-Agent: azsdk-net-AI.OpenAI/2.1.0-beta.1, (.NET 8.0.8; Microsoft Windows 10.0.22631)
x-ms-client-request-id: 0ae8cafc-d86d-48bb-a39c-b0ce1c7f9bc0
api-key: ***
Content-Type: application/json
{"messages":[{"role":"system","content":"You are a smart weather assistant"},{"role":"user","content":"Guangzhou weather"}],"model":"gpt-4o","frequency_penalty":0,"presence_penalty":0,"stream":true,"temperature":0.7,"top_p":1,"tools":[{"type":"function","function":{"description":"Get city weather based on area code","name":"WeatherPlugin-GetWeather","parameters":{"type":"object","required":["addressCode"],"properties":{"addressCode":{"type":"string","description":"City area address code. e.g. 110000, 440100..."}}}}}],"tool_choice":"auto","max_tokens":2048}
Trace: [2024/10/11 21:25:53] /openai/deployments/gpt-4o/chat/completions OK
Transfer-Encoding: chunked
...
Content-Type: text/event-stream; charset=utf-8
Trace: [2024/10/11 21:25:53]
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"role":"assistant","content":null,"tool_calls":[{"index":0,"id":"call_yXkmOQ1GvYheU9tVolJngmLa","type":"function","function":{"name":"WeatherPlugin-GetWeather","arguments":""}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\n"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":" "}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":" \""}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"address"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"Code"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"\":"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":" \""}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"440"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"100"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"\"\n"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"}"}}]},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-AH9wO192nxDoDKnTwpgdLCtAYLkjp","object":"chat.completion.chunk","created":1728653152,"model":"gpt-4o-2024-05-13","system_fingerprint":"fp_67802d9a6d","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"tool_calls"}]}
data: [DONE]
Error: [2024/10/11 21:25:53]
System.ArgumentNullException: Value cannot be null. (Parameter 'bytes')
at System.ArgumentNullException.Throw(String paramName)
at System.Text.Encoding.GetString(Byte* bytes, Int32 byteCount)
at System.BinaryData.ToString()
at Microsoft.SemanticKernel.Connectors.OpenAI.OpenAIFunctionToolCall.TrackStreamingToolingUpdate(IReadOnlyList`1 updates, Dictionary`2& toolCallIdsByIndex, Dictionary`2& functionNamesByIndex, Dictionary`2& functionArgumentBuildersByIndex)
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetStreamingChatMessageContentsAsync(String targetModel, ChatHistory chatHistory, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)+MoveNext()
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetStreamingChatMessageContentsAsync(String targetModel, ChatHistory chatHistory, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)+MoveNext()
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetStreamingChatMessageContentsAsync(String targetModel, ChatHistory chatHistory, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
...
Metadata
Metadata
Assignees
Labels
.NETIssue or Pull requests regarding .NET codeIssue or Pull requests regarding .NET codebugSomething isn't workingSomething isn't working
Type
Projects
- StatusShow more project fieldsSprint: Done
Activity
[-]Function Arguments Is Empty[/-][+].Net: Function Arguments Is Empty[/+]jichulu commentedon Oct 11, 2024
Update
semantic-kernel/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs
Lines 337 to 348 in ec9233c
to
Update
semantic-kernel/dotnet/src/Connectors/Connectors.OpenAI/Core/OpenAIFunctionToolCall.cs
Lines 124 to 132 in ec9233c
to
rogerbarreto commentedon Oct 15, 2024
jichulu, Thanks for the contribution!
I added some UnitTests to the provided PR, but interestingly enough the payload provided in this issue didn't cover throw any argument null exception as you mentioned.
I would appreciate if you can provide a payload that we can replicate the issue.
.Net: Fix: Enhance Function Argument Validation to Prevent Null Argum…
jichulu commentedon Oct 21, 2024
Roger Barreto (@rogerbarreto) I've found the specific reason. It's not exactly SK's bug, but SK can avoid it.
is caused by the version of the package
System.Memory.Data.The package
Azure.AI.OpenAI[2.1.0-beta.1]referencesSystem.Memory.Data, Version=1.0.2.0, . NETStandard,Version=v2.0。My project uses the package
Microsoft.Extensions.Azure, which referencesSystem.Memory.Data, Version=6.0.0.0, . NETCoreApp,Version=v6.0, so the null reference issue of System.BinaryData.ToString() is triggered.Upgrading System.Memory.Data to the latest version resolves the issue.
But projects that use .NET 6.0 may still have problems.
Steps to reproduce: Reference package
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.6" />or<PackageVersion Include="System.Memory.Data" Version="6.0.0" />in the project "Connectors.AzureOpenAI.UnitTests"