examples: use tool call arguments in the realtime sample#1126
examples: use tool call arguments in the realtime sample#1126Rohan5commit wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Realtime tools example to use the model-provided tool call arguments (location/unit) when producing the tool output item, making the sample reflect a more realistic tool-calling flow.
Changes:
- Parse
RealtimeFunctionCallItem.FunctionArgumentsas JSON and extractlocation/unit. - Pass extracted
location/unitintoGetCurrentWeatherinstead of using hard-coded values. - Update the console output to include the requested location.
| using JsonDocument argumentsJson = JsonDocument.Parse(functionCallItem.FunctionArguments.ToString()); | ||
| string location = argumentsJson.RootElement.TryGetProperty("location", out JsonElement locationElement) | ||
| ? locationElement.GetString() ?? "San Francisco, CA" | ||
| : "San Francisco, CA"; | ||
| string unit = argumentsJson.RootElement.TryGetProperty("unit", out JsonElement unitElement) | ||
| ? unitElement.GetString() ?? "celsius" | ||
| : "celsius"; |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95ca213328
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| hasToolCalls = true; | ||
|
|
||
| Console.WriteLine($">> Calling {functionCallItem.FunctionName} function..."); | ||
| using JsonDocument argumentsJson = JsonDocument.Parse(functionCallItem.FunctionArguments.ToString()); |
There was a problem hiding this comment.
Handle empty arguments before JSON parsing
functionCallItem.FunctionArguments is a string payload and can be empty in realtime function-call events; parsing it unconditionally with JsonDocument.Parse(...) will throw JsonException and stop the sample before it can submit tool output. This is a regression from the previous behavior (which continued with defaults) and can surface whenever the model returns an empty/malformed arguments string, so the example should defensively fall back (for example, treat empty input as {}) before parsing.
Useful? React with 👍 / 👎.
Summary
locationandunitvalues instead of always sending a hard-coded weather lookupRelated issue
Guideline alignment
Validation
git diff --checkdotnetbuild because thedotnetCLI is unavailable in this environment