mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 19:47:22 +00:00
Stopped the tool results and the JSON tree view from building JSON contracts by reflection
This commit is contained in:
3 files changed
+21
-3
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
@@ -37,7 +36,7 @@ public partial class JsonTreeView : ComponentBase
|
|||||||
private static List<TreeItemData<JsonTreeNode>> CreateChildren(JsonNode? value) => value switch
|
private static List<TreeItemData<JsonTreeNode>> CreateChildren(JsonNode? value) => value switch
|
||||||
{
|
{
|
||||||
JsonObject jsonObject => jsonObject
|
JsonObject jsonObject => jsonObject
|
||||||
.Select(property => CreateTreeItem(JsonSerializer.Serialize(property.Key), property.Value))
|
.Select(property => CreateTreeItem(JsonValue.Create(property.Key).ToJsonString(), property.Value))
|
||||||
.ToList(),
|
.ToList(),
|
||||||
JsonArray jsonArray => jsonArray
|
JsonArray jsonArray => jsonArray
|
||||||
.Select((item, index) => CreateTreeItem($"[{index}]", item))
|
.Select((item, index) => CreateTreeItem($"[{index}]", item))
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ public sealed class ToolExecutionResult
|
|||||||
/// with every umlaut as six characters. The relaxed encoder escapes only what JSON requires.
|
/// with every umlaut as six characters. The relaxed encoder escapes only what JSON requires.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
// Internal, so a tool which keeps its result within a budget measures exactly what the model gets:
|
// Internal, so a tool which keeps its result within a budget measures exactly what the model gets:
|
||||||
internal static readonly JsonSerializerOptions MODEL_CONTENT_OPTIONS = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
|
internal static readonly JsonSerializerOptions MODEL_CONTENT_OPTIONS = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
|
TypeInfoResolver = ToolExecutionResultJsonContext.Default,
|
||||||
|
}.AsReadOnly();
|
||||||
|
|
||||||
public string? TextContent { get; init; }
|
public string? TextContent { get; init; }
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace AIStudio.Tools.ToolCallingSystem;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The contracts of the options with which a tool result is written for the model, built at compile time.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// A JSON result is a tree of JSON nodes, which writes itself and needs no contract from the options. The
|
||||||
|
/// context is there all the same, so that these options can never fall back to reflection either.
|
||||||
|
/// </remarks>
|
||||||
|
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||||
|
[JsonSerializable(typeof(JsonNode))]
|
||||||
|
internal sealed partial class ToolExecutionResultJsonContext : JsonSerializerContext;
|
||||||
Reference in new issue
Block a user