Skip to content

Commit df41bfa

Browse files
authored
Fix HostedCodeInterpreterTool with Responses (#6817)
When no file IDs are present, we're outputting the wrong JSON.
1 parent e5ad845 commit df41bfa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ private ResponseCreationOptions ToOpenAIResponseCreationOptions(ChatOptions? opt
479479
}
480480
else
481481
{
482-
json = """{"type":"code_interpreter","container":"auto"}""";
482+
json = """{"type":"code_interpreter","container":{"type":"auto"}}""";
483483
}
484484

485485
result.Tools.Add(ModelReaderWriter.Read<ResponseTool>(BinaryData.FromString(json)));

test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ public class OpenAIResponseClientIntegrationTests : ChatClientIntegrationTests
2121
// Test structure doesn't make sense with Responses.
2222
public override Task Caching_AfterFunctionInvocation_FunctionOutputUnchangedAsync() => Task.CompletedTask;
2323

24+
[ConditionalFact]
25+
public async Task UseCodeInterpreter_ProducesCodeExecutionResults()
26+
{
27+
SkipIfNotEnabled();
28+
29+
var response = await ChatClient.GetResponseAsync("Use the code interpreter to calculate the square root of 42. Return only the nearest integer value and no other text.", new()
30+
{
31+
Tools = [new HostedCodeInterpreterTool()],
32+
});
33+
Assert.NotNull(response);
34+
35+
ChatMessage message = Assert.Single(response.Messages);
36+
37+
Assert.Equal("6", message.Text);
38+
}
39+
2440
[ConditionalFact]
2541
public async Task UseWebSearch_AnnotationsReflectResults()
2642
{

0 commit comments

Comments
 (0)