|
136 | 136 | { |
137 | 137 | <TextVisualizer ViewModel="@itemPart.TextVisualizerViewModel" HideLineNumbers="true" Virtualize="false" /> |
138 | 138 | } |
| 139 | + |
| 140 | + if (itemPart.MessagePart is ToolCallRequestPart toolCallPart && !string.IsNullOrEmpty(toolCallPart.Name)) |
| 141 | + { |
| 142 | + if (Content.ToolDefinitions.FirstOrDefault(d => d.ToolDefinition.Name == toolCallPart.Name) is { } toolVM) |
| 143 | + { |
| 144 | + <div class="tool-button-container"> |
| 145 | + <FluentButton OnClick="@(() => ViewToolDefinition(toolVM))"> |
| 146 | + <FluentIcon Value="@s_wrenchIcon" Style="vertical-align: sub;" slot="start" /> |
| 147 | + Tool definition |
| 148 | + </FluentButton> |
| 149 | + </div> |
| 150 | + } |
| 151 | + } |
| 152 | + else if (itemPart.MessagePart is ToolCallResponsePart toolCallResponsePart && !string.IsNullOrEmpty(toolCallResponsePart.Id)) |
| 153 | + { |
| 154 | + if (TryGetToolCall(toolCallResponsePart.Id, out var itemVM, out var toolCallRequestPart)) |
| 155 | + { |
| 156 | + <div class="tool-button-container"> |
| 157 | + <FluentButton OnClick="@(() => OnViewItem(itemVM))"> |
| 158 | + <FluentIcon Value="@s_toolIcon" Style="vertical-align: sub;" slot="start" /> |
| 159 | + Tool call |
| 160 | + </FluentButton> |
| 161 | + |
| 162 | + @if (Content.ToolDefinitions.FirstOrDefault(d => d.ToolDefinition.Name == toolCallRequestPart.Name) is { } toolVM) |
| 163 | + { |
| 164 | + <FluentButton OnClick="@(() => ViewToolDefinition(toolVM))"> |
| 165 | + <FluentIcon Value="@s_wrenchIcon" Style="vertical-align: sub;" slot="start" /> |
| 166 | + Tool definition |
| 167 | + </FluentButton> |
| 168 | + } |
| 169 | + </div> |
| 170 | + } |
| 171 | + } |
139 | 172 | } |
140 | 173 | } |
141 | 174 | </div> |
|
231 | 264 | @((MarkupString)string.Format(CultureInfo.CurrentCulture, Loc[nameof(Dialogs.GenAINoMessageContentMoreInformationMessage)], "https://aka.ms/aspire/telemetry-ai-content")) |
232 | 265 | </div> |
233 | 266 | } |
234 | | - @RenderMessageSection(Loc[nameof(Dialogs.GenAIInputHeaderText)], Content.InputMessages, Content.NoMessageContent, Content.ToolDefinitions) |
235 | | - @RenderMessageSection(Loc[nameof(Dialogs.GenAIOutputHeaderText)], Content.OutputMessages, Content.NoMessageContent, Content.ToolDefinitions) |
| 267 | + @RenderMessageSection(Loc[nameof(Dialogs.GenAIInputHeaderText)], Content.InputMessages, Content.NoMessageContent) |
| 268 | + @RenderMessageSection(Loc[nameof(Dialogs.GenAIOutputHeaderText)], Content.OutputMessages, Content.NoMessageContent) |
236 | 269 | @if (Content.ErrorItem is { } errorItem) |
237 | 270 | { |
238 | | - @RenderMessageSection(Loc[nameof(Dialogs.GenAIErrorHeaderText)], [errorItem], Content.NoMessageContent, Content.ToolDefinitions) |
| 271 | + @RenderMessageSection(Loc[nameof(Dialogs.GenAIErrorHeaderText)], [errorItem], Content.NoMessageContent) |
239 | 272 | } |
240 | 273 | } |
241 | 274 | </div> |
|
252 | 285 | @if (Content.ToolDefinitions.Count > 0) |
253 | 286 | { |
254 | 287 | <FluentAccordion Class="tools-list"> |
255 | | - @foreach (var tool in Content.ToolDefinitions.Where(t => t.Type == "function")) |
| 288 | + @foreach (var toolVM in Content.ToolDefinitions.Where(t => t.ToolDefinition.Type == "function")) |
256 | 289 | { |
257 | | - <FluentAccordionItem title="test 4"> |
| 290 | + <FluentAccordionItem @bind-Expanded="toolVM.Expanded"> |
258 | 291 | <HeadingTemplate> |
259 | | - <div style="display: flex; align-items: center; gap: 1rem;"> |
| 292 | + <div class="tool-heading"> |
260 | 293 | <FluentBadge Appearance="Appearance.Accent" Style="min-width: 80px; text-align: center;"> |
261 | | - @tool.Type |
| 294 | + @toolVM.ToolDefinition.Type |
262 | 295 | </FluentBadge> |
263 | | - <strong>@tool.Name</strong> |
264 | | - @if (!string.IsNullOrEmpty(tool.Description)) |
| 296 | + <strong>@toolVM.ToolDefinition.Name</strong> |
| 297 | + @if (!string.IsNullOrEmpty(toolVM.ToolDefinition.Description)) |
265 | 298 | { |
266 | | - <span>@FormatHelpers.TruncateText(tool.Description, maxLength: 100)</span> |
| 299 | + <span>@FormatHelpers.TruncateText(toolVM.ToolDefinition.Description, maxLength: 100)</span> |
267 | 300 | } |
268 | 301 | </div> |
269 | 302 | </HeadingTemplate> |
270 | 303 | <ChildContent> |
271 | | - @if (tool.Parameters?.Properties.Count > 0) |
| 304 | + @if (toolVM.ToolDefinition.Parameters?.Properties.Count > 0) |
272 | 305 | { |
273 | 306 | <table class="tool-parameters-table"> |
274 | 307 | <thead> |
|
279 | 312 | </tr> |
280 | 313 | </thead> |
281 | 314 | <tbody> |
282 | | - @foreach (var prop in tool.Parameters.Properties) |
| 315 | + @foreach (var prop in toolVM.ToolDefinition.Parameters.Properties) |
283 | 316 | { |
284 | 317 | <tr> |
285 | 318 | <td class="tool-cell tool-cell-nowrap"> |
286 | 319 | <strong>@prop.Key</strong> |
287 | | - @if (tool.Parameters.Required?.Contains(prop.Key) == true) |
| 320 | + @if (toolVM.ToolDefinition.Parameters.Required?.Contains(prop.Key) == true) |
288 | 321 | { |
289 | 322 | <span style="color: var(--error);"> *</span> |
290 | 323 | } |
|
299 | 332 | } |
300 | 333 | </tbody> |
301 | 334 | </table> |
302 | | - @if (tool.Parameters.Required?.Count > 0) |
| 335 | + @if (toolVM.ToolDefinition.Parameters.Required?.Count > 0) |
303 | 336 | { |
304 | | - <div> |
| 337 | + <div class="tool-footer"> |
305 | 338 | <span style="color: var(--error);">*</span> Required parameter |
306 | 339 | </div> |
307 | 340 | } |
308 | 341 | } |
309 | 342 | else |
310 | 343 | { |
311 | | - <p style="font-style: italic; color: var(--neutral-foreground-rest);">No parameters</p> |
| 344 | + <div class="tool-footer">No parameters</div> |
312 | 345 | } |
313 | 346 | </ChildContent> |
314 | 347 | </FluentAccordionItem> |
|
331 | 364 | <FluentDialogFooter Visible="false" /> |
332 | 365 |
|
333 | 366 | @{ |
334 | | - RenderFragment RenderMessageSection(string title, List<GenAIItemViewModel> items, bool noMessageContent, List<ToolDefinition> toolDefinitions) |
| 367 | + RenderFragment RenderMessageSection(string title, List<GenAIItemViewModel> items, bool noMessageContent) |
335 | 368 | { |
336 | 369 | return@<div class="section-container"> |
337 | 370 | <div class="section-title">@title</div> |
|
358 | 391 | foreach (var itemPart in itemParts) |
359 | 392 | { |
360 | 393 | <TextVisualizer ViewModel="@itemPart.TextVisualizerViewModel" HideLineNumbers="true" Virtualize="false" /> |
361 | | - |
362 | | - @if (itemPart.MessagePart is ToolCallRequestPart toolCallPart && !string.IsNullOrEmpty(toolCallPart.Name)) |
363 | | - { |
364 | | - if (toolDefinitions.FirstOrDefault(d => d.Name == toolCallPart.Name) is { } sdf) |
365 | | - { |
366 | | - <FluentButton Appearance="Appearance.Outline">View @toolCallPart.Name definition</FluentButton> |
367 | | - } |
368 | | - } |
369 | 394 | } |
370 | 395 | } |
371 | 396 | else |
|
0 commit comments