Skip to content

Commit 24ff66a

Browse files
authored
Fix broken chat functions example in README (Azure#38461)
* Fix broken chat functions example in README The use of the ChatRole.Function message will fail if the message doesn't have its Name set to the name of function. * Update test as well
1 parent 1e4a508 commit 24ff66a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sdk/openai/Azure.AI.OpenAI/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ if (responseChoice.FinishReason == CompletionsFinishReason.FunctionCall)
323323
ChatRole.Function,
324324
JsonSerializer.Serialize(
325325
functionResultData,
326-
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }));
326+
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }))
327+
{
328+
Name = responseChoice.Message.FunctionCall.Name
329+
};
327330
conversationMessages.Add(functionResponseMessage);
328331
// Now make a new request using all three messages in conversationMessages
329332
}

sdk/openai/Azure.AI.OpenAI/tests/Samples/Sample07_ChatFunctions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ public async Task ChatFunctions()
9090
ChatRole.Function,
9191
JsonSerializer.Serialize(
9292
functionResultData,
93-
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }));
93+
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }))
94+
{
95+
Name = responseChoice.Message.FunctionCall.Name
96+
};
9497
conversationMessages.Add(functionResponseMessage);
9598
// Now make a new request using all three messages in conversationMessages
9699
}

0 commit comments

Comments
 (0)