Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,34 @@ public async Task FunctionResultsCanBeProvidedToLLMAsOneResultPerChatMessageAsyn
Assert.Equal("2", assistantMessage2.GetProperty("tool_call_id").GetString());
}

[Fact]
public async Task FunctionResultsWithoutCallIdThrowsClearExceptionAsync()
{
// Arrange
this._messageHandlerStub.ResponseToReturn = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StringContent(ChatCompletionResponse)
};

var sut = new OpenAIChatCompletionService(modelId: "gpt-3.5-turbo", apiKey: "NOKEY", httpClient: this._httpClient);

var chatHistory = new ChatHistory
{
new ChatMessageContent(AuthorRole.Tool,
[
new FunctionResultContent(functionName: "GetCurrentWeather", pluginName: "MyPlugin", callId: null, result: "rainy")
])
};

var settings = new OpenAIPromptExecutionSettings() { ToolCallBehavior = ToolCallBehavior.EnableKernelFunctions };

// Act
var exception = await Assert.ThrowsAsync<ArgumentException>(() => sut.GetChatMessageContentAsync(chatHistory, settings));

// Assert
Assert.Contains("missing a tool call id", exception.Message, StringComparison.OrdinalIgnoreCase);
}

[Fact]
public async Task FunctionResultsCanBeProvidedToLLMAsManyResultsInOneChatMessageAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,13 @@ private static List<ChatMessage> CreateRequestMessages(ChatMessageContent messag
continue;
}

if (string.IsNullOrWhiteSpace(resultContent.CallId))
{
throw new ArgumentException(
$"Function result message is missing a tool call ID. Provide {nameof(FunctionResultContent.CallId)} when sending tool results to OpenAI.",
nameof(message));
}

toolMessages ??= [];

if (resultContent.Result is Exception ex)
Expand Down
Loading