-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from andresharpe/feature/graphql-chat-improvemets
Refined prompts and display
- Loading branch information
Showing
3 changed files
with
140 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Text; | ||
using Newtonsoft.Json.Linq; | ||
|
||
public static class JTokenExtensions | ||
{ | ||
public static string ToUserFriendlyString(this JToken token, int indentLevel = 0) | ||
{ | ||
var sb = new StringBuilder(); | ||
WriteYaml(token, sb, indentLevel); | ||
return sb.ToString(); | ||
} | ||
|
||
private static void WriteYaml(JToken? token, StringBuilder sb, int indentLevel) | ||
{ | ||
if (token == null) return; | ||
switch (token.Type) | ||
{ | ||
case JTokenType.Object: | ||
foreach (var property in (JObject)token) | ||
{ | ||
AppendIndent(sb, indentLevel); | ||
sb.Append(property.Key).Append(":"); | ||
if (property.Value is JObject || property.Value is JArray) | ||
{ | ||
sb.AppendLine(); | ||
WriteYaml(property.Value, sb, indentLevel + 1); | ||
} | ||
else | ||
{ | ||
sb.Append(" "); | ||
WriteYaml(property.Value, sb, indentLevel); | ||
} | ||
} | ||
break; | ||
|
||
case JTokenType.Array: | ||
foreach (var item in (JArray)token) | ||
{ | ||
AppendIndent(sb, indentLevel); | ||
sb.AppendLine("-"); | ||
WriteYaml(item, sb, indentLevel + 1); | ||
} | ||
break; | ||
|
||
default: | ||
sb.AppendLine(token.ToString()); | ||
break; | ||
} | ||
} | ||
|
||
private static void AppendIndent(StringBuilder sb, int indentLevel) | ||
{ | ||
sb.Append(new string(' ', indentLevel * 2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters