mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 08:19:47 +00:00
In .NET 9 & C# 13 we can use spans inside async methods
This commit is contained in:
parent
38dc1ffc30
commit
4b3b80dc9d
@ -315,26 +315,6 @@ public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection>
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the JSON list from the given text. The text may contain additional
|
||||
/// information around the JSON list. The method tries to extract the JSON list
|
||||
/// from the text.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Algorithm: The method searches for the first line that contains only a '[' character.
|
||||
/// Then, it searches for the first line that contains only a ']' character. The method
|
||||
/// returns the text between these two lines (including the brackets). When the method
|
||||
/// cannot find the JSON list, it returns an empty string.
|
||||
/// <br/><br/>
|
||||
/// This overload is using strings instead of spans. We can use this overload in any
|
||||
/// async method. Thus, it is a wrapper around the span-based method. Yes, we are losing
|
||||
/// the memory efficiency of the span-based method, but we still gain the performance
|
||||
/// of the span-based method: the entire search algorithm is span-based.
|
||||
/// </remarks>
|
||||
/// <param name="text">The text that may contain the JSON list.</param>
|
||||
/// <returns>The extracted JSON list.</returns>
|
||||
private static string ExtractJson(string text) => ExtractJson(text.AsSpan()).ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the JSON list from the given text. The text may contain additional
|
||||
|
@ -319,9 +319,6 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
|
||||
}
|
||||
}
|
||||
|
||||
// A wrapper around the span version, because we need to call this method from an async context.
|
||||
private static string ExtractJson(string text) => ExtractJson(text.AsSpan()).ToString();
|
||||
|
||||
private static ReadOnlySpan<char> ExtractJson(ReadOnlySpan<char> input)
|
||||
{
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user